blob: 1b11d888bdc4f83ee7b92523f22f4b9479ff4e2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
add_subdirectory(memory_utils)
add_header_library(
string_utils
HDRS
string_utils.h
DEPENDS
libc.src.__support.CPP.bitset
.memory_utils.memcpy_implementation
.memory_utils.bzero_implementation
)
add_entrypoint_object(
memccpy
SRCS
memccpy.cpp
HDRS
memccpy.h
)
add_entrypoint_object(
mempcpy
SRCS
mempcpy.cpp
HDRS
mempcpy.h
DEPENDS
.memory_utils.memcpy_implementation
)
add_entrypoint_object(
memchr
SRCS
memchr.cpp
HDRS
memchr.h
DEPENDS
.string_utils
)
add_entrypoint_object(
memrchr
SRCS
memrchr.cpp
HDRS
memrchr.h
)
add_entrypoint_object(
stpcpy
SRCS
stpcpy.cpp
HDRS
stpcpy.h
DEPENDS
.mempcpy
.string_utils
)
add_entrypoint_object(
stpncpy
SRCS
stpncpy.cpp
HDRS
stpncpy.h
DEPENDS
.memory_utils.bzero_implementation
)
add_entrypoint_object(
strcat
SRCS
strcat.cpp
HDRS
strcat.h
DEPENDS
.strcpy
.string_utils
)
add_entrypoint_object(
strchr
SRCS
strchr.cpp
HDRS
strchr.h
)
add_entrypoint_object(
strcmp
SRCS
strcmp.cpp
HDRS
strcmp.h
)
add_entrypoint_object(
strcpy
SRCS
strcpy.cpp
HDRS
strcpy.h
DEPENDS
.memory_utils.memcpy_implementation
.string_utils
)
add_entrypoint_object(
strcspn
SRCS
strcspn.cpp
HDRS
strcspn.h
DEPENDS
.string_utils
)
add_entrypoint_object(
strdup
SRCS
strdup.cpp
HDRS
strdup.h
DEPENDS
.memory_utils.memcpy_implementation
.string_utils
libc.include.stdlib
)
add_entrypoint_object(
strerror
SRCS
strerror.cpp
HDRS
strerror.h
DEPENDS
libc.src.__support.error_to_string
libc.src.__support.CPP.span
)
add_entrypoint_object(
strlcat
SRCS
strlcat.cpp
HDRS
strlcat.h
DEPENDS
.string_utils
libc.include.string
)
add_entrypoint_object(
strlcpy
SRCS
strlcpy.cpp
HDRS
strlcpy.h
DEPENDS
.string_utils
libc.include.string
)
add_entrypoint_object(
strlen
SRCS
strlen.cpp
HDRS
strlen.h
DEPENDS
libc.include.string
)
add_entrypoint_object(
strncat
SRCS
strncat.cpp
HDRS
strncat.h
DEPENDS
.strncpy
.string_utils
)
add_entrypoint_object(
strncmp
SRCS
strncmp.cpp
HDRS
strncmp.h
)
add_entrypoint_object(
strncpy
SRCS
strncpy.cpp
HDRS
strncpy.h
)
add_entrypoint_object(
strndup
SRCS
strndup.cpp
HDRS
strndup.h
DEPENDS
.memory_utils.memcpy_implementation
.string_utils
libc.include.stdlib
)
add_entrypoint_object(
strnlen
SRCS
strnlen.cpp
HDRS
strnlen.h
DEPENDS
.string_utils
)
add_entrypoint_object(
strpbrk
SRCS
strpbrk.cpp
HDRS
strpbrk.h
DEPENDS
.string_utils
)
add_entrypoint_object(
strrchr
SRCS
strrchr.cpp
HDRS
strrchr.h
)
add_entrypoint_object(
strspn
SRCS
strspn.cpp
HDRS
strspn.h
DEPENDS
libc.src.__support.CPP.bitset
)
add_entrypoint_object(
strstr
SRCS
strstr.cpp
HDRS
strstr.h
)
add_entrypoint_object(
strtok
SRCS
strtok.cpp
HDRS
strtok.h
DEPENDS
.string_utils
)
add_entrypoint_object(
strtok_r
SRCS
strtok_r.cpp
HDRS
strtok_r.h
DEPENDS
.string_utils
)
# Helper to define a function with multiple implementations
# - Computes flags to satisfy required/rejected features and arch,
# - Declares an entry point,
# - Attach the REQUIRE_CPU_FEATURES property to the target,
# - Add the fully qualified target to `${name}_implementations` global property for tests.
function(add_implementation name impl_name)
cmake_parse_arguments(
"ADD_IMPL"
"" # Optional arguments
"" # Single value arguments
"REQUIRE;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;MLLVM_COMPILE_OPTIONS" # Multi value arguments
${ARGN})
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
endforeach()
endif()
add_entrypoint_object(${impl_name}
NAME ${name}
SRCS ${ADD_IMPL_SRCS}
HDRS ${ADD_IMPL_HDRS}
DEPENDS ${ADD_IMPL_DEPENDS}
COMPILE_OPTIONS ${ADD_IMPL_COMPILE_OPTIONS}
)
get_fq_target_name(${impl_name} fq_target_name)
set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}")
set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}")
endfunction()
# ------------------------------------------------------------------------------
# bcmp
# ------------------------------------------------------------------------------
function(add_bcmp bcmp_name)
add_implementation(bcmp ${bcmp_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/bcmp.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/bcmp.h
DEPENDS
.memory_utils.memory_utils
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_bcmp(bcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_bcmp(bcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_bcmp(bcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_bcmp(bcmp)
else()
add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_bcmp(bcmp)
endif()
# ------------------------------------------------------------------------------
# bzero
# ------------------------------------------------------------------------------
function(add_bzero bzero_name)
add_implementation(bzero ${bzero_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/bzero.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/bzero.h
DEPENDS
.memory_utils.memset_implementation
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_bzero(bzero_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_bzero(bzero_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_bzero(bzero_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_bzero(bzero_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_bzero(bzero)
else()
add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_bzero(bzero)
endif()
# ------------------------------------------------------------------------------
# memcmp
# ------------------------------------------------------------------------------
function(add_memcmp memcmp_name)
add_implementation(memcmp ${memcmp_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/memcmp.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/memcmp.h
DEPENDS
.memory_utils.memcmp_implementation
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_memcmp(memcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_memcmp(memcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_memcmp(memcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcmp(memcmp)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcmp(memcmp)
else()
add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcmp(memcmp)
endif()
# ------------------------------------------------------------------------------
# memcpy
# ------------------------------------------------------------------------------
function(add_memcpy memcpy_name)
add_implementation(memcpy ${memcpy_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h
DEPENDS
.memory_utils.memcpy_implementation
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_memcpy(memcpy_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_memcpy(memcpy_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_memcpy(memcpy_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_memcpy(memcpy_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcpy(memcpy)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
# Disable tail merging as it leads to lower performance.
add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
add_memcpy(memcpy MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
else()
add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcpy(memcpy)
endif()
# ------------------------------------------------------------------------------
# memmove
# ------------------------------------------------------------------------------
function(add_memmove memmove_name)
add_implementation(memmove ${memmove_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/memmove.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/memmove.h
DEPENDS
.memory_utils.memory_utils
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_memmove(memmove_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_memmove(memmove_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_memmove(memmove_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_memmove(memmove_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memmove(memmove)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
# Disable tail merging as it leads to lower performance.
add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
add_memmove(memmove MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
else()
add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memmove(memmove)
endif()
# ------------------------------------------------------------------------------
# memset
# ------------------------------------------------------------------------------
function(add_memset memset_name)
add_implementation(memset ${memset_name}
SRCS ${LIBC_SOURCE_DIR}/src/string/memset.cpp
HDRS ${LIBC_SOURCE_DIR}/src/string/memset.h
DEPENDS
.memory_utils.memset_implementation
libc.include.string
${ARGN}
)
endfunction()
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_memset(memset_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_memset(memset_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_memset(memset_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
add_memset(memset_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memset(memset)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
# Disable tail merging as it leads to lower performance.
add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
add_memset(memset MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
else()
add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memset(memset)
endif()
|