]> git.sesse.net Git - x264/blob - common/x86/cpu-a.asm
Update source file headers
[x264] / common / x86 / cpu-a.asm
1 ;*****************************************************************************
2 ;* cpu-a.asm: x86 cpu utilities
3 ;*****************************************************************************
4 ;* Copyright (C) 2003-2010 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 %ifdef ARCH_X86_64
33
34 ;-----------------------------------------------------------------------------
35 ; int cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
36 ;-----------------------------------------------------------------------------
37 cglobal cpu_cpuid, 5,7
38     push    rbx
39     mov     r11,   r1
40     mov     r10,   r2
41     movifnidn r9,  r3
42     movifnidn r8,  r4
43     mov     eax,   r0d
44     cpuid
45     mov     [r11], eax
46     mov     [r10], ebx
47     mov     [r9],  ecx
48     mov     [r8],  edx
49     pop     rbx
50     RET
51
52 %else
53
54 ;-----------------------------------------------------------------------------
55 ; int cpu_cpuid_test( void )
56 ; return 0 if unsupported
57 ;-----------------------------------------------------------------------------
58 cglobal cpu_cpuid_test
59     pushfd
60     push    ebx
61     push    ebp
62     push    esi
63     push    edi
64     pushfd
65     pop     eax
66     mov     ebx, eax
67     xor     eax, 0x200000
68     push    eax
69     popfd
70     pushfd
71     pop     eax
72     xor     eax, ebx
73     pop     edi
74     pop     esi
75     pop     ebp
76     pop     ebx
77     popfd
78     ret
79
80 ;-----------------------------------------------------------------------------
81 ; int cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
82 ;-----------------------------------------------------------------------------
83 cglobal cpu_cpuid, 0,6
84     mov     eax,    r0m
85     cpuid
86     mov     esi,    r1m
87     mov     [esi],  eax
88     mov     esi,    r2m
89     mov     [esi],  ebx
90     mov     esi,    r3m
91     mov     [esi],  ecx
92     mov     esi,    r4m
93     mov     [esi],  edx
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