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