Skip to content

Commit

Permalink
Static dispatch Arm-optimized-routines instead of dynamic dispatch (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lloyd-Pottiger authored Apr 2, 2024
1 parent 52fc334 commit f04b16d
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 58 deletions.
6 changes: 2 additions & 4 deletions contrib/arm-optimized-routines-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
# the qualities can be ensured while using it also enables us to keep sync with latest
# acceleration techniques.

set(CMAKE_C_FLAGS "")
ENABLE_LANGUAGE(C)
ENABLE_LANGUAGE(ASM)
set(TIFLASH_AOR_DIR ../arm-optimized-routines)
set(TIFLASH_AOR_DIR ${TiFlash_SOURCE_DIR}/contrib/arm-optimized-routines)

file(GLOB TIFLASH_AARCH64_STRING_FILES ${TIFLASH_AOR_DIR}/string/aarch64/*.S)
add_library(tiflash-aarch64-string STATIC ${TIFLASH_AARCH64_STRING_FILES} src/aor.c)
target_compile_options(tiflash-aarch64-string PRIVATE -march=armv8-a+sve)
add_library(tiflash-aarch64-string STATIC ${TIFLASH_AARCH64_STRING_FILES})
target_include_directories(tiflash-aarch64-string PRIVATE ${TIFLASH_AOR_DIR}/string/include)

file(GLOB TIFLASH_AARCH64_MATH_FILES ${TIFLASH_AOR_DIR}/math/*.c)
Expand Down
49 changes: 0 additions & 49 deletions contrib/arm-optimized-routines-cmake/src/aor.c

This file was deleted.

3 changes: 3 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ if (NOT NO_WERROR)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif ()

# Optimized routines under arm
add_subdirectory (libarm-optimized-routines)
add_subdirectory (libcommon)
add_subdirectory (libpocoext)
add_subdirectory (libdaemon)
# Optimized memcpy under x86_64
add_subdirectory (libmemcpy)

if (GLIBC_COMPATIBILITY)
Expand Down
44 changes: 44 additions & 0 deletions libs/libarm-optimized-routines/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

option(USE_ARM_OPTIMIZED_ROUTINES "Use ARM optimized routines" ON)

set (aor_sources)

if (ARCH_AARCH64 AND OS_LINUX AND USE_ARM_OPTIMIZED_ROUTINES)
list (APPEND aor_sources aor.cpp aor.h)
else ()
set (USE_ARM_OPTIMIZED_ROUTINES OFF)
endif ()

check_then_add_sources_compile_flag (
TIFLASH_ENABLE_ASIMD_SUPPORT
"-march=armv8-a+simd"
aor_sources
)

check_then_add_sources_compile_flag (
TIFLASH_ENABLE_SVE_SUPPORT
"-march=armv8-a+sve"
aor_sources
)

if (USE_ARM_OPTIMIZED_ROUTINES)
add_library (aor STATIC ${aor_sources})
target_link_libraries(aor PUBLIC tiflash-aarch64-string tiflash-aarch64-math)
target_include_directories(aor PUBLIC ${TiFlash_SOURCE_DIR}/contrib/arm-optimized-routines/string/include)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
endif ()
100 changes: 100 additions & 0 deletions libs/libarm-optimized-routines/aor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "aor.h"

extern "C" __attribute__((visibility("default"))) void * memcpy(
void * __restrict dst,
const void * __restrict src,
size_t size)
{
return inline_memcpy(dst, src, size);
}

extern "C" __attribute__((visibility("default"))) void * memmove(void * __restrict dst, const void * src, size_t size)
{
return inline_memmove(dst, src, size);
}

extern "C" __attribute__((visibility("default"))) void * memset(void * dst, int c, size_t size)
{
return inline_memset(dst, c, size);
}

extern "C" __attribute__((visibility("default"))) void * memchr(const void * src, int c, size_t size)
{
return inline_memchr(src, c, size);
}

extern "C" __attribute__((visibility("default"))) void * memrchr(const void * src, int c, size_t size)
{
return inline_memrchr(src, c, size);
}

extern "C" __attribute__((visibility("default"))) int memcmp(const void * src1, const void * src2, size_t size)
{
return inline_memcmp(src1, src2, size);
}

extern "C" __attribute__((visibility("default"))) inline char * strcpy(
char * __restrict dst_,
const char * __restrict src_)
{
return inline_strcpy(dst_, src_);
}

extern "C" __attribute__((visibility("default"))) inline char * stpcpy(
char * __restrict dst_,
const char * __restrict src_)
{
return inline_stpcpy(dst_, src_);
}

extern "C" __attribute__((visibility("default"))) inline int strcmp(const char * src1_, const char * src2_)
{
return inline_strcmp(src1_, src2_);
}

extern "C" __attribute__((visibility("default"))) inline char * strchr(const char * src_, int c)
{
return inline_strchr(src_, c);
}

extern "C" __attribute__((visibility("default"))) inline char * strrchr(const char * src_, int c)
{
return inline_strrchr(src_, c);
}

extern "C" __attribute__((visibility("default"))) inline char * strchrnul(const char * src_, int c)
{
return inline_strchrnul(src_, c);
}

extern "C" __attribute__((visibility("default"))) inline size_t strlen(const char * src_)
{
return inline_strlen(src_);
}

extern "C" __attribute__((visibility("default"))) inline size_t strnlen(const char * src_, size_t size)
{
return inline_strnlen(src_, size);
}

extern "C" __attribute__((visibility("default"))) inline int strncmp(
const char * src1_,
const char * src2_,
size_t size)
{
return inline_strncmp(src1_, src2_, size);
}
Loading

0 comments on commit f04b16d

Please sign in to comment.