authorgravatar for yefeng@emma-app.comYefeng Li <yefeng@emma-app.com> 2025-08-25 18:07:07+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-27 03:35:18+02:00
logaae5560712fb67cea2b1405c4e2b03e9be236678
treed0ba70e9a7281c8241639f10fbc721a2e6554a2c
parent42eb1329b1b9f41fe64e96c9c15afb486d0a1666

Remove memcmp and memset from bundled musl and wasi


10 files changed, 0 insertions(+), 537 deletions(-)

lib/libc/musl/src/string/aarch64/memset.S deleted-115
......@@ -1,115 +0,0 @@
1/*
2 * memset - fill memory with a constant byte
3 *
4 * Copyright (c) 2012-2020, Arm Limited.
5 * SPDX-License-Identifier: MIT
6 */
7
8/* Assumptions:
9 *
10 * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses.
11 *
12 */
13
14#define dstin x0
15#define val x1
16#define valw w1
17#define count x2
18#define dst x3
19#define dstend x4
20#define zva_val x5
21
22.global memset
23.type memset,%function
24memset:
25
26 dup v0.16B, valw
27 add dstend, dstin, count
28
29 cmp count, 96
30 b.hi .Lset_long
31 cmp count, 16
32 b.hs .Lset_medium
33 mov val, v0.D[0]
34
35 /* Set 0..15 bytes. */
36 tbz count, 3, 1f
37 str val, [dstin]
38 str val, [dstend, -8]
39 ret
40 nop
411: tbz count, 2, 2f
42 str valw, [dstin]
43 str valw, [dstend, -4]
44 ret
452: cbz count, 3f
46 strb valw, [dstin]
47 tbz count, 1, 3f
48 strh valw, [dstend, -2]
493: ret
50
51 /* Set 17..96 bytes. */
52.Lset_medium:
53 str q0, [dstin]
54 tbnz count, 6, .Lset96
55 str q0, [dstend, -16]
56 tbz count, 5, 1f
57 str q0, [dstin, 16]
58 str q0, [dstend, -32]
591: ret
60
61 .p2align 4
62 /* Set 64..96 bytes. Write 64 bytes from the start and
63 32 bytes from the end. */
64.Lset96:
65 str q0, [dstin, 16]
66 stp q0, q0, [dstin, 32]
67 stp q0, q0, [dstend, -32]
68 ret
69
70 .p2align 4
71.Lset_long:
72 and valw, valw, 255
73 bic dst, dstin, 15
74 str q0, [dstin]
75 cmp count, 160
76 ccmp valw, 0, 0, hs
77 b.ne .Lno_zva
78
79#ifndef SKIP_ZVA_CHECK
80 mrs zva_val, dczid_el0
81 and zva_val, zva_val, 31
82 cmp zva_val, 4 /* ZVA size is 64 bytes. */
83 b.ne .Lno_zva
84#endif
85 str q0, [dst, 16]
86 stp q0, q0, [dst, 32]
87 bic dst, dst, 63
88 sub count, dstend, dst /* Count is now 64 too large. */
89 sub count, count, 128 /* Adjust count and bias for loop. */
90
91 .p2align 4
92.Lzva_loop:
93 add dst, dst, 64
94 dc zva, dst
95 subs count, count, 64
96 b.hi .Lzva_loop
97 stp q0, q0, [dstend, -64]
98 stp q0, q0, [dstend, -32]
99 ret
100
101.Lno_zva:
102 sub count, dstend, dst /* Count is 16 too large. */
103 sub dst, dst, 16 /* Dst is biased by -32. */
104 sub count, count, 64 + 16 /* Adjust count and bias for loop. */
105.Lno_zva_loop:
106 stp q0, q0, [dst, 32]
107 stp q0, q0, [dst, 64]!
108 subs count, count, 64
109 b.hi .Lno_zva_loop
110 stp q0, q0, [dstend, -64]
111 stp q0, q0, [dstend, -32]
112 ret
113
114.size memset,.-memset
115
lib/libc/musl/src/string/arm/__aeabi_memset.s deleted-31
......@@ -1,31 +0,0 @@
1.syntax unified
2
3.global __aeabi_memclr8
4.global __aeabi_memclr4
5.global __aeabi_memclr
6.global __aeabi_memset8
7.global __aeabi_memset4
8.global __aeabi_memset
9
10.type __aeabi_memclr8,%function
11.type __aeabi_memclr4,%function
12.type __aeabi_memclr,%function
13.type __aeabi_memset8,%function
14.type __aeabi_memset4,%function
15.type __aeabi_memset,%function
16
17__aeabi_memclr8:
18__aeabi_memclr4:
19__aeabi_memclr:
20 movs r2, #0
21__aeabi_memset8:
22__aeabi_memset4:
23__aeabi_memset:
24 cmp r1, #0
25 beq 2f
26 adds r1, r0, r1
271: strb r2, [r0]
28 adds r0, r0, #1
29 cmp r1, r0
30 bne 1b
312: bx lr
lib/libc/musl/src/string/i386/memset.s deleted-76
......@@ -1,76 +0,0 @@
1.global memset
2.type memset,@function
3memset:
4 mov 12(%esp),%ecx
5 cmp $62,%ecx
6 ja 2f
7
8 mov 8(%esp),%dl
9 mov 4(%esp),%eax
10 test %ecx,%ecx
11 jz 1f
12
13 mov %dl,%dh
14
15 mov %dl,(%eax)
16 mov %dl,-1(%eax,%ecx)
17 cmp $2,%ecx
18 jbe 1f
19
20 mov %dx,1(%eax)
21 mov %dx,(-1-2)(%eax,%ecx)
22 cmp $6,%ecx
23 jbe 1f
24
25 shl $16,%edx
26 mov 8(%esp),%dl
27 mov 8(%esp),%dh
28
29 mov %edx,(1+2)(%eax)
30 mov %edx,(-1-2-4)(%eax,%ecx)
31 cmp $14,%ecx
32 jbe 1f
33
34 mov %edx,(1+2+4)(%eax)
35 mov %edx,(1+2+4+4)(%eax)
36 mov %edx,(-1-2-4-8)(%eax,%ecx)
37 mov %edx,(-1-2-4-4)(%eax,%ecx)
38 cmp $30,%ecx
39 jbe 1f
40
41 mov %edx,(1+2+4+8)(%eax)
42 mov %edx,(1+2+4+8+4)(%eax)
43 mov %edx,(1+2+4+8+8)(%eax)
44 mov %edx,(1+2+4+8+12)(%eax)
45 mov %edx,(-1-2-4-8-16)(%eax,%ecx)
46 mov %edx,(-1-2-4-8-12)(%eax,%ecx)
47 mov %edx,(-1-2-4-8-8)(%eax,%ecx)
48 mov %edx,(-1-2-4-8-4)(%eax,%ecx)
49
501: ret
51
522: movzbl 8(%esp),%eax
53 mov %edi,12(%esp)
54 imul $0x1010101,%eax
55 mov 4(%esp),%edi
56 test $15,%edi
57 mov %eax,-4(%edi,%ecx)
58 jnz 2f
59
601: shr $2, %ecx
61 rep
62 stosl
63 mov 4(%esp),%eax
64 mov 12(%esp),%edi
65 ret
66
672: xor %edx,%edx
68 sub %edi,%edx
69 and $15,%edx
70 mov %eax,(%edi)
71 mov %eax,4(%edi)
72 mov %eax,8(%edi)
73 mov %eax,12(%edi)
74 sub %edx,%ecx
75 add %edx,%edi
76 jmp 1b
lib/libc/musl/src/string/memcmp.c deleted-8
......@@ -1,8 +0,0 @@
1#include <string.h>
2
3int memcmp(const void *vl, const void *vr, size_t n)
4{
5 const unsigned char *l=vl, *r=vr;
6 for (; n && *l == *r; n--, l++, r++);
7 return n ? *l-*r : 0;
8}
lib/libc/musl/src/string/memset.c deleted-90
......@@ -1,90 +0,0 @@
1#include <string.h>
2#include <stdint.h>
3
4void *memset(void *dest, int c, size_t n)
5{
6 unsigned char *s = dest;
7 size_t k;
8
9 /* Fill head and tail with minimal branching. Each
10 * conditional ensures that all the subsequently used
11 * offsets are well-defined and in the dest region. */
12
13 if (!n) return dest;
14 s[0] = c;
15 s[n-1] = c;
16 if (n <= 2) return dest;
17 s[1] = c;
18 s[2] = c;
19 s[n-2] = c;
20 s[n-3] = c;
21 if (n <= 6) return dest;
22 s[3] = c;
23 s[n-4] = c;
24 if (n <= 8) return dest;
25
26 /* Advance pointer to align it at a 4-byte boundary,
27 * and truncate n to a multiple of 4. The previous code
28 * already took care of any head/tail that get cut off
29 * by the alignment. */
30
31 k = -(uintptr_t)s & 3;
32 s += k;
33 n -= k;
34 n &= -4;
35
36#ifdef __GNUC__
37 typedef uint32_t __attribute__((__may_alias__)) u32;
38 typedef uint64_t __attribute__((__may_alias__)) u64;
39
40 u32 c32 = ((u32)-1)/255 * (unsigned char)c;
41
42 /* In preparation to copy 32 bytes at a time, aligned on
43 * an 8-byte bounary, fill head/tail up to 28 bytes each.
44 * As in the initial byte-based head/tail fill, each
45 * conditional below ensures that the subsequent offsets
46 * are valid (e.g. !(n<=24) implies n>=28). */
47
48 *(u32 *)(s+0) = c32;
49 *(u32 *)(s+n-4) = c32;
50 if (n <= 8) return dest;
51 *(u32 *)(s+4) = c32;
52 *(u32 *)(s+8) = c32;
53 *(u32 *)(s+n-12) = c32;
54 *(u32 *)(s+n-8) = c32;
55 if (n <= 24) return dest;
56 *(u32 *)(s+12) = c32;
57 *(u32 *)(s+16) = c32;
58 *(u32 *)(s+20) = c32;
59 *(u32 *)(s+24) = c32;
60 *(u32 *)(s+n-28) = c32;
61 *(u32 *)(s+n-24) = c32;
62 *(u32 *)(s+n-20) = c32;
63 *(u32 *)(s+n-16) = c32;
64
65 /* Align to a multiple of 8 so we can fill 64 bits at a time,
66 * and avoid writing the same bytes twice as much as is
67 * practical without introducing additional branching. */
68
69 k = 24 + ((uintptr_t)s & 4);
70 s += k;
71 n -= k;
72
73 /* If this loop is reached, 28 tail bytes have already been
74 * filled, so any remainder when n drops below 32 can be
75 * safely ignored. */
76
77 u64 c64 = c32 | ((u64)c32 << 32);
78 for (; n >= 32; n-=32, s+=32) {
79 *(u64 *)(s+0) = c64;
80 *(u64 *)(s+8) = c64;
81 *(u64 *)(s+16) = c64;
82 *(u64 *)(s+24) = c64;
83 }
84#else
85 /* Pure C fallback with no aliasing violations. */
86 for (; n; n--, s++) *s = c;
87#endif
88
89 return dest;
90}
lib/libc/musl/src/string/x86_64/memset.s deleted-72
......@@ -1,72 +0,0 @@
1.global memset
2.type memset,@function
3memset:
4 movzbq %sil,%rax
5 mov $0x101010101010101,%r8
6 imul %r8,%rax
7
8 cmp $126,%rdx
9 ja 2f
10
11 test %edx,%edx
12 jz 1f
13
14 mov %sil,(%rdi)
15 mov %sil,-1(%rdi,%rdx)
16 cmp $2,%edx
17 jbe 1f
18
19 mov %ax,1(%rdi)
20 mov %ax,(-1-2)(%rdi,%rdx)
21 cmp $6,%edx
22 jbe 1f
23
24 mov %eax,(1+2)(%rdi)
25 mov %eax,(-1-2-4)(%rdi,%rdx)
26 cmp $14,%edx
27 jbe 1f
28
29 mov %rax,(1+2+4)(%rdi)
30 mov %rax,(-1-2-4-8)(%rdi,%rdx)
31 cmp $30,%edx
32 jbe 1f
33
34 mov %rax,(1+2+4+8)(%rdi)
35 mov %rax,(1+2+4+8+8)(%rdi)
36 mov %rax,(-1-2-4-8-16)(%rdi,%rdx)
37 mov %rax,(-1-2-4-8-8)(%rdi,%rdx)
38 cmp $62,%edx
39 jbe 1f
40
41 mov %rax,(1+2+4+8+16)(%rdi)
42 mov %rax,(1+2+4+8+16+8)(%rdi)
43 mov %rax,(1+2+4+8+16+16)(%rdi)
44 mov %rax,(1+2+4+8+16+24)(%rdi)
45 mov %rax,(-1-2-4-8-16-32)(%rdi,%rdx)
46 mov %rax,(-1-2-4-8-16-24)(%rdi,%rdx)
47 mov %rax,(-1-2-4-8-16-16)(%rdi,%rdx)
48 mov %rax,(-1-2-4-8-16-8)(%rdi,%rdx)
49
501: mov %rdi,%rax
51 ret
52
532: test $15,%edi
54 mov %rdi,%r8
55 mov %rax,-8(%rdi,%rdx)
56 mov %rdx,%rcx
57 jnz 2f
58
591: shr $3,%rcx
60 rep
61 stosq
62 mov %r8,%rax
63 ret
64
652: xor %edx,%edx
66 sub %edi,%edx
67 and $15,%edx
68 mov %rax,(%rdi)
69 mov %rax,8(%rdi)
70 sub %rdx,%rcx
71 add %rdx,%rdi
72 jmp 1b
lib/libc/wasi/libc-top-half/musl/src/string/memcmp.c deleted-43
......@@ -1,43 +0,0 @@
1#include <string.h>
2
3#ifdef __wasm_simd128__
4#include <wasm_simd128.h>
5#endif
6
7int memcmp(const void *vl, const void *vr, size_t n)
8{
9#if defined(__wasm_simd128__) && defined(__wasilibc_simd_string)
10 if (n >= sizeof(v128_t)) {
11 // memcmp is allowed to read up to n bytes from each object.
12 // Find the first different character in the objects.
13 // Unaligned loads handle the case where the objects
14 // have mismatching alignments.
15 const v128_t *v1 = (v128_t *)vl;
16 const v128_t *v2 = (v128_t *)vr;
17 while (n) {
18 const v128_t cmp = wasm_i8x16_eq(wasm_v128_load(v1), wasm_v128_load(v2));
19 // Bitmask is slow on AArch64, all_true is much faster.
20 if (!wasm_i8x16_all_true(cmp)) {
21 // Find the offset of the first zero bit (little-endian).
22 size_t ctz = __builtin_ctz(~wasm_i8x16_bitmask(cmp));
23 const unsigned char *u1 = (unsigned char *)v1 + ctz;
24 const unsigned char *u2 = (unsigned char *)v2 + ctz;
25 // This may help the compiler if the function is inlined.
26 __builtin_assume(*u1 - *u2 != 0);
27 return *u1 - *u2;
28 }
29 // This makes n a multiple of sizeof(v128_t)
30 // for every iteration except the first.
31 size_t align = (n - 1) % sizeof(v128_t) + 1;
32 v1 = (v128_t *)((char *)v1 + align);
33 v2 = (v128_t *)((char *)v2 + align);
34 n -= align;
35 }
36 return 0;
37 }
38#endif
39
40 const unsigned char *l=vl, *r=vr;
41 for (; n && *l == *r; n--, l++, r++);
42 return n ? *l-*r : 0;
43}
lib/libc/wasi/libc-top-half/musl/src/string/memset.c deleted-94
......@@ -1,94 +0,0 @@
1#include <string.h>
2#include <stdint.h>
3
4void *memset(void *dest, int c, size_t n)
5{
6#if defined(__wasm_bulk_memory__)
7 if (n > BULK_MEMORY_THRESHOLD)
8 return __builtin_memset(dest, c, n);
9#endif
10 unsigned char *s = dest;
11 size_t k;
12
13 /* Fill head and tail with minimal branching. Each
14 * conditional ensures that all the subsequently used
15 * offsets are well-defined and in the dest region. */
16
17 if (!n) return dest;
18 s[0] = c;
19 s[n-1] = c;
20 if (n <= 2) return dest;
21 s[1] = c;
22 s[2] = c;
23 s[n-2] = c;
24 s[n-3] = c;
25 if (n <= 6) return dest;
26 s[3] = c;
27 s[n-4] = c;
28 if (n <= 8) return dest;
29
30 /* Advance pointer to align it at a 4-byte boundary,
31 * and truncate n to a multiple of 4. The previous code
32 * already took care of any head/tail that get cut off
33 * by the alignment. */
34
35 k = -(uintptr_t)s & 3;
36 s += k;
37 n -= k;
38 n &= -4;
39
40#ifdef __GNUC__
41 typedef uint32_t __attribute__((__may_alias__)) u32;
42 typedef uint64_t __attribute__((__may_alias__)) u64;
43
44 u32 c32 = ((u32)-1)/255 * (unsigned char)c;
45
46 /* In preparation to copy 32 bytes at a time, aligned on
47 * an 8-byte bounary, fill head/tail up to 28 bytes each.
48 * As in the initial byte-based head/tail fill, each
49 * conditional below ensures that the subsequent offsets
50 * are valid (e.g. !(n<=24) implies n>=28). */
51
52 *(u32 *)(s+0) = c32;
53 *(u32 *)(s+n-4) = c32;
54 if (n <= 8) return dest;
55 *(u32 *)(s+4) = c32;
56 *(u32 *)(s+8) = c32;
57 *(u32 *)(s+n-12) = c32;
58 *(u32 *)(s+n-8) = c32;
59 if (n <= 24) return dest;
60 *(u32 *)(s+12) = c32;
61 *(u32 *)(s+16) = c32;
62 *(u32 *)(s+20) = c32;
63 *(u32 *)(s+24) = c32;
64 *(u32 *)(s+n-28) = c32;
65 *(u32 *)(s+n-24) = c32;
66 *(u32 *)(s+n-20) = c32;
67 *(u32 *)(s+n-16) = c32;
68
69 /* Align to a multiple of 8 so we can fill 64 bits at a time,
70 * and avoid writing the same bytes twice as much as is
71 * practical without introducing additional branching. */
72
73 k = 24 + ((uintptr_t)s & 4);
74 s += k;
75 n -= k;
76
77 /* If this loop is reached, 28 tail bytes have already been
78 * filled, so any remainder when n drops below 32 can be
79 * safely ignored. */
80
81 u64 c64 = c32 | ((u64)c32 << 32);
82 for (; n >= 32; n-=32, s+=32) {
83 *(u64 *)(s+0) = c64;
84 *(u64 *)(s+8) = c64;
85 *(u64 *)(s+16) = c64;
86 *(u64 *)(s+24) = c64;
87 }
88#else
89 /* Pure C fallback with no aliasing violations. */
90 for (; n; n--, s++) *s = c;
91#endif
92
93 return dest;
94}
src/libs/musl.zig-6
......@@ -1786,20 +1786,15 @@ const src_files = [_][]const u8{
17861786 "musl/src/stdlib/strtol.c",
17871787 "musl/src/stdlib/wcstod.c",
17881788 "musl/src/stdlib/wcstol.c",
1789 "musl/src/string/aarch64/memset.S",
1790 "musl/src/string/arm/__aeabi_memset.s",
17911789 "musl/src/string/bcmp.c",
17921790 "musl/src/string/bcopy.c",
17931791 "musl/src/string/explicit_bzero.c",
1794 "musl/src/string/i386/memset.s",
17951792 "musl/src/string/index.c",
17961793 "musl/src/string/memccpy.c",
17971794 "musl/src/string/memchr.c",
1798 "musl/src/string/memcmp.c",
17991795 "musl/src/string/memmem.c",
18001796 "musl/src/string/mempcpy.c",
18011797 "musl/src/string/memrchr.c",
1802 "musl/src/string/memset.c",
18031798 "musl/src/string/rindex.c",
18041799 "musl/src/string/stpcpy.c",
18051800 "musl/src/string/stpncpy.c",
......@@ -1855,7 +1850,6 @@ const src_files = [_][]const u8{
18551850 "musl/src/string/wmemcpy.c",
18561851 "musl/src/string/wmemmove.c",
18571852 "musl/src/string/wmemset.c",
1858 "musl/src/string/x86_64/memset.s",
18591853 "musl/src/temp/mkdtemp.c",
18601854 "musl/src/temp/mkostemp.c",
18611855 "musl/src/temp/mkostemps.c",
src/libs/wasi_libc.zig-2
......@@ -1221,9 +1221,7 @@ const libc_top_half_src_files = [_][]const u8{
12211221 "wasi/libc-top-half/musl/src/stdlib/wcstod.c",
12221222 "wasi/libc-top-half/musl/src/stdlib/wcstol.c",
12231223 "wasi/libc-top-half/musl/src/string/memchr.c",
1224 "wasi/libc-top-half/musl/src/string/memcmp.c",
12251224 "wasi/libc-top-half/musl/src/string/memrchr.c",
1226 "wasi/libc-top-half/musl/src/string/memset.c",
12271225 "wasi/libc-top-half/musl/src/string/strchrnul.c",
12281226 "wasi/libc-top-half/musl/src/thread/pthread_attr_get.c",
12291227 "wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c",