From 43c317529c29456706216bfb23d45219d9b5eb3f Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 26 Jul 2015 14:17:35 -1000 Subject: [PATCH] AES optimization and aligned SSE allocators --- include/Athena/Types.hpp | 23 ++++++++++++++++++++--- src/aes.cpp | 9 +-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/Athena/Types.hpp b/include/Athena/Types.hpp index 8cef4d2..d7f26fe 100644 --- a/include/Athena/Types.hpp +++ b/include/Athena/Types.hpp @@ -44,37 +44,54 @@ typedef unsigned long long atUint64; // Vector types #if __SSE__ #include +#ifndef _WIN32 +#include +#endif #endif -typedef union +#include +#define AT_ALIGNED_ALLOCATOR \ +void* operator new(size_t bytes) noexcept \ +{return _mm_malloc(bytes, 16);} \ +void* operator new[](size_t bytes) noexcept \ +{return _mm_malloc(bytes, 16);} \ +void operator delete(void* buf) noexcept \ +{_mm_free(buf);} \ +void operator delete[](void* buf) noexcept \ +{_mm_free(buf);} \ + +typedef union alignas(16) { #if __clang__ float clangVec __attribute__((__vector_size__(8))); #endif #if __SSE__ __m128 mVec128; + AT_ALIGNED_ALLOCATOR #endif float vec[2]; } atVec2f; -typedef union +typedef union alignas(16) { #if __clang__ float clangVec __attribute__((__vector_size__(12))); #endif #if __SSE__ __m128 mVec128; + AT_ALIGNED_ALLOCATOR #endif float vec[3]; } atVec3f; -typedef union +typedef union alignas(16) { #if __clang__ float clangVec __attribute__((__vector_size__(16))); #endif #if __SSE__ __m128 mVec128; + AT_ALIGNED_ALLOCATOR #endif float vec[4]; } atVec4f; diff --git a/src/aes.cpp b/src/aes.cpp index 268700a..7fd617e 100644 --- a/src/aes.cpp +++ b/src/aes.cpp @@ -39,14 +39,7 @@ static inline void unpack(uint32_t a, uint8_t* b) static inline uint8_t xtime(uint8_t a) { - uint8_t b; - - if (a & 0x80) b = 0x1B; - else b = 0; - - a <<= 1; - a ^= b; - return a; + return ((a << 1) ^ (((a>>7) & 1) * 0x11B)); } static const struct SoftwareAESTables