diff options
author | Jack Lloyd <[email protected]> | 2018-10-05 19:23:14 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-10-05 19:23:14 -0400 |
commit | abc8e0a5a18052c158e2b109e6ac2fa8c51dce6a (patch) | |
tree | 823f797b9130c46e83b370d9663207577e2c1ca0 /src | |
parent | 89e1c718af537ca504dac681f7a388202bc60cdc (diff) |
Add explicit AVX2 function annotations
Needed for single amalagamation file with AVX2 enabled.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/block/serpent/serpent.cpp | 2 | ||||
-rw-r--r-- | src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp | 6 | ||||
-rw-r--r-- | src/lib/utils/simd/simd_avx2/simd_avx2.h | 24 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/lib/block/serpent/serpent.cpp b/src/lib/block/serpent/serpent.cpp index 7bdda0f9f..77cf9f32b 100644 --- a/src/lib/block/serpent/serpent.cpp +++ b/src/lib/block/serpent/serpent.cpp @@ -293,4 +293,6 @@ std::string Serpent::provider() const return "base"; } +#undef key_xor + } diff --git a/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp b/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp index 92ea909a8..3438440da 100644 --- a/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp +++ b/src/lib/block/serpent/serpent_avx2/serpent_avx2.cpp @@ -50,6 +50,7 @@ namespace Botan { B0 = B0.rotr<13>(); \ } while(0) +BOTAN_FUNC_ISA("avx2") void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const { SIMD_8x32 B0 = SIMD_8x32::load_le(in); @@ -99,6 +100,7 @@ void Serpent::avx2_encrypt_8(const uint8_t in[128], uint8_t out[128]) const B3.store_le(out + 96); } +BOTAN_FUNC_ISA("avx2") void Serpent::avx2_decrypt_8(const uint8_t in[128], uint8_t out[128]) const { SIMD_8x32 B0 = SIMD_8x32::load_le(in); @@ -152,4 +154,8 @@ void Serpent::avx2_decrypt_8(const uint8_t in[128], uint8_t out[128]) const B3.store_le(out + 96); } +#undef key_xor +#undef transform +#undef i_transform + } diff --git a/src/lib/utils/simd/simd_avx2/simd_avx2.h b/src/lib/utils/simd/simd_avx2/simd_avx2.h index 3161af962..6f4b37b24 100644 --- a/src/lib/utils/simd/simd_avx2/simd_avx2.h +++ b/src/lib/utils/simd/simd_avx2/simd_avx2.h @@ -22,42 +22,50 @@ class SIMD_8x32 final SIMD_8x32& operator=(SIMD_8x32&& other) = default; SIMD_8x32(SIMD_8x32&& other) = default; + BOTAN_FUNC_ISA("avx2") SIMD_8x32() { m_avx2 = _mm256_setzero_si256(); } + BOTAN_FUNC_ISA("avx2") explicit SIMD_8x32(const uint32_t B[8]) { m_avx2 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(B)); } + BOTAN_FUNC_ISA("avx2") static SIMD_8x32 splat(uint32_t B) { return SIMD_8x32(_mm256_set1_epi32(B)); } + BOTAN_FUNC_ISA("avx2") static SIMD_8x32 load_le(const uint8_t* in) { return SIMD_8x32(_mm256_loadu_si256(reinterpret_cast<const __m256i*>(in))); } + BOTAN_FUNC_ISA("avx2") static SIMD_8x32 load_be(const uint8_t* in) { return load_le(in).bswap(); } + BOTAN_FUNC_ISA("avx2") void store_le(uint8_t out[]) const { _mm256_storeu_si256(reinterpret_cast<__m256i*>(out), m_avx2); } + BOTAN_FUNC_ISA("avx2") void store_be(uint8_t out[]) const { bswap().store_le(out); } template<size_t ROT> + BOTAN_FUNC_ISA("avx2") SIMD_8x32 rotl() const { static_assert(ROT > 0 && ROT < 32, "Invalid rotation constant"); @@ -67,6 +75,7 @@ class SIMD_8x32 final } template<size_t ROT> + BOTAN_FUNC_ISA("avx2") SIMD_8x32 rotr() const { return this->rotl<32-ROT>(); @@ -107,52 +116,60 @@ class SIMD_8x32 final return retval; } + BOTAN_FUNC_ISA("avx2") void operator+=(const SIMD_8x32& other) { m_avx2 = _mm256_add_epi32(m_avx2, other.m_avx2); } + BOTAN_FUNC_ISA("avx2") void operator-=(const SIMD_8x32& other) { m_avx2 = _mm256_sub_epi32(m_avx2, other.m_avx2); } + BOTAN_FUNC_ISA("avx2") void operator^=(const SIMD_8x32& other) { m_avx2 = _mm256_xor_si256(m_avx2, other.m_avx2); } + BOTAN_FUNC_ISA("avx2") void operator|=(const SIMD_8x32& other) { m_avx2 = _mm256_or_si256(m_avx2, other.m_avx2); } + BOTAN_FUNC_ISA("avx2") void operator&=(const SIMD_8x32& other) { m_avx2 = _mm256_and_si256(m_avx2, other.m_avx2); } - template<int SHIFT> SIMD_8x32 shl() const + template<int SHIFT> BOTAN_FUNC_ISA("avx2") SIMD_8x32 shl() const { return SIMD_8x32(_mm256_slli_epi32(m_avx2, SHIFT)); } - template<int SHIFT> SIMD_8x32 shr() const + template<int SHIFT> BOTAN_FUNC_ISA("avx2")SIMD_8x32 shr() const { return SIMD_8x32(_mm256_srli_epi32(m_avx2, SHIFT)); } + BOTAN_FUNC_ISA("avx2") SIMD_8x32 operator~() const { return SIMD_8x32(_mm256_xor_si256(m_avx2, _mm256_set1_epi32(0xFFFFFFFF))); } // (~reg) & other + BOTAN_FUNC_ISA("avx2") SIMD_8x32 andc(const SIMD_8x32& other) const { return SIMD_8x32(_mm256_andnot_si256(m_avx2, other.m_avx2)); } + BOTAN_FUNC_ISA("avx2") SIMD_8x32 bswap() const { const uint8_t BSWAP_MASK[32] = { 3, 2, 1, 0, @@ -171,6 +188,7 @@ class SIMD_8x32 final return SIMD_8x32(output); } + BOTAN_FUNC_ISA("avx2") static void transpose(SIMD_8x32& B0, SIMD_8x32& B1, SIMD_8x32& B2, SIMD_8x32& B3) { @@ -186,6 +204,8 @@ class SIMD_8x32 final } private: + + BOTAN_FUNC_ISA("avx2") SIMD_8x32(__m256i x) : m_avx2(x) {} __m256i m_avx2; |