554 lines · plain
1add_subdirectory(memory_utils)2 3add_header_library(4 string_utils5 HDRS6 string_utils.h7 DEPENDS8 libc.hdr.types.size_t9 libc.hdr.limits_macros10 libc.hdr.stdint_proxy11 libc.src.__support.CPP.bitset12 libc.src.__support.CPP.type_traits13 libc.src.__support.CPP.simd14 libc.src.__support.common15 libc.src.__support.macros.attributes16 libc.src.string.memory_utils.inline_memcpy17)18 19add_header_library(20 allocating_string_utils21 HDRS22 allocating_string_utils.h23 DEPENDS24 .memory_utils.inline_memcpy25 libc.include.stdlib26 libc.src.__support.CPP.optional27 libc.src.__support.macros.config28)29 30add_entrypoint_object(31 memccpy32 SRCS33 memccpy.cpp34 HDRS35 memccpy.h36)37 38add_entrypoint_object(39 mempcpy40 SRCS41 mempcpy.cpp42 HDRS43 mempcpy.h44 DEPENDS45 .memory_utils.inline_memcpy46)47 48add_entrypoint_object(49 memmem50 SRCS51 memmem.cpp52 HDRS53 memmem.h54 DEPENDS55 .memory_utils.inline_memmem56)57 58add_entrypoint_object(59 memchr60 SRCS61 memchr.cpp62 HDRS63 memchr.h64 DEPENDS65 .string_utils66)67 68add_entrypoint_object(69 memrchr70 SRCS71 memrchr.cpp72 HDRS73 memrchr.h74)75 76add_entrypoint_object(77 stpcpy78 SRCS79 stpcpy.cpp80 HDRS81 stpcpy.h82 DEPENDS83 .string_utils84)85 86add_entrypoint_object(87 stpncpy88 SRCS89 stpncpy.cpp90 HDRS91 stpncpy.h92 DEPENDS93 .memory_utils.inline_bzero94)95 96add_entrypoint_object(97 strcat98 SRCS99 strcat.cpp100 HDRS101 strcat.h102 DEPENDS103 .string_utils104 libc.include.llvm-libc-types.size_t105)106 107add_entrypoint_object(108 strchr109 SRCS110 strchr.cpp111 HDRS112 strchr.h113 DEPENDS114 .string_utils115)116 117add_entrypoint_object(118 strchrnul119 SRCS120 strchrnul.cpp121 HDRS122 strchrnul.h123 DEPENDS124 .string_utils125)126 127add_entrypoint_object(128 strcmp129 SRCS130 strcmp.cpp131 HDRS132 strcmp.h133 DEPENDS134 .memory_utils.inline_strcmp135)136 137add_entrypoint_object(138 strcasestr139 SRCS140 strcasestr.cpp141 HDRS142 strcasestr.h143 DEPENDS144 .memory_utils.inline_strstr145 libc.src.__support.ctype_utils146)147 148add_entrypoint_object(149 strcoll150 SRCS151 strcoll.cpp152 HDRS153 strcoll.h154)155 156add_entrypoint_object(157 strcoll_l158 SRCS159 strcoll_l.cpp160 HDRS161 strcoll_l.h162)163 164add_entrypoint_object(165 strcpy166 SRCS167 strcpy.cpp168 HDRS169 strcpy.h170 DEPENDS171 .memory_utils.inline_memcpy172 .string_utils173)174 175add_entrypoint_object(176 strcspn177 SRCS178 strcspn.cpp179 HDRS180 strcspn.h181 DEPENDS182 .string_utils183)184 185add_entrypoint_object(186 strdup187 SRCS188 strdup.cpp189 HDRS190 strdup.h191 DEPENDS192 .memory_utils.inline_memcpy193 .string_utils194 libc.hdr.stdlib_macros195 libc.src.errno.errno196 libc.include.llvm-libc-types.size_t197)198 199add_entrypoint_object(200 strerror201 SRCS202 strerror.cpp203 HDRS204 strerror.h205 DEPENDS206 libc.src.__support.StringUtil.error_to_string207)208 209add_entrypoint_object(210 strerror_r211 SRCS212 strerror_r.cpp213 HDRS214 strerror_r.h215 DEPENDS216 libc.src.__support.StringUtil.error_to_string217)218 219add_entrypoint_object(220 strlcat221 SRCS222 strlcat.cpp223 HDRS224 strlcat.h225 DEPENDS226 .string_utils227 libc.include.llvm-libc-types.size_t228)229 230add_entrypoint_object(231 strlcpy232 SRCS233 strlcpy.cpp234 HDRS235 strlcpy.h236 DEPENDS237 .string_utils238 libc.include.llvm-libc-types.size_t239)240 241add_entrypoint_object(242 strlen243 SRCS244 strlen.cpp245 HDRS246 strlen.h247 DEPENDS248 .string_utils249 libc.include.llvm-libc-types.size_t250)251 252add_entrypoint_object(253 strncat254 SRCS255 strncat.cpp256 HDRS257 strncat.h258 DEPENDS259 .string_utils260 libc.include.llvm-libc-types.size_t261)262 263add_entrypoint_object(264 strncmp265 SRCS266 strncmp.cpp267 HDRS268 strncmp.h269 DEPENDS270 .memory_utils.inline_strcmp271)272 273add_entrypoint_object(274 strncpy275 SRCS276 strncpy.cpp277 HDRS278 strncpy.h279)280 281add_entrypoint_object(282 strndup283 SRCS284 strndup.cpp285 HDRS286 strndup.h287 DEPENDS288 .memory_utils.inline_memcpy289 .string_utils290 libc.include.stdlib291 libc.src.__support.CPP.new292 libc.include.llvm-libc-types.size_t293)294 295add_entrypoint_object(296 strnlen297 SRCS298 strnlen.cpp299 HDRS300 strnlen.h301 DEPENDS302 .string_utils303)304 305add_entrypoint_object(306 strpbrk307 SRCS308 strpbrk.cpp309 HDRS310 strpbrk.h311 DEPENDS312 .string_utils313)314 315add_entrypoint_object(316 strrchr317 SRCS318 strrchr.cpp319 HDRS320 strrchr.h321 DEPENDS322 .string_utils323)324 325add_entrypoint_object(326 strsep327 SRCS328 strsep.cpp329 HDRS330 strsep.h331 DEPENDS332 .string_utils333)334 335add_entrypoint_object(336 strsignal337 SRCS338 strsignal.cpp339 HDRS340 strsignal.h341 DEPENDS342 libc.src.__support.StringUtil.signal_to_string343)344 345add_entrypoint_object(346 strspn347 SRCS348 strspn.cpp349 HDRS350 strspn.h351 DEPENDS352 libc.src.__support.CPP.bitset353)354 355add_entrypoint_object(356 strstr357 SRCS358 strstr.cpp359 HDRS360 strstr.h361 DEPENDS362 .memory_utils.inline_strstr363)364 365add_entrypoint_object(366 strtok367 SRCS368 strtok.cpp369 HDRS370 strtok.h371 DEPENDS372 .string_utils373)374 375add_entrypoint_object(376 strtok_r377 SRCS378 strtok_r.cpp379 HDRS380 strtok_r.h381 DEPENDS382 .string_utils383)384 385add_entrypoint_object(386 strxfrm387 SRCS388 strxfrm.cpp389 HDRS390 strxfrm.h391 DEPENDS392 .string_utils393 .memory_utils.inline_memcpy394)395 396add_entrypoint_object(397 strxfrm_l398 SRCS399 strxfrm_l.cpp400 HDRS401 strxfrm_l.h402 DEPENDS403 .string_utils404 .memory_utils.inline_memcpy405)406 407add_entrypoint_object(408 memset_explicit409 SRCS410 memset_explicit.cpp411 HDRS412 memset_explicit.h413 DEPENDS414 .string_utils415 .memory_utils.inline_memset416)417 418# ------------------------------------------------------------------------------419# memcmp420# ------------------------------------------------------------------------------421 422function(add_memcmp memcmp_name)423 add_implementation(memcmp ${memcmp_name}424 SRCS ${LIBC_SOURCE_DIR}/src/string/memcmp.cpp425 HDRS ${LIBC_SOURCE_DIR}/src/string/memcmp.h426 DEPENDS427 .memory_utils.inline_memcmp428 libc.include.string429 ${ARGN}430 )431endfunction()432 433if(${LIBC_TARGET_ARCHITECTURE_IS_X86_64})434 add_memcmp(memcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)435 add_memcmp(memcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)436 add_memcmp(memcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)437 add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)438 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})439 add_memcmp(memcmp)440elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})441 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})442 add_memcmp(memcmp)443elseif(LIBC_TARGET_OS_IS_GPU)444 add_memcmp(memcmp)445else()446 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})447 add_memcmp(memcmp)448endif()449 450# ------------------------------------------------------------------------------451# memcpy452# ------------------------------------------------------------------------------453 454function(add_memcpy memcpy_name)455 add_implementation(memcpy ${memcpy_name}456 SRCS ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp457 HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h458 DEPENDS459 .memory_utils.inline_memcpy460 libc.include.string461 ${ARGN}462 )463endfunction()464 465if(${LIBC_TARGET_ARCHITECTURE_IS_X86_64})466 add_memcpy(memcpy_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)467 add_memcpy(memcpy_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)468 add_memcpy(memcpy_x86_64_opt_avx COMPILE_OPTIONS -march=sandybridge REQUIRE AVX)469 add_memcpy(memcpy_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)470 add_memcpy(memcpy_x86_64_opt_sw_prefetch_sse4 COMPILE_OPTIONS -DLIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING -march=nehalem REQUIRE SSE4_2)471 add_memcpy(memcpy_x86_64_opt_sw_prefetch_avx COMPILE_OPTIONS -DLIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING -march=sandybridge REQUIRE AVX)472 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})473 add_memcpy(memcpy)474elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})475 # Disable tail merging as it leads to lower performance.476 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}477 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")478 add_memcpy(memcpy MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")479elseif(LIBC_TARGET_OS_IS_GPU)480 add_memcpy(memcpy)481else()482 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})483 add_memcpy(memcpy)484endif()485 486# ------------------------------------------------------------------------------487# memmove488# ------------------------------------------------------------------------------489 490function(add_memmove memmove_name)491 add_implementation(memmove ${memmove_name}492 SRCS ${LIBC_SOURCE_DIR}/src/string/memmove.cpp493 HDRS ${LIBC_SOURCE_DIR}/src/string/memmove.h494 DEPENDS495 .memory_utils.inline_memcpy496 libc.include.string497 ${ARGN}498 )499endfunction()500 501if(${LIBC_TARGET_ARCHITECTURE_IS_X86_64})502 add_memmove(memmove_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)503 add_memmove(memmove_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)504 add_memmove(memmove_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)505 add_memmove(memmove_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)506 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})507 add_memmove(memmove)508elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})509 # Disable tail merging as it leads to lower performance.510 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}511 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")512 add_memmove(memmove MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")513elseif(LIBC_TARGET_OS_IS_GPU)514 add_memmove(memmove)515else()516 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})517 add_memmove(memmove)518endif()519 520# ------------------------------------------------------------------------------521# memset522# ------------------------------------------------------------------------------523 524function(add_memset memset_name)525 add_implementation(memset ${memset_name}526 SRCS ${LIBC_SOURCE_DIR}/src/string/memset.cpp527 HDRS ${LIBC_SOURCE_DIR}/src/string/memset.h528 DEPENDS529 .memory_utils.inline_memset530 libc.include.string531 ${ARGN}532 )533endfunction()534 535if(${LIBC_TARGET_ARCHITECTURE_IS_X86_64})536 add_memset(memset_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)537 add_memset(memset_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)538 add_memset(memset_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)539 add_memset(memset_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)540 add_memset(memset_x86_64_opt_sw_prefetch COMPILE_OPTIONS -DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING)541 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})542 add_memset(memset)543elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})544 # Disable tail merging as it leads to lower performance.545 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}546 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")547 add_memset(memset MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")548elseif(LIBC_TARGET_OS_IS_GPU)549 add_memset(memset)550else()551 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})552 add_memset(memset)553endif()554