]> git.sesse.net Git - x264/blob - common/x86/cpu-a.asm
Add Windows resource file
[x264] / common / x86 / cpu-a.asm
1 ;*****************************************************************************
2 ;* cpu-a.asm: x86 cpu utilities
3 ;*****************************************************************************
4 ;* Copyright (C) 2003-2011 x264 project
5 ;*
6 ;* Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 ;*          Loren Merritt <lorenm@u.washington.edu>
8 ;*          Fiona Glaser <fiona@x264.com>
9 ;*
10 ;* This program is free software; you can redistribute it and/or modify
11 ;* it under the terms of the GNU General Public License as published by
12 ;* the Free Software Foundation; either version 2 of the License, or
13 ;* (at your option) any later version.
14 ;*
15 ;* This program is distributed in the hope that it will be useful,
16 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;* GNU General Public License for more details.
19 ;*
20 ;* You should have received a copy of the GNU General Public License
21 ;* along with this program; if not, write to the Free Software
22 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
23 ;*
24 ;* This program is also available under a commercial proprietary license.
25 ;* For more information, contact us at licensing@x264.com.
26 ;*****************************************************************************
27
28 %include "x86inc.asm"
29
30 SECTION .text
31
32 ;-----------------------------------------------------------------------------
33 ; void cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
34 ;-----------------------------------------------------------------------------
35 cglobal cpu_cpuid, 5,7
36     push rbx
37     push  r4
38     push  r3
39     push  r2
40     push  r1
41     mov  eax, r0d
42     cpuid
43     pop  rsi
44     mov [rsi], eax
45     pop  rsi
46     mov [rsi], ebx
47     pop  rsi
48     mov [rsi], ecx
49     pop  rsi
50     mov [rsi], edx
51     pop  rbx
52     RET
53
54 ;-----------------------------------------------------------------------------
55 ; void cpu_xgetbv( int op, int *eax, int *edx )
56 ;-----------------------------------------------------------------------------
57 cglobal cpu_xgetbv, 3,7
58     push  r2
59     push  r1
60     mov  ecx, r0d
61     xgetbv
62     pop  rsi
63     mov [rsi], eax
64     pop  rsi
65     mov [rsi], edx
66     RET
67
68 %ifndef ARCH_X86_64
69
70 ;-----------------------------------------------------------------------------
71 ; int cpu_cpuid_test( void )
72 ; return 0 if unsupported
73 ;-----------------------------------------------------------------------------
74 cglobal cpu_cpuid_test
75     pushfd
76     push    ebx
77     push    ebp
78     push    esi
79     push    edi
80     pushfd
81     pop     eax
82     mov     ebx, eax
83     xor     eax, 0x200000
84     push    eax
85     popfd
86     pushfd
87     pop     eax
88     xor     eax, ebx
89     pop     edi
90     pop     esi
91     pop     ebp
92     pop     ebx
93     popfd
94     ret
95
96 ;-----------------------------------------------------------------------------
97 ; void stack_align( void (*func)(void*), void *arg );
98 ;-----------------------------------------------------------------------------
99 cglobal stack_align
100     push ebp
101     mov  ebp, esp
102     sub  esp, 12
103     and  esp, ~15
104     mov  ecx, [ebp+8]
105     mov  edx, [ebp+12]
106     mov  [esp], edx
107     mov  edx, [ebp+16]
108     mov  [esp+4], edx
109     mov  edx, [ebp+20]
110     mov  [esp+8], edx
111     call ecx
112     leave
113     ret
114
115 %endif
116
117 ;-----------------------------------------------------------------------------
118 ; void cpu_emms( void )
119 ;-----------------------------------------------------------------------------
120 cglobal cpu_emms
121     emms
122     ret
123
124 ;-----------------------------------------------------------------------------
125 ; void cpu_sfence( void )
126 ;-----------------------------------------------------------------------------
127 cglobal cpu_sfence
128     sfence
129     ret
130
131 ;-----------------------------------------------------------------------------
132 ; void cpu_mask_misalign_sse( void )
133 ;-----------------------------------------------------------------------------
134 cglobal cpu_mask_misalign_sse
135     sub   rsp, 4
136     stmxcsr [rsp]
137     or dword [rsp], 1<<17
138     ldmxcsr [rsp]
139     add   rsp, 4
140     ret