2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
11 #ifndef VPX_PORTS_X86_H
12 #define VPX_PORTS_X86_H
16 #if defined(__GNUC__) && __GNUC__
18 #define cpuid(func,ax,bx,cx,dx)\
19 __asm__ __volatile__ (\
21 : "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) \
24 #define cpuid(func,ax,bx,cx,dx)\
25 __asm__ __volatile__ (\
28 "movl %%ebx, %1 \n\t" \
30 : "=a" (ax), "=r" (bx), "=c" (cx), "=d" (dx) \
35 void __cpuid(int CPUInfo
[4], int info_type
);
36 #pragma intrinsic(__cpuid)
37 #define cpuid(func,a,b,c,d) do{\
39 __cpuid(regs,func); a=regs[0]; b=regs[1]; c=regs[2]; d=regs[3];\
42 #define cpuid(func,a,b,c,d)\
56 #define HAS_SSSE3 0x10
64 unsigned int flags
= 0;
65 unsigned int mask
= ~0;
66 unsigned int reg_eax
, reg_ebx
, reg_ecx
, reg_edx
;
70 /* See if the CPU capabilities are being overridden by the environment */
71 env
= getenv("VPX_SIMD_CAPS");
74 return (int)strtol(env
, NULL
, 0);
76 env
= getenv("VPX_SIMD_CAPS_MASK");
79 mask
= strtol(env
, NULL
, 0);
81 /* Ensure that the CPUID instruction supports extended features */
82 cpuid(0, reg_eax
, reg_ebx
, reg_ecx
, reg_edx
);
87 /* Get the standard feature flags */
88 cpuid(1, reg_eax
, reg_ebx
, reg_ecx
, reg_edx
);
90 if (reg_edx
& BIT(23)) flags
|= HAS_MMX
;
92 if (reg_edx
& BIT(25)) flags
|= HAS_SSE
; /* aka xmm */
94 if (reg_edx
& BIT(26)) flags
|= HAS_SSE2
; /* aka wmt */
96 if (reg_ecx
& BIT(0)) flags
|= HAS_SSE3
;
98 if (reg_ecx
& BIT(9)) flags
|= HAS_SSSE3
;
104 #if ARCH_X86_64 && defined(_MSC_VER)
105 unsigned __int64
__rdtsc(void);
106 #pragma intrinsic(__rdtsc)
111 #if defined(__GNUC__) && __GNUC__
113 __asm__
__volatile__("rdtsc\n\t":"=a"(tsc
):);
125 #if defined(__GNUC__) && __GNUC__
126 #define x86_pause_hint()\
127 __asm__ __volatile__ ("pause \n\t")
130 /* No pause intrinsic for windows x64 */
131 #define x86_pause_hint()
133 #define x86_pause_hint()\
138 #if defined(__GNUC__) && __GNUC__
140 x87_set_control_word(unsigned short mode
)
142 __asm__
__volatile__("fldcw %0" : : "m"(*&mode
));
144 static unsigned short
145 x87_get_control_word(void)
148 __asm__
__volatile__("fstcw %0\n\t":"=m"(*&mode
):);
152 /* No fldcw intrinsics on Windows x64, punt to external asm */
153 extern void vpx_winx64_fldcw(unsigned short mode
);
154 extern unsigned short vpx_winx64_fstcw(void);
155 #define x87_set_control_word vpx_winx64_fldcw
156 #define x87_get_control_word vpx_winx64_fstcw
159 x87_set_control_word(unsigned short mode
)
163 static unsigned short
164 x87_get_control_word(void)
172 static unsigned short
173 x87_set_double_precision(void)
175 unsigned short mode
= x87_get_control_word();
176 x87_set_control_word((mode
&~0x300) | 0x200);
181 extern void vpx_reset_mmx_state(void);