1 add_subdirectory(memory_utils)
9 libc.src.__support.CPP.bitset
10 libc.src.__support.common
11 .memory_utils.memcpy_implementation
12 .memory_utils.bzero_implementation
16 allocating_string_utils
18 allocating_string_utils.h
20 .memory_utils.memcpy_implementation
22 libc.src.__support.CPP.optional
23 libc.src.__support.macros.config
26 add_entrypoint_object(
34 add_entrypoint_object(
44 add_entrypoint_object(
52 add_entrypoint_object(
59 .memory_utils.memcpy_implementation
62 add_entrypoint_object(
69 .memory_utils.memmem_implementation
72 add_entrypoint_object(
82 add_entrypoint_object(
90 add_entrypoint_object(
100 add_entrypoint_object(
111 add_entrypoint_object(
118 .memory_utils.bzero_implementation
121 add_entrypoint_object(
132 add_entrypoint_object(
142 add_entrypoint_object(
152 add_entrypoint_object(
159 .memory_utils.strcmp_implementation
162 add_entrypoint_object(
169 .memory_utils.strcmp_implementation
170 libc.src.__support.ctype_utils
173 add_entrypoint_object(
180 .memory_utils.strstr_implementation
181 libc.src.__support.ctype_utils
184 add_entrypoint_object(
192 add_entrypoint_object(
199 .memory_utils.memcpy_implementation
203 add_entrypoint_object(
213 add_entrypoint_object(
220 .memory_utils.memcpy_implementation
226 add_entrypoint_object(
233 libc.src.__support.StringUtil.error_to_string
236 add_entrypoint_object(
243 libc.src.__support.StringUtil.error_to_string
246 add_entrypoint_object(
257 add_entrypoint_object(
268 add_entrypoint_object(
279 add_entrypoint_object(
290 add_entrypoint_object(
297 .memory_utils.strcmp_implementation
300 add_entrypoint_object(
307 .memory_utils.strcmp_implementation
308 libc.src.__support.ctype_utils
311 add_entrypoint_object(
319 add_entrypoint_object(
326 .memory_utils.memcpy_implementation
329 libc.src.__support.CPP.new
332 add_entrypoint_object(
342 add_entrypoint_object(
352 add_entrypoint_object(
362 add_entrypoint_object(
372 add_entrypoint_object(
379 libc.src.__support.StringUtil.signal_to_string
382 add_entrypoint_object(
389 libc.src.__support.CPP.bitset
392 add_entrypoint_object(
399 .memory_utils.strstr_implementation
402 add_entrypoint_object(
412 add_entrypoint_object(
422 add_entrypoint_object(
430 .memory_utils.memcpy_implementation
433 # Helper to define a function with multiple implementations
434 # - Computes flags to satisfy required/rejected features and arch,
435 # - Declares an entry point,
436 # - Attach the REQUIRE_CPU_FEATURES property to the target,
437 # - Add the fully qualified target to `${name}_implementations` global property for tests.
438 function(add_implementation name impl_name)
439 cmake_parse_arguments(
441 "" # Optional arguments
442 "" # Single value arguments
443 "REQUIRE;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;MLLVM_COMPILE_OPTIONS" # Multi value arguments
446 if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
447 # Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
448 foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
449 list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
453 add_entrypoint_object(${impl_name}
455 SRCS ${ADD_IMPL_SRCS}
456 HDRS ${ADD_IMPL_HDRS}
457 DEPENDS ${ADD_IMPL_DEPENDS}
458 COMPILE_OPTIONS -O3 ${ADD_IMPL_COMPILE_OPTIONS}
460 get_fq_target_name(${impl_name} fq_target_name)
461 set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}")
462 set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}")
465 # ------------------------------------------------------------------------------
467 # ------------------------------------------------------------------------------
469 function(add_bcmp bcmp_name)
470 add_implementation(bcmp ${bcmp_name}
471 SRCS ${LIBC_SOURCE_DIR}/src/string/bcmp.cpp
472 HDRS ${LIBC_SOURCE_DIR}/src/string/bcmp.h
474 .memory_utils.memory_utils
480 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
481 add_bcmp(bcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
482 add_bcmp(bcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
483 add_bcmp(bcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
484 add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)
485 add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
488 add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
492 # ------------------------------------------------------------------------------
494 # ------------------------------------------------------------------------------
496 function(add_bzero bzero_name)
497 add_implementation(bzero ${bzero_name}
498 SRCS ${LIBC_SOURCE_DIR}/src/string/bzero.cpp
499 HDRS ${LIBC_SOURCE_DIR}/src/string/bzero.h
501 .memory_utils.memset_implementation
507 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
508 add_bzero(bzero_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
509 add_bzero(bzero_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
510 add_bzero(bzero_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
511 add_bzero(bzero_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
512 add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
515 add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
519 # ------------------------------------------------------------------------------
521 # ------------------------------------------------------------------------------
523 function(add_memcmp memcmp_name)
524 add_implementation(memcmp ${memcmp_name}
525 SRCS ${LIBC_SOURCE_DIR}/src/string/memcmp.cpp
526 HDRS ${LIBC_SOURCE_DIR}/src/string/memcmp.h
528 .memory_utils.memcmp_implementation
534 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
535 add_memcmp(memcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
536 add_memcmp(memcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
537 add_memcmp(memcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
538 add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)
539 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
541 elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
542 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
545 add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
549 # ------------------------------------------------------------------------------
551 # ------------------------------------------------------------------------------
553 function(add_memcpy memcpy_name)
554 add_implementation(memcpy ${memcpy_name}
555 SRCS ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp
556 HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h
558 .memory_utils.memcpy_implementation
564 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
565 add_memcpy(memcpy_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
566 add_memcpy(memcpy_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
567 add_memcpy(memcpy_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
568 add_memcpy(memcpy_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
569 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
571 elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
572 # Disable tail merging as it leads to lower performance.
573 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
574 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
575 add_memcpy(memcpy MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
577 add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
581 # ------------------------------------------------------------------------------
583 # ------------------------------------------------------------------------------
585 function(add_memmove memmove_name)
586 add_implementation(memmove ${memmove_name}
587 SRCS ${LIBC_SOURCE_DIR}/src/string/memmove.cpp
588 HDRS ${LIBC_SOURCE_DIR}/src/string/memmove.h
590 .memory_utils.memcpy_implementation
596 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
597 add_memmove(memmove_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
598 add_memmove(memmove_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
599 add_memmove(memmove_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
600 add_memmove(memmove_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
601 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
603 elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
604 # Disable tail merging as it leads to lower performance.
605 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
606 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
607 add_memmove(memmove MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
609 add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
613 # ------------------------------------------------------------------------------
615 # ------------------------------------------------------------------------------
617 function(add_memset memset_name)
618 add_implementation(memset ${memset_name}
619 SRCS ${LIBC_SOURCE_DIR}/src/string/memset.cpp
620 HDRS ${LIBC_SOURCE_DIR}/src/string/memset.h
622 .memory_utils.memset_implementation
628 if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
629 add_memset(memset_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
630 add_memset(memset_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
631 add_memset(memset_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
632 add_memset(memset_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
633 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
635 elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
636 # Disable tail merging as it leads to lower performance.
637 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
638 MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
639 add_memset(memset MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
641 add_memset(memset_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})