From 0ad21a218c049945083136e33da07097fee28c12 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 16 Nov 2015 16:16:54 +0100 Subject: [PATCH] Return CPU features in Visual Studio builds Please note that on other platforms, we keep checking if intrinsics are available. has_*() means that not only a CPU feature is present, but also that Sodium can use it. --- src/libsodium/sodium/runtime.c | 44 +++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index 55c1df84..0c79797e 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -102,42 +102,48 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features) return -1; /* LCOV_EXCL_LINE */ } _cpuid(cpu_info, 0x00000001); -#ifndef HAVE_EMMINTRIN_H - cpu_features->has_sse2 = 0; -#else +#if defined(HAVE_EMMINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_sse2 = ((cpu_info[3] & CPUID_SSE2) != 0x0); +#else + cpu_features->has_sse2 = 0; #endif -#ifndef HAVE_PMMINTRIN_H - cpu_features->has_sse3 = 0; -#else +#if defined(HAVE_PMMINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_sse3 = ((cpu_info[2] & CPUIDECX_SSE3) != 0x0); +#else + cpu_features->has_sse3 = 0; #endif -#ifndef HAVE_TMMINTRIN_H - cpu_features->has_ssse3 = 0; -#else +#if defined(HAVE_TMMINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_ssse3 = ((cpu_info[2] & CPUIDECX_SSSE3) != 0x0); +#else + cpu_features->has_ssse3 = 0; #endif -#ifndef HAVE_SMMINTRIN_H - cpu_features->has_sse41 = 0; -#else +#if defined(HAVE_SMMINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_sse41 = ((cpu_info[2] & CPUIDECX_SSE41) != 0x0); +#else + cpu_features->has_sse41 = 0; #endif -#ifndef HAVE_AVXINTRIN_H - cpu_features->has_avx = 0; -#else +#if defined(HAVE_AVXINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_avx = ((cpu_info[2] & CPUIDECX_AVX) != 0x0); +#else + cpu_features->has_avx = 0; #endif -#ifndef HAVE_WMMINTRIN_H - cpu_features->has_pclmul = 0; - cpu_features->has_aesni = 0; -#else +#if defined(HAVE_WMMINTRIN_H) || \ + (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))) cpu_features->has_pclmul = ((cpu_info[2] & CPUIDECX_PCLMUL) != 0x0); cpu_features->has_aesni = ((cpu_info[2] & CPUIDECX_AESNI) != 0x0); +#else + cpu_features->has_pclmul = 0; + cpu_features->has_aesni = 0; #endif return 0;