diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -56,7 +56,7 @@ SRCS ${ADD_IMPL_SRCS} HDRS ${ADD_IMPL_HDRS} DEPENDS ${ADD_IMPL_DEPENDS} - COMPILE_OPTIONS ${ADD_IMPL_COMPILE_OPTIONS} ${flags} + COMPILE_OPTIONS ${ADD_IMPL_COMPILE_OPTIONS} ${flags} -O2 ) get_fq_target_name(${impl_name} fq_target_name) set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}") @@ -76,7 +76,7 @@ function(add_memcpy memcpy_name) add_implementation(memcpy ${memcpy_name} - SRCS ${LIBC_SOURCE_DIR}/src/string/${LIBC_STRING_TARGET_ARCH}/memcpy.cpp + SRCS ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h DEPENDS .memory_utils.memory_utils @@ -87,7 +87,11 @@ ) endfunction() -add_memcpy(memcpy MARCH native) +if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") + add_memcpy(memcpy MARCH native) +else() + add_memcpy(memcpy) +endif() # ------------------------------------------------------------------------------ # memset @@ -106,7 +110,11 @@ ) endfunction() -add_memset(memset MARCH native) +if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") + add_memset(memset MARCH native) +else() + add_memset(memset) +endif() # ------------------------------------------------------------------------------ # bzero @@ -126,7 +134,11 @@ ) endfunction() -add_bzero(bzero MARCH native) +if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") + add_bzero(bzero MARCH native) +else() + add_bzero(bzero) +endif() # ------------------------------------------------------------------------------ # Add all other relevant implementations for the native target. diff --git a/libc/src/string/x86/memcpy.cpp b/libc/src/string/memcpy.cpp rename from libc/src/string/x86/memcpy.cpp rename to libc/src/string/memcpy.cpp --- a/libc/src/string/x86/memcpy.cpp +++ b/libc/src/string/memcpy.cpp @@ -12,15 +12,6 @@ namespace __llvm_libc { -static void CopyRepMovsb(char *__restrict dst, const char *__restrict src, - size_t count) { - // FIXME: Add MSVC support with - // #include - // __movsb(reinterpret_cast(dst), - // reinterpret_cast(src), count); - asm volatile("rep movsb" : "+D"(dst), "+S"(src), "+c"(count) : : "memory"); -} - #if defined(__AVX__) #define BEST_SIZE 64 #else @@ -45,8 +36,8 @@ // implementation parameters. // - As compilers and processors get better, the generated code is improved // with little change on the code side. -static void memcpy_x86(char *__restrict dst, const char *__restrict src, - size_t count) { +static void memcpy_impl(char *__restrict dst, const char *__restrict src, + size_t count) { if (count == 0) return; if (count == 1) @@ -75,19 +66,13 @@ if (count < 256) return CopyBlockOverlap<128>(dst, src, count); #endif - // kRepMovsBSize == -1 : Only CopyAligned is used. - // kRepMovsBSize == 0 : Only RepMovsb is used. - // else CopyAligned is used to to kRepMovsBSize and then RepMovsb. - constexpr size_t kRepMovsBSize = -1; - if (count <= kRepMovsBSize) - return CopyAlignedBlocks(dst, src, count); - return CopyRepMovsb(dst, src, count); + return CopyAlignedBlocks(dst, src, count); } void *LLVM_LIBC_ENTRYPOINT(memcpy)(void *__restrict dst, const void *__restrict src, size_t size) { - memcpy_x86(reinterpret_cast(dst), reinterpret_cast(src), - size); + memcpy_impl(reinterpret_cast(dst), + reinterpret_cast(src), size); return dst; }