3 * x86 hardware feature detection
6 * Alex Rønne Petersen (alexrp@xamarin.com)
7 * Elijah Taylor (elijahtaylor@google.com)
8 * Miguel de Icaza (miguel@xamarin.com)
9 * Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com)
10 * Paolo Molaro (lupus@xamarin.com)
11 * Rodrigo Kumpera (kumpera@gmail.com)
12 * Sebastien Pouliot (sebastien@xamarin.com)
13 * Zoltan Varga (vargaz@xamarin.com)
15 * Copyright 2003 Ximian, Inc.
16 * Copyright 2003-2011 Novell, Inc
17 * Copyright 2006 Broadcom
18 * Copyright 2007-2008 Andreas Faerber
19 * Copyright 2011-2013 Xamarin Inc
20 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
23 #include "mono/utils/mono-hwcap.h"
25 #if defined(HAVE_UNISTD_H)
33 cpuid (int id, int *p_eax, int *p_ebx, int *p_ecx, int *p_edx)
39 /* First, make sure we can use cpuid if we're on 32-bit. */
40 #if defined(TARGET_X86)
41 gboolean have_cpuid = FALSE;
58 __asm__ __volatile__ (
61 "movl\t%%eax, %%edx\n\t"
62 "xorl\t$0x200000, %%eax\n\t"
67 "xorl\t%%edx, %%eax\n\t"
68 "andl\t$0x200000, %%eax\n\t"
80 /* Now issue the actual cpuid instruction. We can use
81 MSVC's __cpuid on both 32-bit and 64-bit. */
88 #elif defined(TARGET_X86)
89 /* This complicated stuff is necessary because EBX
90 may be used by the compiler in PIC mode. */
91 __asm__ __volatile__ (
92 "xchgl\t%%ebx, %k1\n\t"
94 "xchgl\t%%ebx, %k1\n\t"
95 : "=a" (*p_eax), "=&r" (*p_ebx), "=c" (*p_ecx), "=d" (*p_edx)
99 __asm__ __volatile__ (
101 : "=a" (*p_eax), "=b" (*p_ebx), "=c" (*p_ecx), "=d" (*p_edx)
110 mono_hwcap_arch_init (void)
112 int eax, ebx, ecx, edx;
114 if (cpuid (1, &eax, &ebx, &ecx, &edx)) {
115 if (edx & (1 << 15)) {
116 mono_hwcap_x86_has_cmov = TRUE;
119 mono_hwcap_x86_has_fcmov = TRUE;
123 mono_hwcap_x86_has_sse1 = TRUE;
126 mono_hwcap_x86_has_sse2 = TRUE;
129 mono_hwcap_x86_has_sse3 = TRUE;
132 mono_hwcap_x86_has_ssse3 = TRUE;
135 mono_hwcap_x86_has_sse41 = TRUE;
138 mono_hwcap_x86_has_sse42 = TRUE;
141 if (cpuid (0x80000000, &eax, &ebx, &ecx, &edx)) {
142 if ((unsigned int) eax >= 0x80000001 && ebx == 0x68747541 && ecx == 0x444D4163 && edx == 0x69746E65) {
143 if (cpuid (0x80000001, &eax, &ebx, &ecx, &edx)) {
145 mono_hwcap_x86_has_sse4a = TRUE;
150 #if defined(HAVE_UNISTD_H)
151 mono_hwcap_x86_is_xen = !access ("/proc/xen", F_OK);