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