From a8e9b9069e006df2899dd5369b12f2b96b9833be Mon Sep 17 00:00:00 2001 From: Konstantnos Margaritis Date: Tue, 21 Nov 2023 17:13:33 +0000 Subject: [PATCH] enable SIMDe backend --- src/nfa/shufti_simd.hpp | 2 +- src/nfa/truffle_simd.hpp | 2 +- src/nfa/vermicelli_simd.cpp | 2 +- src/util/arch/common/simd_utils.h | 4 ++-- src/util/bitutils.h | 25 +++++++++++++++++++++++++ src/util/intrinsics.h | 2 -- src/util/match.hpp | 2 +- src/util/simd_types.h | 9 +++++++-- src/util/simd_utils.h | 2 ++ 9 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/nfa/shufti_simd.hpp b/src/nfa/shufti_simd.hpp index 0f8e2a7b..30df80bf 100644 --- a/src/nfa/shufti_simd.hpp +++ b/src/nfa/shufti_simd.hpp @@ -52,7 +52,7 @@ template static really_inline SuperVector blockDoubleMask(SuperVector mask1_lo, SuperVector mask1_hi, SuperVector mask2_lo, SuperVector mask2_hi, SuperVector chars); -#if defined(ARCH_IA32) || defined(ARCH_X86_64) +#if defined(ARCH_IA32) || defined(ARCH_X86_64) || defined(SIMDE_BACKEND) #include "x86/shufti.hpp" #elif defined(ARCH_ARM32) || defined(ARCH_AARCH64) #include "arm/shufti.hpp" diff --git a/src/nfa/truffle_simd.hpp b/src/nfa/truffle_simd.hpp index e07e92f6..0214833c 100644 --- a/src/nfa/truffle_simd.hpp +++ b/src/nfa/truffle_simd.hpp @@ -45,7 +45,7 @@ template static really_inline const SuperVector blockSingleMask(SuperVector shuf_mask_lo_highclear, SuperVector shuf_mask_lo_highset, SuperVector chars); -#if defined(ARCH_IA32) || defined(ARCH_X86_64) +#if defined(ARCH_IA32) || defined(ARCH_X86_64) || defined(SIMDE_BACKEND) #include "x86/truffle.hpp" #elif defined(ARCH_ARM32) || defined(ARCH_AARCH64) #include "arm/truffle.hpp" diff --git a/src/nfa/vermicelli_simd.cpp b/src/nfa/vermicelli_simd.cpp index a0da0719..c5fbc39a 100644 --- a/src/nfa/vermicelli_simd.cpp +++ b/src/nfa/vermicelli_simd.cpp @@ -71,7 +71,7 @@ const u8 *vermicelliDoubleMaskedBlock(SuperVector const data, SuperVector SuperVector const mask1, SuperVector const mask2, u8 const c1, u8 const c2, u8 const m1, u8 const m2, u8 const *buf, u16 const len); -#if defined(ARCH_IA32) || defined(ARCH_X86_64) +#if defined(ARCH_IA32) || defined(ARCH_X86_64) || defined(SIMDE_BACKEND) #include "x86/vermicelli.hpp" #elif defined(ARCH_ARM32) || defined(ARCH_AARCH64) #include "arm/vermicelli.hpp" diff --git a/src/util/arch/common/simd_utils.h b/src/util/arch/common/simd_utils.h index d142ee9a..2542f0f6 100644 --- a/src/util/arch/common/simd_utils.h +++ b/src/util/arch/common/simd_utils.h @@ -41,7 +41,7 @@ #include // for memcpy -#if !defined(HAVE_SIMD_128_BITS) +#if !defined(HAVE_SIMD_128_BITS) && !defined(SIMDE_BACKEND) #error "You need at least a 128-bit capable SIMD engine!" #endif // HAVE_SIMD_128_BITS @@ -88,7 +88,7 @@ static inline void print_m128_2x64(const char *label, m128 vec) { #define print_m128_2x64(label, vec) ; #endif -#if !defined(ARCH_IA32) && !defined(ARCH_X86_64) +#if !defined(ARCH_IA32) && !defined(ARCH_X86_64) && !defined(SIMDE_BACKEND) #define ZEROES_8 0, 0, 0, 0, 0, 0, 0, 0 #define ZEROES_31 ZEROES_8, ZEROES_8, ZEROES_8, 0, 0, 0, 0, 0, 0, 0 #define ZEROES_32 ZEROES_8, ZEROES_8, ZEROES_8, ZEROES_8 diff --git a/src/util/bitutils.h b/src/util/bitutils.h index ffc8f45d..7e006158 100644 --- a/src/util/bitutils.h +++ b/src/util/bitutils.h @@ -51,6 +51,31 @@ #include "util/arch/arm/bitutils.h" #elif defined(ARCH_PPC64EL) #include "util/arch/ppc64el/bitutils.h" +#else +#include "util/arch/common/bitutils.h" +#define clz32_impl clz32_impl_c +#define clz64_impl clz64_impl_c +#define ctz32_impl ctz32_impl_c +#define ctz64_impl ctz64_impl_c +#define lg2_impl lg2_impl_c +#define lg2_64_impl lg2_64_impl_c +#define findAndClearLSB_32_impl findAndClearLSB_32_impl_c +#define findAndClearLSB_64_impl findAndClearLSB_64_impl_c +#define findAndClearMSB_32_impl findAndClearMSB_32_impl_c +#define findAndClearMSB_64_impl findAndClearMSB_64_impl_c +#define compress32_impl compress32_impl_c +#define compress64_impl compress64_impl_c +#define compress128_impl compress128_impl_c +#define expand32_impl expand32_impl_c +#define expand64_impl expand64_impl_c +#define expand128_impl expand128_impl_c +#define bf64_iterate_impl bf64_iterate_impl_c +#define bf64_set_impl bf64_set_impl_c +#define bf64_unset_impl bf64_unset_impl_c +#define rank_in_mask32_impl rank_in_mask32_impl_c +#define rank_in_mask64_impl rank_in_mask64_impl_c +#define pext32_impl pext32_impl_c +#define pext64_impl pext64_impl_c #endif static really_inline diff --git a/src/util/intrinsics.h b/src/util/intrinsics.h index 08eb6ba6..64f9e9ba 100644 --- a/src/util/intrinsics.h +++ b/src/util/intrinsics.h @@ -74,8 +74,6 @@ # endif #elif defined(USE_PPC64EL_ALTIVEC_H) #include -#else -#error no intrinsics file #endif #endif // INTRINSICS_H diff --git a/src/util/match.hpp b/src/util/match.hpp index 003c665f..68497349 100644 --- a/src/util/match.hpp +++ b/src/util/match.hpp @@ -49,7 +49,7 @@ const u8 *first_zero_match_inverted(const u8 *buf, SuperVector v, u16 const l template const u8 *last_zero_match_inverted(const u8 *buf, SuperVector v, u16 len = S); -#if defined(ARCH_IA32) || defined(ARCH_X86_64) +#if defined(ARCH_IA32) || defined(ARCH_X86_64) || defined(SIMDE_BACKEND) #include "util/arch/x86/match.hpp" #elif defined(ARCH_ARM32) || defined(ARCH_AARCH64) #include "util/arch/arm/match.hpp" diff --git a/src/util/simd_types.h b/src/util/simd_types.h index 4f0fd1a9..b9e2a492 100644 --- a/src/util/simd_types.h +++ b/src/util/simd_types.h @@ -42,8 +42,13 @@ #include "util/arch/ppc64el/simd_types.h" #endif -#if !defined(m128) && !defined(HAVE_SIMD_128_BITS) -typedef struct ALIGN_DIRECTIVE {u64a hi; u64a lo;} m128; +#if defined(SIMDE_BACKEND) +#define VECTORSIZE 16 +#define SIMDE_ENABLE_NATIVE_ALIASES +#define SIMDE_NO_NATIVE +#include "simde/simde/x86/sse4.2.h" +typedef simde__m128i m128; +#define HAVE_SIMD_128_BITS #endif #if !defined(m256) && !defined(HAVE_SIMD_256_BITS) diff --git a/src/util/simd_utils.h b/src/util/simd_utils.h index 2f0012c6..0ed66177 100644 --- a/src/util/simd_utils.h +++ b/src/util/simd_utils.h @@ -67,6 +67,8 @@ extern const char vbs_mask_data[]; #include "util/arch/arm/simd_utils.h" #elif defined(ARCH_PPC64EL) #include "util/arch/ppc64el/simd_utils.h" +#elif defined(SIMDE_BACKEND) +#include "util/arch/simde/simd_utils.h" #endif #include "util/arch/common/simd_utils.h"