Skip to content

Commit 24ffb98

Browse files
committed
[libc] optimize bzero/memset for x86
This is simpy using the x86 optimized elements when targetting x86 cpus. Differential Revision: https://reviews.llvm.org/D106551
1 parent 71d0fd3 commit 24ffb98

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

libc/src/string/memory_utils/memset_utils.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,33 @@ namespace __llvm_libc {
4949
// superior for sizes that mattered.
5050
inline static void GeneralPurposeMemset(char *dst, unsigned char value,
5151
size_t count) {
52+
#if defined(__i386__) || defined(__x86_64__)
53+
using namespace ::__llvm_libc::x86;
54+
#else
55+
using namespace ::__llvm_libc::scalar;
56+
#endif
57+
5258
if (count == 0)
5359
return;
5460
if (count == 1)
55-
return SplatSet<scalar::_1>(dst, value);
61+
return SplatSet<_1>(dst, value);
5662
if (count == 2)
57-
return SplatSet<scalar::_2>(dst, value);
63+
return SplatSet<_2>(dst, value);
5864
if (count == 3)
59-
return SplatSet<scalar::_3>(dst, value);
65+
return SplatSet<_3>(dst, value);
6066
if (count == 4)
61-
return SplatSet<scalar::_4>(dst, value);
67+
return SplatSet<_4>(dst, value);
6268
if (count <= 8)
63-
return SplatSet<HeadTail<scalar::_4>>(dst, value, count);
69+
return SplatSet<HeadTail<_4>>(dst, value, count);
6470
if (count <= 16)
65-
return SplatSet<HeadTail<scalar::_8>>(dst, value, count);
71+
return SplatSet<HeadTail<_8>>(dst, value, count);
6672
if (count <= 32)
67-
return SplatSet<HeadTail<scalar::_16>>(dst, value, count);
73+
return SplatSet<HeadTail<_16>>(dst, value, count);
6874
if (count <= 64)
69-
return SplatSet<HeadTail<scalar::_32>>(dst, value, count);
75+
return SplatSet<HeadTail<_32>>(dst, value, count);
7076
if (count <= 128)
71-
return SplatSet<HeadTail<scalar::_64>>(dst, value, count);
72-
return SplatSet<Align<scalar::_32, Arg::Dst>::Then<Loop<scalar::_32>>>(
73-
dst, value, count);
77+
return SplatSet<HeadTail<_64>>(dst, value, count);
78+
return SplatSet<Align<_32, Arg::Dst>::Then<Loop<_32>>>(dst, value, count);
7479
}
7580

7681
} // namespace __llvm_libc

0 commit comments

Comments
 (0)