LDFLAGS=$ac_save_LDFLAGS
ac_c_werror_flag=$cu_save_c_werror_flag
-AC_MSG_CHECKING([if __get_cpuid available])
-AC_LINK_IFELSE(
- [AC_LANG_SOURCE([[
- #include <cpuid.h>
-
- int
- main (void)
- {
- unsigned int eax, ebx, ecx, edx;
- __get_cpuid (1, &eax, &ebx, &ecx, &edx);
- return 1;
- }
- ]])
- ],[
- AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_CPUID], [1], [__get_cpuid available])
- cpuid_exists=yes
- ],[
- AC_MSG_RESULT([no])
- ])
-
ac_save_CFLAGS=$CFLAGS
CFLAGS="-mavx -mpclmul $CFLAGS"
AC_MSG_CHECKING([if pclmul intrinsic exists])
__m128i a, b;
a = _mm_clmulepi64_si128 (a, b, 0x00);
a = _mm_shuffle_epi8 (a, b);
- return 1;
+ return __builtin_cpu_supports ("pclmul");
}
]])
],[
- AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_PCLMUL_INTRINSIC], [1], [pclmul intrinsic exists])
pclmul_intrinsic_exists=yes
],[
- AC_MSG_RESULT([no])
+ pclmul_intrinsic_exists=no
])
-if test "x$cpuid_exists" = "xyes" &&
- test "x$pclmul_intrinsic_exists" = "xyes"; then
+AC_MSG_RESULT([$pclmul_intrinsic_exists])
+if test $pclmul_intrinsic_exists = yes; then
AC_DEFINE([USE_PCLMUL_CRC32], [1],
[CRC32 calculation by pclmul hardware instruction enabled])
fi
AM_CONDITIONAL([USE_PCLMUL_CRC32],
- [test "x$cpuid_exists" = "xyes" &&
- test "x$pclmul_intrinsic_exists" = "xyes"])
+ [test $pclmul_intrinsic_exists = yes])
CFLAGS=$ac_save_CFLAGS
-AC_MSG_CHECKING([if __get_cpuid_count exists])
-AC_LINK_IFELSE(
- [AC_LANG_SOURCE([[
- #include <cpuid.h>
-
- int
- main (void)
- {
- unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
- __get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx);
- return 1;
- }
- ]])
- ],[
- AC_MSG_RESULT([yes])
- get_cpuid_count_exists=yes
- ],[
- AC_MSG_RESULT([no])
- ])
-
CFLAGS="-mavx2 $CFLAGS"
AC_MSG_CHECKING([if avx2 intrinstics exists])
AC_COMPILE_IFELSE(
{
__m256i a, b;
a = _mm256_sad_epu8 (a, b);
- return 1;
+ return __builtin_cpu_supports ("avx2");
}
]])
],[
- AC_MSG_RESULT([yes])
- AC_DEFINE([HAVE_AVX2_INTRINSIC], [1], [avx2 intrinsics exists])
avx2_intrinsic_exists=yes
],[
- AC_MSG_RESULT([no])
+ avx2_intrinsic_exists=no
])
-if test "x$get_cpuid_count_exists" = "xyes" &&
- test "x$avx2_intrinsic_exists" = "xyes"; then
+AC_MSG_RESULT([$avx2_intrinsic_exists])
+if test $avx2_intrinsic_exists = yes; then
AC_DEFINE([USE_AVX2_WC_LINECOUNT], [1], [Counting lines with AVX2 enabled])
fi
AM_CONDITIONAL([USE_AVX2_WC_LINECOUNT],
- [test "x$get_cpuid_count_exists" = "xyes" &&
- test "x$avx2_intrinsic_exists" = "xyes"])
+ [test $avx2_intrinsic_exists = yes])
CFLAGS=$ac_save_CFLAGS
pclmul_supported (void)
{
# if USE_PCLMUL_CRC32
- unsigned int eax = 0;
- unsigned int ebx = 0;
- unsigned int ecx = 0;
- unsigned int edx = 0;
-
- if (! __get_cpuid (1, &eax, &ebx, &ecx, &edx))
- {
- if (cksum_debug)
- error (0, 0, "%s", _("failed to get cpuid"));
- return false;
- }
-
- if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX))
- {
- if (cksum_debug)
- error (0, 0, "%s", _("pclmul support not detected"));
- return false;
- }
+ bool pclmul_enabled = 0 < __builtin_cpu_supports ("pclmul");
if (cksum_debug)
- error (0, 0, "%s", _("using pclmul hardware support"));
+ error (0, 0, "%s",
+ (pclmul_enabled
+ ? _("using pclmul hardware support")
+ : _("pclmul support not detected")));
- return true;
+ return pclmul_enabled;
# else
if (cksum_debug)
error (0, 0, "%s", _("using generic hardware support"));
static bool
avx2_supported (void)
{
- unsigned int eax = 0;
- unsigned int ebx = 0;
- unsigned int ecx = 0;
- unsigned int edx = 0;
- bool getcpuid_ok = false;
- bool avx_enabled = false;
-
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- {
- getcpuid_ok = true;
- if (ecx & bit_OSXSAVE)
- avx_enabled = true; /* Support is not disabled. */
- }
-
-
- if (avx_enabled)
- {
- eax = ebx = ecx = edx = 0;
- if (! __get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
- getcpuid_ok = false;
- else
- {
- if (! (ebx & bit_AVX2))
- avx_enabled = false; /* Hardware doesn't support it. */
- }
- }
+ bool avx_enabled = 0 < __builtin_cpu_supports ("avx2");
+ if (debug)
+ error (0, 0, (avx_enabled
+ ? _("using avx2 hardware support")
+ : _("avx2 support not detected")));
- if (! getcpuid_ok)
- {
- if (debug)
- error (0, 0, "%s", _("failed to get cpuid"));
- return false;
- }
- else if (! avx_enabled)
- {
- if (debug)
- error (0, 0, "%s", _("avx2 support not detected"));
- return false;
- }
- else
- {
- if (debug)
- error (0, 0, "%s", _("using avx2 hardware support"));
- return true;
- }
+ return avx_enabled;
}
#endif