Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
52867 views
1
;*****************************************************************************
2
;* cpu-a.asm: x86 cpu utilities
3
;*****************************************************************************
4
;* Copyright (C) 2003-2016 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
xor ecx, ecx
43
cpuid
44
pop r4
45
mov [r4], eax
46
pop r4
47
mov [r4], ebx
48
pop r4
49
mov [r4], ecx
50
pop r4
51
mov [r4], edx
52
pop rbx
53
RET
54
55
;-----------------------------------------------------------------------------
56
; void cpu_xgetbv( int op, int *eax, int *edx )
57
;-----------------------------------------------------------------------------
58
cglobal cpu_xgetbv, 3,7
59
push r2
60
push r1
61
mov ecx, r0d
62
xgetbv
63
pop r4
64
mov [r4], eax
65
pop r4
66
mov [r4], edx
67
RET
68
69
%if ARCH_X86_64
70
71
;-----------------------------------------------------------------------------
72
; void stack_align( void (*func)(void*), void *arg );
73
;-----------------------------------------------------------------------------
74
cglobal stack_align
75
push rbp
76
mov rbp, rsp
77
%if WIN64
78
sub rsp, 32 ; shadow space
79
%endif
80
and rsp, ~31
81
mov rax, r0
82
mov r0, r1
83
mov r1, r2
84
mov r2, r3
85
call rax
86
leave
87
ret
88
89
%else
90
91
;-----------------------------------------------------------------------------
92
; int cpu_cpuid_test( void )
93
; return 0 if unsupported
94
;-----------------------------------------------------------------------------
95
cglobal cpu_cpuid_test
96
pushfd
97
push ebx
98
push ebp
99
push esi
100
push edi
101
pushfd
102
pop eax
103
mov ebx, eax
104
xor eax, 0x200000
105
push eax
106
popfd
107
pushfd
108
pop eax
109
xor eax, ebx
110
pop edi
111
pop esi
112
pop ebp
113
pop ebx
114
popfd
115
ret
116
117
cglobal stack_align
118
push ebp
119
mov ebp, esp
120
sub esp, 12
121
and esp, ~31
122
mov ecx, [ebp+8]
123
mov edx, [ebp+12]
124
mov [esp], edx
125
mov edx, [ebp+16]
126
mov [esp+4], edx
127
mov edx, [ebp+20]
128
mov [esp+8], edx
129
call ecx
130
leave
131
ret
132
133
%endif
134
135
;-----------------------------------------------------------------------------
136
; void cpu_emms( void )
137
;-----------------------------------------------------------------------------
138
cglobal cpu_emms
139
emms
140
ret
141
142
;-----------------------------------------------------------------------------
143
; void cpu_sfence( void )
144
;-----------------------------------------------------------------------------
145
cglobal cpu_sfence
146
sfence
147
ret
148
149