Whitespace check-in

We also simplified the CPU_ProbeNEON logic a bit to a vmov.u32 and vshl.u32.
pull/853/head
Jeffrey Walton 2019-05-21 02:21:15 -04:00
parent 40251d9b7f
commit e8603143dc
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 92 additions and 107 deletions

View File

@ -6,6 +6,7 @@
// ARMv8a NEON instructions. A separate source file is needed // ARMv8a NEON instructions. A separate source file is needed
// because additional CXXFLAGS are required to enable the // because additional CXXFLAGS are required to enable the
// appropriate instructions sets in some build configurations. // appropriate instructions sets in some build configurations.
// For Linux and Unix additional flags are not required.
#include "pch.h" #include "pch.h"
#include "config.h" #include "config.h"
@ -39,55 +40,55 @@ NAMESPACE_BEGIN(CryptoPP)
extern "C" { extern "C" {
typedef void (*SigHandler)(int); typedef void (*SigHandler)(int);
static jmp_buf s_jmpSIGILL; static jmp_buf s_jmpSIGILL;
static void SigIllHandler(int) static void SigIllHandler(int)
{ {
longjmp(s_jmpSIGILL, 1); longjmp(s_jmpSIGILL, 1);
} }
} }
#endif // Not CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY #endif // Not CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
bool CPU_ProbeARMv7() bool CPU_ProbeARMv7()
{ {
#if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES) #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
return false; return false;
#elif CRYPTOPP_BOOL_ARM32 #elif CRYPTOPP_BOOL_ARM32
# if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
volatile bool result = true; volatile bool result = true;
__try __try
{ {
// Modern MS hardware is ARMv7 // Modern MS hardware is ARMv7
result = true; result = true;
} }
__except (EXCEPTION_EXECUTE_HANDLER) __except (EXCEPTION_EXECUTE_HANDLER)
{ {
return false; return false;
} }
return result; return result;
# elif defined(__GNUC__) || defined(__clang__) # else
// longjmp and clobber warnings. Volatile is required. // longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true; volatile bool result = true;
volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
if (oldHandler == SIG_ERR) if (oldHandler == SIG_ERR)
return false; return false;
volatile sigset_t oldMask; volatile sigset_t oldMask;
if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask)) if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
return false; return false;
if (setjmp(s_jmpSIGILL)) if (setjmp(s_jmpSIGILL))
result = false; result = false;
else else
{ {
#if 0 #if 0
// ARMv7 added movt and movw // ARMv7 added movt and movw
int a; int a;
asm volatile("movw %0,%1 \n" asm volatile("movw %0,%1 \n"
"movt %0,%1 \n" "movt %0,%1 \n"
: "=r"(a) : "i"(0x1234)); : "=r"(a) : "i"(0x1234));
00000010 <_Z5test2v>: // ARM 00000010 <_Z5test2v>: // ARM
10: e3010234 movw r0, #4660 ; 0x1234 10: e3010234 movw r0, #4660 ; 0x1234
@ -100,96 +101,80 @@ bool CPU_ProbeARMv7()
24: e12fff1e bx lr 24: e12fff1e bx lr
#endif #endif
int a; volatile int a;
asm volatile ( asm volatile (
".arm \n\t" ".arm \n\t"
".inst 0xe3010234 \n\t" // movw r0, 0x1234 ".inst 0xe3010234 \n\t" // movw r0, 0x1234
".inst 0xe3410234 \n\t" // movt r0, 0x1234 ".inst 0xe3410234 \n\t" // movt r0, 0x1234
"mov %0, r0 \n\t" // mov [a], r0 "mov %0, r0 \n\t" // mov [a], r0
: "=r" (a) : : "r0"); : "=r" (a) : : "r0");
result = (a == 0x12341234); result = (a == 0x12341234);
} }
sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR); sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
signal(SIGILL, oldHandler); signal(SIGILL, oldHandler);
return result; return result;
# endif # endif
#else #else
return false; return false;
#endif // CRYPTOPP_BOOL_ARM32 #endif // CRYPTOPP_BOOL_ARM32
} }
bool CPU_ProbeNEON() bool CPU_ProbeNEON()
{ {
#if defined(__aarch32__) || defined(__aarch64__) #if defined(__aarch32__) || defined(__aarch64__)
return true; return true;
#elif defined(CRYPTOPP_NO_CPU_FEATURE_PROBES) #elif defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
return false; return false;
#elif (CRYPTOPP_ARM_NEON_AVAILABLE) #elif CRYPTOPP_BOOL_ARM32
# if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
volatile bool result = true; volatile bool result = true;
__try __try
{ {
uint32_t v1[4] = {1,1,1,1}; volatile uint32x4_t x = vdupq_n_u32(1);
uint32x4_t x1 = vld1q_u32(v1); volatile uint32x4_t y = vshlq_n_u32(x, 4);
uint64_t v2[2] = {1,1}; return (y[0] & y[1] & y[2] & y[3]) == 16;
uint64x2_t x2 = vld1q_u64(v2); }
__except (EXCEPTION_EXECUTE_HANDLER)
uint32x4_t x3 = vdupq_n_u32(2); {
x3 = vsetq_lane_u32(vgetq_lane_u32(x1,0),x3,0); return false;
x3 = vsetq_lane_u32(vgetq_lane_u32(x1,3),x3,3); }
uint64x2_t x4 = vdupq_n_u64(2); return result;
x4 = vsetq_lane_u64(vgetq_lane_u64(x2,0),x4,0);
x4 = vsetq_lane_u64(vgetq_lane_u64(x2,1),x4,1);
result = !!(vgetq_lane_u32(x3,0) | vgetq_lane_u64(x4,1));
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return false;
}
return result;
# else # else
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;
// longjmp and clobber warnings. Volatile is required. volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 if (oldHandler == SIG_ERR)
volatile bool result = true; return false;
volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); volatile sigset_t oldMask;
if (oldHandler == SIG_ERR) if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
return false; return false;
volatile sigset_t oldMask; if (setjmp(s_jmpSIGILL))
if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask)) result = false;
return false; else
{
// This is risky... When we hand encode the instructions
// for vmov.u32 and vshl.u32 we get a SIGILL. Apparently
// we need more than just the instructions. Using
// intrinsics introduces the risk because the whole
// file gets built with ISA options, and the higher ISA
// may escape the try block with the SIGILL guard.
uint32x4_t x = vdupq_n_u32(1);
uint32x4_t y = vshlq_n_u32(x, 4);
return (y[0] & y[1] & y[2] & y[3]) == 16;
}
if (setjmp(s_jmpSIGILL)) sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
result = false; signal(SIGILL, oldHandler);
else return result;
{
uint32_t v1[4] = {1,1,1,1};
uint32x4_t x1 = vld1q_u32(v1);
uint64_t v2[2] = {1,1};
uint64x2_t x2 = vld1q_u64(v2);
uint32x4_t x3 = {0,0,0,0};
x3 = vsetq_lane_u32(vgetq_lane_u32(x1,0),x3,0);
x3 = vsetq_lane_u32(vgetq_lane_u32(x1,3),x3,3);
uint64x2_t x4 = {0,0};
x4 = vsetq_lane_u64(vgetq_lane_u64(x2,0),x4,0);
x4 = vsetq_lane_u64(vgetq_lane_u64(x2,1),x4,1);
// Hack... GCC optimizes away the code and returns true
result = !!(vgetq_lane_u32(x3,0) | vgetq_lane_u64(x4,1));
}
sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
signal(SIGILL, oldHandler);
return result;
# endif # endif
#else #else
return false; return false;
#endif // CRYPTOPP_ARM_NEON_AVAILABLE #endif // CRYPTOPP_ARM_NEON_AVAILABLE
} }