From 7c1edc83e2620bfbdc1911aa7e8fca2ace76969b Mon Sep 17 00:00:00 2001 From: Ilya Kurdyukov Date: Wed, 31 Aug 2022 16:04:35 +0700 Subject: [PATCH] libbotan-2.19.1 e2k support --- src/build-data/arch/e2k.txt | 11 +++++++ src/build-data/detect_arch.cpp | 3 ++ src/lib/block/aes/aes_vperm/info.txt | 3 ++ src/lib/filters/filter.h | 4 +++ src/lib/misc/zfec/zfec_vperm/info.txt | 3 ++ src/lib/utils/cpuid/cpuid.cpp | 7 ++++ src/lib/utils/cpuid/cpuid.h | 44 +++++++++++++++++++++++++- src/lib/utils/ghash/ghash_cpu/info.txt | 3 ++ src/lib/utils/os_utils.cpp | 8 +++++ src/lib/utils/simd/info.txt | 2 ++ 10 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/build-data/arch/e2k.txt diff --git a/src/build-data/arch/e2k.txt b/src/build-data/arch/e2k.txt new file mode 100644 index 0000000..b2cafe7 --- /dev/null +++ b/src/build-data/arch/e2k.txt @@ -0,0 +1,11 @@ +endian little +wordsize 64 + +family e2k + + +avx2 +sse2 +sse41 +ssse3 + diff --git a/src/build-data/detect_arch.cpp b/src/build-data/detect_arch.cpp index 3a4bf8e..4d23cc9 100644 --- a/src/build-data/detect_arch.cpp +++ b/src/build-data/detect_arch.cpp @@ -73,6 +73,9 @@ #elif defined(__loongarch64) LOONGARCH64 +#elif defined(__e2k__) + E2K + #else UNKNOWN diff --git a/src/lib/block/aes/aes_vperm/info.txt b/src/lib/block/aes/aes_vperm/info.txt index 0b7eaba..4ee7038 100644 --- a/src/lib/block/aes/aes_vperm/info.txt +++ b/src/lib/block/aes/aes_vperm/info.txt @@ -9,6 +9,8 @@ x86_32:sse2 x86_64:sse2 x86_32:ssse3 x86_64:ssse3 +e2k:sse2 +e2k:ssse3 arm32:neon arm64:neon ppc32:altivec @@ -18,6 +20,7 @@ ppc64:altivec x86_32 x86_64 +e2k arm32 arm64 ppc32 diff --git a/src/lib/filters/filter.h b/src/lib/filters/filter.h index 94b9c6c..81d262b 100644 --- a/src/lib/filters/filter.h +++ b/src/lib/filters/filter.h @@ -155,7 +155,11 @@ class BOTAN_PUBLIC_API(2,0) Fanout_Filter : public Filter void attach(Filter* f) { Filter::attach(f); } +#ifdef __e2k__ + public: /* LCC bug workaround */ +#else private: +#endif friend class Threaded_Fork; using Filter::m_write_queue; using Filter::total_ports; diff --git a/src/lib/misc/zfec/zfec_vperm/info.txt b/src/lib/misc/zfec/zfec_vperm/info.txt index c0731ca..dc398e1 100644 --- a/src/lib/misc/zfec/zfec_vperm/info.txt +++ b/src/lib/misc/zfec/zfec_vperm/info.txt @@ -7,6 +7,8 @@ x86_32:sse2 x86_64:sse2 x86_32:ssse3 x86_64:ssse3 +e2k:sse2 +e2k:ssse3 arm32:neon arm64:neon @@ -14,6 +16,7 @@ arm64:neon x86_32 x86_64 +e2k arm32 arm64 diff --git a/src/lib/utils/cpuid/cpuid.cpp b/src/lib/utils/cpuid/cpuid.cpp index e76e12e..d98b60d 100644 --- a/src/lib/utils/cpuid/cpuid.cpp +++ b/src/lib/utils/cpuid/cpuid.cpp @@ -58,6 +58,13 @@ std::string CPUID::to_string() CPUID_PRINT(avx512_clmul); #endif +#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY) + CPUID_PRINT(sse2); + CPUID_PRINT(ssse3); + CPUID_PRINT(sse41); + CPUID_PRINT(avx2); +#endif + #if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) CPUID_PRINT(altivec); CPUID_PRINT(power_crypto); diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h index 04d0bbd..effcd41 100644 --- a/src/lib/utils/cpuid/cpuid.h +++ b/src/lib/utils/cpuid/cpuid.h @@ -355,13 +355,55 @@ class BOTAN_PUBLIC_API(2,1) CPUID final { return has_cpuid_bit(CPUID_RDSEED_BIT); } #endif +#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY) + /** + * Check if the processor supports SSE2 + */ + static bool has_sse2() +#ifdef __SSE2__ + { return true; } +#else + { return false; } +#endif + + /** + * Check if the processor supports SSSE3 + */ + static bool has_ssse3() +#ifdef __SSSE3__ + { return true; } +#else + { return false; } +#endif + + /** + * Check if the processor supports SSE4.1 + */ + static bool has_sse41() +#ifdef __SSE4_1__ + { return true; } +#else + { return false; } +#endif + + /** + * Check if the processor supports AVX2 + */ + static bool has_avx2() +#ifdef __AVX2__ + { return true; } +#else + { return false; } +#endif +#endif + /** * Check if the processor supports byte-level vector permutes * (SSSE3, NEON, Altivec) */ static bool has_vperm() { -#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) +#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) || defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY) return has_ssse3(); #elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) return has_neon(); diff --git a/src/lib/utils/ghash/ghash_cpu/info.txt b/src/lib/utils/ghash/ghash_cpu/info.txt index 1f56377..97ab5e5 100644 --- a/src/lib/utils/ghash/ghash_cpu/info.txt +++ b/src/lib/utils/ghash/ghash_cpu/info.txt @@ -15,6 +15,8 @@ x86_32:aesni x86_64:sse2 x86_64:ssse3 x86_64:aesni +e2k:sse2 +e2k:ssse3 arm64:neon arm64:armv8crypto ppc64:powercrypto @@ -23,6 +25,7 @@ ppc64:powercrypto x86_32 x86_64 +e2k arm64 ppc64 diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index f5151da..f21aaf4 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -151,6 +151,10 @@ bool OS::running_in_privileged_state() #endif } +#if defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY) +#include +#endif + uint64_t OS::get_cpu_cycle_counter() { uint64_t rtc = 0; @@ -160,6 +164,10 @@ uint64_t OS::get_cpu_cycle_counter() ::QueryPerformanceCounter(&tv); rtc = tv.QuadPart; +#elif defined(BOTAN_TARGET_CPU_IS_E2K_FAMILY) + unsigned aux; + rtc = __rdtscp(&aux); + #elif defined(BOTAN_USE_GCC_INLINE_ASM) #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) diff --git a/src/lib/utils/simd/info.txt b/src/lib/utils/simd/info.txt index 4a7044a..c70f3a2 100644 --- a/src/lib/utils/simd/info.txt +++ b/src/lib/utils/simd/info.txt @@ -10,6 +10,7 @@ simd_32.h x86_32:sse2 x86_64:sse2 x32:sse2 +e2k:sse2 arm32:neon arm64:neon ppc32:altivec @@ -20,6 +21,7 @@ ppc64:altivec x86_32 x86_64 x32 +e2k arm32 arm64 ppc32 -- 2.34.1