[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
2020-02-20 22:00:45 +08:00
|
|
|
# Cpu features definition and flags
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
2020-02-20 22:00:45 +08:00
|
|
|
|
2021-05-12 15:24:53 +08:00
|
|
|
# Initialize ALL_CPU_FEATURES as empty list.
|
|
|
|
set(ALL_CPU_FEATURES "")
|
|
|
|
|
2021-05-05 23:52:42 +08:00
|
|
|
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
|
2022-05-09 01:47:08 +08:00
|
|
|
set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX2 AVX512F FMA)
|
2021-05-12 15:24:53 +08:00
|
|
|
set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
|
|
|
|
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
|
|
|
|
set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=native)
|
2020-02-20 22:00:45 +08:00
|
|
|
endif()
|
|
|
|
|
2021-05-12 15:24:53 +08:00
|
|
|
# Making sure ALL_CPU_FEATURES is sorted.
|
|
|
|
list(SORT ALL_CPU_FEATURES)
|
|
|
|
|
2021-01-22 13:21:48 +08:00
|
|
|
# Function to check whether the target CPU supports the provided set of features.
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# Usage:
|
2021-01-22 13:21:48 +08:00
|
|
|
# cpu_supports(
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# <output variable>
|
|
|
|
# <list of cpu features>
|
|
|
|
# )
|
2021-01-22 13:21:48 +08:00
|
|
|
function(cpu_supports output_var features)
|
|
|
|
_intersection(var "${LIBC_CPU_FEATURES}" "${features}")
|
|
|
|
if("${var}" STREQUAL "${features}")
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
set(${output_var} TRUE PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
unset(${output_var} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Internal helpers and utilities.
|
|
|
|
# ------------------------------------------------------------------------------
|
2020-02-20 22:00:45 +08:00
|
|
|
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# Computes the intersection between two lists.
|
|
|
|
function(_intersection output_var list1 list2)
|
|
|
|
foreach(element IN LISTS list1)
|
|
|
|
if("${list2}" MATCHES "(^|;)${element}(;|$)")
|
|
|
|
list(APPEND tmp "${element}")
|
2020-02-20 22:00:45 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
set(${output_var} ${tmp} PARENT_SCOPE)
|
2020-02-20 22:00:45 +08:00
|
|
|
endfunction()
|
|
|
|
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
# Generates a cpp file to introspect the compiler defined flags.
|
|
|
|
function(_generate_check_code)
|
|
|
|
foreach(feature IN LISTS ALL_CPU_FEATURES)
|
|
|
|
set(DEFINITIONS
|
|
|
|
"${DEFINITIONS}
|
|
|
|
#ifdef __${feature}__
|
|
|
|
\"${feature}\",
|
|
|
|
#endif")
|
2020-02-20 22:00:45 +08:00
|
|
|
endforeach()
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
configure_file(
|
|
|
|
"${LIBC_SOURCE_DIR}/cmake/modules/cpu_features/check_cpu_features.cpp.in"
|
|
|
|
"cpu_features/check_cpu_features.cpp" @ONLY)
|
2020-02-20 22:00:45 +08:00
|
|
|
endfunction()
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
_generate_check_code()
|
2020-02-20 22:00:45 +08:00
|
|
|
|
2021-05-12 15:24:53 +08:00
|
|
|
set(LIBC_CPU_FEATURES "" CACHE PATH "Host supported CPU features")
|
|
|
|
|
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
|
|
_intersection(cpu_features "${ALL_CPU_FEATURES}" "${LIBC_CPU_FEATURES}")
|
|
|
|
if(NOT "${cpu_features}" STREQUAL "${LIBC_CPU_FEATURES}")
|
|
|
|
message(FATAL_ERROR "Unsupported CPU features: ${cpu_features}")
|
|
|
|
endif()
|
2022-05-09 01:47:08 +08:00
|
|
|
message(STATUS "Set CPU features: ${cpu_features}")
|
2021-05-12 15:24:53 +08:00
|
|
|
set(LIBC_CPU_FEATURES "${cpu_features}")
|
|
|
|
else()
|
|
|
|
# Populates the LIBC_CPU_FEATURES list from host.
|
2020-02-20 22:00:45 +08:00
|
|
|
try_run(
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
run_result compile_result "${CMAKE_CURRENT_BINARY_DIR}/check_${feature}"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cpu_features/check_cpu_features.cpp"
|
2021-05-12 15:24:53 +08:00
|
|
|
COMPILE_DEFINITIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
COMPILE_OUTPUT_VARIABLE compile_output
|
|
|
|
RUN_OUTPUT_VARIABLE run_output)
|
2021-01-21 16:01:18 +08:00
|
|
|
if("${run_result}" EQUAL 0)
|
2022-05-09 01:47:08 +08:00
|
|
|
message(STATUS "Set CPU features: ${run_output}")
|
2021-05-12 15:24:53 +08:00
|
|
|
set(LIBC_CPU_FEATURES "${run_output}")
|
2021-01-21 16:01:18 +08:00
|
|
|
elseif(NOT ${compile_result})
|
|
|
|
message(FATAL_ERROR "Failed to compile: ${compile_output}")
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
else()
|
2021-01-21 16:01:18 +08:00
|
|
|
message(FATAL_ERROR "Failed to run: ${run_output}")
|
2020-02-20 22:00:45 +08:00
|
|
|
endif()
|
2020-06-11 01:55:00 +08:00
|
|
|
endif()
|