2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
12 #ifndef VPX_PORTS_X86_H
13 #define VPX_PORTS_X86_H
30 VPX_CPU_TRANSMETA_OLD,
37 #if defined(__GNUC__) && __GNUC__
39 #define cpuid(func,ax,bx,cx,dx)\
40 __asm__ __volatile__ (\
42 : "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) \
45 #define cpuid(func,ax,bx,cx,dx)\
46 __asm__ __volatile__ (\
47 "mov %%ebx, %%edi \n\t" \
49 "xchg %%edi, %%ebx \n\t" \
50 : "=a" (ax), "=D" (bx), "=c" (cx), "=d" (dx) \
55 void __cpuid(int CPUInfo[4], int info_type);
56 #pragma intrinsic(__cpuid)
57 #define cpuid(func,a,b,c,d) do{\
59 __cpuid(regs,func); a=regs[0]; b=regs[1]; c=regs[2]; d=regs[3];\
62 #define cpuid(func,a,b,c,d)\
76 #define HAS_SSSE3 0x10
84 unsigned int flags = 0;
85 unsigned int mask = ~0;
86 unsigned int reg_eax, reg_ebx, reg_ecx, reg_edx;
90 /* See if the CPU capabilities are being overridden by the environment */
91 env = getenv("VPX_SIMD_CAPS");
94 return (int)strtol(env, NULL, 0);
96 env = getenv("VPX_SIMD_CAPS_MASK");
99 mask = strtol(env, NULL, 0);
101 /* Ensure that the CPUID instruction supports extended features */
102 cpuid(0, reg_eax, reg_ebx, reg_ecx, reg_edx);
107 /* Get the standard feature flags */
108 cpuid(1, reg_eax, reg_ebx, reg_ecx, reg_edx);
110 if (reg_edx & BIT(23)) flags |= HAS_MMX;
112 if (reg_edx & BIT(25)) flags |= HAS_SSE; /* aka xmm */
114 if (reg_edx & BIT(26)) flags |= HAS_SSE2; /* aka wmt */
116 if (reg_ecx & BIT(0)) flags |= HAS_SSE3;
118 if (reg_ecx & BIT(9)) flags |= HAS_SSSE3;
123 vpx_cpu_t vpx_x86_vendor(void);
125 #if ARCH_X86_64 && defined(_MSC_VER)
126 unsigned __int64 __rdtsc(void);
127 #pragma intrinsic(__rdtsc)
132 #if defined(__GNUC__) && __GNUC__
134 __asm__ __volatile__("rdtsc\n\t":"=a"(tsc):);
146 #if defined(__GNUC__) && __GNUC__
147 #define x86_pause_hint()\
148 __asm__ __volatile__ ("pause \n\t")
151 /* No pause intrinsic for windows x64 */
152 #define x86_pause_hint()
154 #define x86_pause_hint()\
159 #if defined(__GNUC__) && __GNUC__
161 x87_set_control_word(unsigned short mode)
163 __asm__ __volatile__("fldcw %0" : : "m"(*&mode));
165 static unsigned short
166 x87_get_control_word(void)
169 __asm__ __volatile__("fstcw %0\n\t":"=m"(*&mode):);
173 /* No fldcw intrinsics on Windows x64, punt to external asm */
174 extern void vpx_winx64_fldcw(unsigned short mode);
175 extern unsigned short vpx_winx64_fstcw(void);
176 #define x87_set_control_word vpx_winx64_fldcw
177 #define x87_get_control_word vpx_winx64_fstcw
180 x87_set_control_word(unsigned short mode)
184 static unsigned short
185 x87_get_control_word(void)
193 static unsigned short
194 x87_set_double_precision(void)
196 unsigned short mode = x87_get_control_word();
197 x87_set_control_word((mode&~0x300) | 0x200);
202 extern void vpx_reset_mmx_state(void);