]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
read_cpuid_vals: use __get_cpuid_count() only when available tmp-fixes
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 2 Aug 2019 19:57:40 +0000 (21:57 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 5 Aug 2019 18:57:25 +0000 (20:57 +0200)
This makes the functionality available on gcc 4.8.

Resolves: #812

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
configure.ac
lib/accelerated/x86/x86-common.c

index 6a1d3dbc5cbd6af2cea9ecf248172fccc957e50f..1bf9bce95ede9e741ebd0428fc06b7f6de7ec6fd 100644 (file)
@@ -182,6 +182,17 @@ case $host_cpu in
   ;;
 esac
 
+# check for gcc's __get_cpuid_count functionality
+AC_MSG_CHECKING([for __get_cpuid_count])
+AC_LINK_IFELSE(
+   [AC_LANG_SOURCE([
+    #include <cpuid.h>
+    int main(void) { unsigned t1; return __get_cpuid_count(7, 0, &t1, &t1, &t1, &t1); }
+   ])],
+   [AC_DEFINE([HAVE_GET_CPUID_COUNT], [1], [use __get_cpuid_count]) AC_MSG_RESULT([yes])],
+   [AC_MSG_RESULT([no])]
+)
+
 fi
 
 AC_ARG_ENABLE(tls13-interop,
index fb3ff90919f2f2de63f383bce9b48719f79a741e..516d6776c5695e8fea59e877ed12f33d8bf361f0 100644 (file)
@@ -106,17 +106,33 @@ unsigned int _gnutls_x86_cpuid_s[4];
 #define VIA_PADLOCK_PHE (1<<21)
 #define VIA_PADLOCK_PHE_SHA512 (1<<22)
 
+#ifndef HAVE_GET_CPUID_COUNT
+static inline void
+get_cpuid_level7(unsigned int *eax, unsigned int *ebx,
+                unsigned int *ecx, unsigned int *edx)
+{
+       /* we avoid using __get_cpuid_count, because it is not available with gcc 4.8 */
+       if (__get_cpuid_max(7, 0) < 7)
+               return;
+
+       __cpuid_count(7, 0, *eax, *ebx, *ecx, *edx);
+       return;
+}
+#else
+# define get_cpuid_level7(a,b,c,d) __get_cpuid_count(7, 0, a, b, c, d)
+#endif
+
 static unsigned read_cpuid_vals(unsigned int vals[4])
 {
        unsigned t1, t2, t3;
-       if (!__get_cpuid(1, &t1, &vals[0],
-                        &vals[1], &t2))
+       vals[0] = vals[1] = vals[2] = vals[3] = 0;
+
+       if (!__get_cpuid(1, &t1, &vals[0], &vals[1], &t2))
                return 0;
        /* suppress AVX512; it works conditionally on certain CPUs on the original code */
        vals[1] &= 0xfffff7ff;
 
-       if (!__get_cpuid_count(7, 0, &t1, &vals[2], &t2, &t3))
-               return 0;
+       get_cpuid_level7(&t1, &vals[2], &t2, &t3);
 
        return 1;
 }