Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build/run on machines that only have SSE2 with SIMDE #303

Merged
merged 23 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 56 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ include (${CMAKE_MODULE_PATH}/platform.cmake)
# Detect OS and if Fat Runtime is available
include (${CMAKE_MODULE_PATH}/osdetection.cmake)

if(ARCH_X86_86 AND BUILD_SSE2_SIMDE AND NOT FAT_RUNTIME)
set(SIMDE_BACKEND True)
endif()

if(SIMDE_BACKEND)
include (${CMAKE_MODULE_PATH}/simde.cmake)
elseif (ARCH_IA32 OR ARCH_X86_64)
Expand Down Expand Up @@ -947,16 +951,36 @@ else ()
if (NOT BUILD_AVX512VBMI)
set (DISPATCHER_DEFINE "${DISPATCHER_DEFINE} -DDISABLE_AVX512VBMI_DISPATCH")
endif (NOT BUILD_AVX512VBMI)
if(BUILD_SSE2_SIMDE)
set (DISPATCHER_DEFINE "${DISPATCHER_DEFINE} -DVS_SIMDE_BACKEND -DVS_SIMDE_NATIVE -march=core2 -msse2")
endif(BUILD_SSE2_SIMDE)
set_source_files_properties(src/dispatcher.c PROPERTIES
COMPILE_FLAGS "-Wno-unused-parameter -Wno-unused-function ${DISPATCHER_DEFINE}")

if (BUILD_STATIC_LIBS)
add_library(hs_exec_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_LIBS $<TARGET_OBJECTS:hs_exec_core2>)
set_target_properties(hs_exec_core2 PROPERTIES
COMPILE_FLAGS "-march=core2 -msse4.2"
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)

if (BUILD_SSE2_SIMDE)
add_library(hs_exec_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_LIBS $<TARGET_OBJECTS:hs_exec_core2>)
message("Building SIMDE SSE2 version..")
include_directories(${PROJECT_SOURCE_DIR}/simde)
if (CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSIMDE_NO_CHECK_IMMEDIATE_CONSTANT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSIMDE_NO_CHECK_IMMEDIATE_CONSTANT")
endif()

set_target_properties(hs_exec_core2 PROPERTIES
COMPILE_FLAGS "-DVS_SIMDE_BACKEND -DVS_SIMDE_NATIVE -march=core2 -msse2"
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)
else()
add_library(hs_exec_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_LIBS $<TARGET_OBJECTS:hs_exec_core2>)
set_target_properties(hs_exec_core2 PROPERTIES
COMPILE_FLAGS "-march=core2 -msse4.2"
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)
endif(BUILD_SSE2_SIMDE)

add_library(hs_exec_corei7 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_LIBS $<TARGET_OBJECTS:hs_exec_corei7>)
Expand Down Expand Up @@ -1015,13 +1039,32 @@ else ()
# build shared libs
add_library(hs_compile_shared OBJECT ${hs_compile_SRCS})
set_target_properties(hs_compile_shared PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_library(hs_exec_shared_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_SHLIBS $<TARGET_OBJECTS:hs_exec_shared_core2>)
set_target_properties(hs_exec_shared_core2 PROPERTIES
COMPILE_FLAGS "-march=core2 -msse4.2"
POSITION_INDEPENDENT_CODE TRUE
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)

if (BUILD_SSE2_SIMDE)
message("Building SIMDE SSE2 version..")
add_library(hs_exec_shared_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_SHLIBS $<TARGET_OBJECTS:hs_exec_shared_core2>)

include_directories(${PROJECT_SOURCE_DIR}/simde)
if (CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSIMDE_NO_CHECK_IMMEDIATE_CONSTANT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSIMDE_NO_CHECK_IMMEDIATE_CONSTANT")
endif()
set_target_properties(hs_exec_shared_core2 PROPERTIES
COMPILE_FLAGS "-DVS_SIMDE_BACKEND -DVS_SIMDE_NATIVE -march=core2 -msse2"
POSITION_INDEPENDENT_CODE TRUE
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)
else()
add_library(hs_exec_shared_core2 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_SHLIBS $<TARGET_OBJECTS:hs_exec_shared_core2>)
set_target_properties(hs_exec_shared_core2 PROPERTIES
COMPILE_FLAGS "-march=core2 -msse4.2"
POSITION_INDEPENDENT_CODE TRUE
RULE_LAUNCH_COMPILE "${BUILD_WRAPPER} core2 ${CMAKE_MODULE_PATH}/keep.syms.in"
)
endif (BUILD_SSE2_SIMDE)

add_library(hs_exec_shared_corei7 OBJECT ${hs_exec_SRCS})
list(APPEND RUNTIME_SHLIBS $<TARGET_OBJECTS:hs_exec_shared_corei7>)
set_target_properties(hs_exec_shared_corei7 PROPERTIES
Expand Down
7 changes: 7 additions & 0 deletions cmake/simde.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ if (SIMDE_SSE42_H_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVS_SIMDE_NATIVE -DSIMDE_ENABLE_OPENMP -fopenmp-simd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVS_SIMDE_NATIVE -DSIMDE_ENABLE_OPENMP -fopenmp-simd")
endif()

if (BUILD_SSE2_SIMDE)
set(ARCH_C_FLAGS "-msse2")
set(ARCH_CXX_FLAGS "-msse2")
set(X86_ARCH "x86-64")
endif()

else()
message(FATAL_ERROR "SIMDe backend requested but SIMDe is not available on the system")
endif()
8 changes: 7 additions & 1 deletion src/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
#define check_avx512vbmi() (0)
#endif

#if defined(VS_SIMDE_BACKEND)
isildur-g marked this conversation as resolved.
Show resolved Hide resolved
#define CHECK_SSE_LAST() (1)
#else
#define CHECK_SSE_LAST() check_ssse3()
#endif

#define CREATE_DISPATCH(RTYPE, NAME, ...) \
/* create defns */ \
RTYPE JOIN(avx512vbmi_, NAME)(__VA_ARGS__); \
Expand Down Expand Up @@ -111,7 +117,7 @@
else if (check_sse42() && check_popcnt()) { \
fat_dispatch_ ## NAME = &JOIN(corei7_, NAME); \
} \
else if (check_ssse3()) { \
else if (CHECK_SSE_LAST()) { \
isildur-g marked this conversation as resolved.
Show resolved Hide resolved
fat_dispatch_ ## NAME = &JOIN(core2_, NAME); \
} else { \
/* anything else is fail */ \
Expand Down
4 changes: 2 additions & 2 deletions src/hs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ hs_compile_multi_int(const char *const *expressions, const unsigned *flags,
*comp_error = generateCompileError("Unsupported architecture", -1);
return HS_ARCH_ERROR;
}
#endif
#endif
#endif // arch
#endif // FAT_RUNTIME
isildur-g marked this conversation as resolved.
Show resolved Hide resolved

if (!checkMode(mode, comp_error)) {
*db = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/util/arch/x86/cpuid_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ int check_avx512vbmi(void) {

static inline
int check_ssse3(void) {
#if defined(VS_SIMDE_NATIVE) && (defined(ARCH_IA32) || defined(ARCH_X86_64))
return 1;
#else
unsigned int eax, ebx, ecx, edx;
cpuid(1, 0, &eax, &ebx, &ecx, &edx);
return !!(ecx & CPUID_SSSE3);
#endif
}

static inline
Expand Down
2 changes: 2 additions & 0 deletions src/util/simd_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include "ue2common.h"

#if defined(VS_SIMDE_BACKEND)
#ifndef VECTORSIZE
#define VECTORSIZE 16
#endif
#define SIMDE_ENABLE_NATIVE_ALIASES
#if !defined(VS_SIMDE_NATIVE)
#define SIMDE_NO_NATIVE
Expand Down