Skip to content

Commit 60ea749

Browse files
committed
detect whether the operating system can use AVX
1 parent 0d7015f commit 60ea749

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/blake2-dispatch.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ static inline void cpuid( uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t
6363
: "=a"( *eax ), "=b"( *ebx ), "=c"( *ecx ), "=d"( *edx ) : "a"( *eax ) );
6464
#endif
6565
}
66+
67+
static inline uint64_t xgetbv(uint32_t xcr)
68+
{
69+
uint32_t a, d;
70+
__asm__ __volatile__(
71+
"xgetbv"
72+
: "=a"(a),"=d"(d)
73+
: "c"(xcr)
74+
);
75+
return ((uint64_t)d << 32) | a;
76+
}
77+
6678
#elif defined(_MSC_VER)
6779
#include <intrin.h>
6880
static inline void cpuid( uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx )
@@ -106,8 +118,13 @@ static inline cpu_feature_t get_cpu_features( void )
106118
if( IsProcessorFeaturePresent(17) ) /* Some environments don't know about PF_XSAVE_ENABLED */
107119
#endif
108120
{
109-
if( 1 & ( ecx >> 28 ) )
121+
/* check for AVX and OSXSAVE bits */
122+
if( 1 & ( ecx >> 28 ) & (ecx >> 27) ) {
123+
#if !defined(WIN32) /* Already checked for this in WIN32 */
124+
if( (xgetbv(0) & 6) == 6 ) /* XCR0 */
125+
#endif
110126
feature = AVX;
127+
}
111128

112129

113130
eax = 0x80000001;

0 commit comments

Comments
 (0)