diff options
-rw-r--r-- | src/engine/simd_engine/simd_engine.cpp | 2 | ||||
-rw-r--r-- | src/simd/simd_32.h | 2 | ||||
-rw-r--r-- | src/simd/simd_scalar/simd_scalar.h | 129 | ||||
-rw-r--r-- | src/utils/assert.h | 5 |
4 files changed, 73 insertions, 65 deletions
diff --git a/src/engine/simd_engine/simd_engine.cpp b/src/engine/simd_engine/simd_engine.cpp index 70529f1fd..3f4e2b7aa 100644 --- a/src/engine/simd_engine/simd_engine.cpp +++ b/src/engine/simd_engine/simd_engine.cpp @@ -80,6 +80,8 @@ SIMD_Engine::find_hash(const SCAN_Name& request, return new SHA_160_SSE2; #endif + BOTAN_UNUSED(request); + return nullptr; } diff --git a/src/simd/simd_32.h b/src/simd/simd_32.h index 4ef0cea85..17cf5b91e 100644 --- a/src/simd/simd_32.h +++ b/src/simd/simd_32.h @@ -20,7 +20,7 @@ #elif defined(BOTAN_HAS_SIMD_SCALAR) #include <botan/internal/simd_scalar.h> - namespace Botan { typedef SIMD_Scalar SIMD_32; } + namespace Botan { typedef SIMD_4_Scalar<u32bit> SIMD_32; } #else #error "No SIMD module defined" diff --git a/src/simd/simd_scalar/simd_scalar.h b/src/simd/simd_scalar/simd_scalar.h index 2c68622af..cf1145794 100644 --- a/src/simd/simd_scalar/simd_scalar.h +++ b/src/simd/simd_scalar/simd_scalar.h @@ -1,6 +1,6 @@ /* -* Scalar emulation of SIMD 32-bit operations -* (C) 2009 Jack Lloyd +* Scalar emulation of SIMD +* (C) 2009,2013 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -17,12 +17,13 @@ namespace Botan { * Fake SIMD, using plain scalar operations * Often still faster than iterative on superscalar machines */ -class SIMD_Scalar +template<typename T> +class SIMD_4_Scalar { public: static bool enabled() { return true; } - SIMD_Scalar(const u32bit B[4]) + SIMD_4_Scalar(const T B[4]) { R0 = B[0]; R1 = B[1]; @@ -30,7 +31,7 @@ class SIMD_Scalar R3 = B[3]; } - SIMD_Scalar(u32bit B0, u32bit B1, u32bit B2, u32bit B3) + SIMD_4_Scalar(T B0, T B1, T B2, T B3) { R0 = B0; R1 = B1; @@ -38,7 +39,7 @@ class SIMD_Scalar R3 = B3; } - SIMD_Scalar(u32bit B) + SIMD_4_Scalar(T B) { R0 = B; R1 = B; @@ -46,22 +47,22 @@ class SIMD_Scalar R3 = B; } - static SIMD_Scalar load_le(const void* in) + static SIMD_4_Scalar<T> load_le(const void* in) { const byte* in_b = static_cast<const byte*>(in); - return SIMD_Scalar(Botan::load_le<u32bit>(in_b, 0), - Botan::load_le<u32bit>(in_b, 1), - Botan::load_le<u32bit>(in_b, 2), - Botan::load_le<u32bit>(in_b, 3)); + return SIMD_4_Scalar<T>(Botan::load_le<T>(in_b, 0), + Botan::load_le<T>(in_b, 1), + Botan::load_le<T>(in_b, 2), + Botan::load_le<T>(in_b, 3)); } - static SIMD_Scalar load_be(const void* in) + static SIMD_4_Scalar<T> load_be(const void* in) { const byte* in_b = static_cast<const byte*>(in); - return SIMD_Scalar(Botan::load_be<u32bit>(in_b, 0), - Botan::load_be<u32bit>(in_b, 1), - Botan::load_be<u32bit>(in_b, 2), - Botan::load_be<u32bit>(in_b, 3)); + return SIMD_4_Scalar<T>(Botan::load_be<T>(in_b, 0), + Botan::load_be<T>(in_b, 1), + Botan::load_be<T>(in_b, 2), + Botan::load_be<T>(in_b, 3)); } void store_le(byte out[]) const @@ -90,7 +91,7 @@ class SIMD_Scalar R3 = Botan::rotate_right(R3, rot); } - void operator+=(const SIMD_Scalar& other) + void operator+=(const SIMD_4_Scalar<T>& other) { R0 += other.R0; R1 += other.R1; @@ -98,15 +99,15 @@ class SIMD_Scalar R3 += other.R3; } - SIMD_Scalar operator+(const SIMD_Scalar& other) const + SIMD_4_Scalar<T> operator+(const SIMD_4_Scalar<T>& other) const { - return SIMD_Scalar(R0 + other.R0, + return SIMD_4_Scalar<T>(R0 + other.R0, R1 + other.R1, R2 + other.R2, R3 + other.R3); } - void operator-=(const SIMD_Scalar& other) + void operator-=(const SIMD_4_Scalar<T>& other) { R0 -= other.R0; R1 -= other.R1; @@ -114,15 +115,15 @@ class SIMD_Scalar R3 -= other.R3; } - SIMD_Scalar operator-(const SIMD_Scalar& other) const + SIMD_4_Scalar<T> operator-(const SIMD_4_Scalar<T>& other) const { - return SIMD_Scalar(R0 - other.R0, - R1 - other.R1, - R2 - other.R2, - R3 - other.R3); + return SIMD_4_Scalar<T>(R0 - other.R0, + R1 - other.R1, + R2 - other.R2, + R3 - other.R3); } - void operator^=(const SIMD_Scalar& other) + void operator^=(const SIMD_4_Scalar<T>& other) { R0 ^= other.R0; R1 ^= other.R1; @@ -130,15 +131,15 @@ class SIMD_Scalar R3 ^= other.R3; } - SIMD_Scalar operator^(const SIMD_Scalar& other) const + SIMD_4_Scalar<T> operator^(const SIMD_4_Scalar<T>& other) const { - return SIMD_Scalar(R0 ^ other.R0, + return SIMD_4_Scalar<T>(R0 ^ other.R0, R1 ^ other.R1, R2 ^ other.R2, R3 ^ other.R3); } - void operator|=(const SIMD_Scalar& other) + void operator|=(const SIMD_4_Scalar<T>& other) { R0 |= other.R0; R1 |= other.R1; @@ -146,15 +147,15 @@ class SIMD_Scalar R3 |= other.R3; } - SIMD_Scalar operator&(const SIMD_Scalar& other) + SIMD_4_Scalar<T> operator&(const SIMD_4_Scalar<T>& other) { - return SIMD_Scalar(R0 & other.R0, - R1 & other.R1, - R2 & other.R2, - R3 & other.R3); + return SIMD_4_Scalar<T>(R0 & other.R0, + R1 & other.R1, + R2 & other.R2, + R3 & other.R3); } - void operator&=(const SIMD_Scalar& other) + void operator&=(const SIMD_4_Scalar<T>& other) { R0 &= other.R0; R1 &= other.R1; @@ -162,51 +163,51 @@ class SIMD_Scalar R3 &= other.R3; } - SIMD_Scalar operator<<(size_t shift) const + SIMD_4_Scalar<T> operator<<(size_t shift) const { - return SIMD_Scalar(R0 << shift, - R1 << shift, - R2 << shift, - R3 << shift); + return SIMD_4_Scalar<T>(R0 << shift, + R1 << shift, + R2 << shift, + R3 << shift); } - SIMD_Scalar operator>>(size_t shift) const + SIMD_4_Scalar<T> operator>>(size_t shift) const { - return SIMD_Scalar(R0 >> shift, - R1 >> shift, - R2 >> shift, - R3 >> shift); + return SIMD_4_Scalar<T>(R0 >> shift, + R1 >> shift, + R2 >> shift, + R3 >> shift); } - SIMD_Scalar operator~() const + SIMD_4_Scalar<T> operator~() const { - return SIMD_Scalar(~R0, ~R1, ~R2, ~R3); + return SIMD_4_Scalar<T>(~R0, ~R1, ~R2, ~R3); } // (~reg) & other - SIMD_Scalar andc(const SIMD_Scalar& other) + SIMD_4_Scalar<T> andc(const SIMD_4_Scalar<T>& other) { - return SIMD_Scalar(~R0 & other.R0, - ~R1 & other.R1, - ~R2 & other.R2, - ~R3 & other.R3); + return SIMD_4_Scalar<T>(~R0 & other.R0, + ~R1 & other.R1, + ~R2 & other.R2, + ~R3 & other.R3); } - SIMD_Scalar bswap() const + SIMD_4_Scalar<T> bswap() const { - return SIMD_Scalar(reverse_bytes(R0), - reverse_bytes(R1), - reverse_bytes(R2), - reverse_bytes(R3)); + return SIMD_4_Scalar<T>(reverse_bytes(R0), + reverse_bytes(R1), + reverse_bytes(R2), + reverse_bytes(R3)); } - static void transpose(SIMD_Scalar& B0, SIMD_Scalar& B1, - SIMD_Scalar& B2, SIMD_Scalar& B3) + static void transpose(SIMD_4_Scalar<T>& B0, SIMD_4_Scalar<T>& B1, + SIMD_4_Scalar<T>& B2, SIMD_4_Scalar<T>& B3) { - SIMD_Scalar T0(B0.R0, B1.R0, B2.R0, B3.R0); - SIMD_Scalar T1(B0.R1, B1.R1, B2.R1, B3.R1); - SIMD_Scalar T2(B0.R2, B1.R2, B2.R2, B3.R2); - SIMD_Scalar T3(B0.R3, B1.R3, B2.R3, B3.R3); + SIMD_4_Scalar<T> T0(B0.R0, B1.R0, B2.R0, B3.R0); + SIMD_4_Scalar<T> T1(B0.R1, B1.R1, B2.R1, B3.R1); + SIMD_4_Scalar<T> T2(B0.R2, B1.R2, B2.R2, B3.R2); + SIMD_4_Scalar<T> T3(B0.R3, B1.R3, B2.R3, B3.R3); B0 = T0; B1 = T1; @@ -215,7 +216,7 @@ class SIMD_Scalar } private: - u32bit R0, R1, R2, R3; + T R0, R1, R2, R3; }; } diff --git a/src/utils/assert.h b/src/utils/assert.h index 9265be450..f62fae63e 100644 --- a/src/utils/assert.h +++ b/src/utils/assert.h @@ -73,6 +73,11 @@ void BOTAN_DLL assertion_failure(const char* expr_str, __LINE__); \ } while(0) +/** +* Mark variable as unused +*/ +#define BOTAN_UNUSED(v) static_cast<void>(v) + } #endif |