summaryrefslogtreecommitdiff
path: root/lib/accelerated
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2019-08-02 21:57:40 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2019-08-05 20:57:25 +0200
commitef80617d1e17e0878a909baad62a75ba265c0e00 (patch)
tree16b70933c185aa51994ab39732d8eef09f924573 /lib/accelerated
parent11dc122ebd3f6acd87fffa0b6bceb8606787d3fe (diff)
downloadgnutls-ef80617d1e17e0878a909baad62a75ba265c0e00.tar.gz
read_cpuid_vals: use __get_cpuid_count() only when availabletmp-fixes
This makes the functionality available on gcc 4.8. Resolves: #812 Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Diffstat (limited to 'lib/accelerated')
-rw-r--r--lib/accelerated/x86/x86-common.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/accelerated/x86/x86-common.c b/lib/accelerated/x86/x86-common.c
index fb3ff90919..516d6776c5 100644
--- a/lib/accelerated/x86/x86-common.c
+++ b/lib/accelerated/x86/x86-common.c
@@ -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;
}