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
29 VPX_CPU_TRANSMETA_OLD,
36 #if defined(__GNUC__) && __GNUC__
38 #define cpuid(func,ax,bx,cx,dx)\
39 __asm__ __volatile__ (\
41 : "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) \
44 #define cpuid(func,ax,bx,cx,dx)\
45 __asm__ __volatile__ (\
46 "mov %%ebx, %%edi \n\t" \
48 "xchg %%edi, %%ebx \n\t" \
49 : "=a" (ax), "=D" (bx), "=c" (cx), "=d" (dx) \
54 void __cpuid(int CPUInfo[4], int info_type);
55 #pragma intrinsic(__cpuid)
56 #define cpuid(func,a,b,c,d) do{\
58 __cpuid(regs,func); a=regs[0]; b=regs[1]; c=regs[2]; d=regs[3];\
61 #define cpuid(func,a,b,c,d)\
75 #define HAS_SSSE3 0x10
76 #define HAS_SSE4_1 0x20
83 unsigned int flags = 0;
84 unsigned int mask = ~0;
85 unsigned int reg_eax, reg_ebx, reg_ecx, reg_edx;
89 /* See if the CPU capabilities are being overridden by the environment */
90 env = getenv("VPX_SIMD_CAPS");
93 return (int)strtol(env, NULL, 0);
95 env = getenv("VPX_SIMD_CAPS_MASK");
98 mask = strtol(env, NULL, 0);
100 /* Ensure that the CPUID instruction supports extended features */
101 cpuid(0, reg_eax, reg_ebx, reg_ecx, reg_edx);
106 /* Get the standard feature flags */
107 cpuid(1, reg_eax, reg_ebx, reg_ecx, reg_edx);
109 if (reg_edx & BIT(23)) flags |= HAS_MMX;
111 if (reg_edx & BIT(25)) flags |= HAS_SSE; /* aka xmm */
113 if (reg_edx & BIT(26)) flags |= HAS_SSE2; /* aka wmt */
115 if (reg_ecx & BIT(0)) flags |= HAS_SSE3;
117 if (reg_ecx & BIT(9)) flags |= HAS_SSSE3;
119 if (reg_ecx & BIT(19)) flags |= HAS_SSE4_1;
124 vpx_cpu_t vpx_x86_vendor(void);
126 #if ARCH_X86_64 && defined(_MSC_VER)
127 unsigned __int64 __rdtsc(void);
128 #pragma intrinsic(__rdtsc)
132 #if defined(__GNUC__) && __GNUC__
133 #define x86_pause_hint()\
134 __asm__ __volatile__ ("pause \n\t")
137 #define x86_pause_hint()\
140 #define x86_pause_hint()\
145 #if defined(__GNUC__) && __GNUC__
147 x87_set_control_word(unsigned short mode) {
148 __asm__ __volatile__("fldcw %0" : : "m"( *&mode));
150 static unsigned short
151 x87_get_control_word(void) {
153 __asm__ __volatile__("fstcw %0\n\t":"=m"( *&mode):);
157 /* No fldcw intrinsics on Windows x64, punt to external asm */
158 extern void vpx_winx64_fldcw(unsigned short mode);
159 extern unsigned short vpx_winx64_fstcw(void);
160 #define x87_set_control_word vpx_winx64_fldcw
161 #define x87_get_control_word vpx_winx64_fstcw
164 x87_set_control_word(unsigned short mode) {
167 static unsigned short
168 x87_get_control_word(void) {
175 static unsigned short
176 x87_set_double_precision(void) {
177 unsigned short mode = x87_get_control_word();
178 x87_set_control_word((mode&~0x300) | 0x200);
183 extern void vpx_reset_mmx_state(void);