Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
52867 views
1
;*****************************************************************************
2
;* checkasm-a.asm: assembly check tool
3
;*****************************************************************************
4
;* Copyright (C) 2008-2016 x264 project
5
;*
6
;* Authors: Loren Merritt <lorenm@u.washington.edu>
7
;* Henrik Gramner <henrik@gramner.com>
8
;*
9
;* This program is free software; you can redistribute it and/or modify
10
;* it under the terms of the GNU General Public License as published by
11
;* the Free Software Foundation; either version 2 of the License, or
12
;* (at your option) any later version.
13
;*
14
;* This program is distributed in the hope that it will be useful,
15
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
;* GNU General Public License for more details.
18
;*
19
;* You should have received a copy of the GNU General Public License
20
;* along with this program; if not, write to the Free Software
21
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22
;*
23
;* This program is also available under a commercial proprietary license.
24
;* For more information, contact us at licensing@x264.com.
25
;*****************************************************************************
26
27
%include "x86inc.asm"
28
29
SECTION_RODATA
30
31
error_message: db "failed to preserve register", 0
32
33
%if ARCH_X86_64
34
; just random numbers to reduce the chance of incidental match
35
ALIGN 16
36
x6: dq 0x1a1b2550a612b48c,0x79445c159ce79064
37
x7: dq 0x2eed899d5a28ddcd,0x86b2536fcd8cf636
38
x8: dq 0xb0856806085e7943,0x3f2bf84fc0fcca4e
39
x9: dq 0xacbd382dcf5b8de2,0xd229e1f5b281303f
40
x10: dq 0x71aeaff20b095fd9,0xab63e2e11fa38ed9
41
x11: dq 0x89b0c0765892729a,0x77d410d5c42c882d
42
x12: dq 0xc45ea11a955d8dd5,0x24b3c1d2a024048b
43
x13: dq 0x2e8ec680de14b47c,0xdd7b8919edd42786
44
x14: dq 0x135ce6888fa02cbf,0x11e53e2b2ac655ef
45
x15: dq 0x011ff554472a7a10,0x6de8f4c914c334d5
46
n7: dq 0x21f86d66c8ca00ce
47
n8: dq 0x75b6ba21077c48ad
48
n9: dq 0xed56bb2dcb3c7736
49
n10: dq 0x8bda43d3fd1a7e06
50
n11: dq 0xb64a9c9e5d318408
51
n12: dq 0xdf9a54b303f1d3a3
52
n13: dq 0x4a75479abd64e097
53
n14: dq 0x249214109d5d1c88
54
%endif
55
56
SECTION .text
57
58
cextern_naked puts
59
60
; max number of args used by any x264 asm function.
61
; (max_args % 4) must equal 3 for stack alignment
62
%define max_args 15
63
64
%if ARCH_X86_64
65
66
;-----------------------------------------------------------------------------
67
; void x264_checkasm_stack_clobber( uint64_t clobber, ... )
68
;-----------------------------------------------------------------------------
69
cglobal checkasm_stack_clobber, 1,2
70
; Clobber the stack with junk below the stack pointer
71
%define argsize (max_args+6)*8
72
SUB rsp, argsize
73
mov r1, argsize-8
74
.loop:
75
mov [rsp+r1], r0
76
sub r1, 8
77
jge .loop
78
ADD rsp, argsize
79
RET
80
81
%if WIN64
82
%assign free_regs 7
83
%else
84
%assign free_regs 9
85
%endif
86
87
;-----------------------------------------------------------------------------
88
; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
89
;-----------------------------------------------------------------------------
90
INIT_XMM
91
cglobal checkasm_call, 2,15,16,max_args*8+8
92
mov r6, r0
93
mov [rsp+max_args*8], r1
94
95
; All arguments have been pushed on the stack instead of registers in order to
96
; test for incorrect assumptions that 32-bit ints are zero-extended to 64-bit.
97
mov r0, r6mp
98
mov r1, r7mp
99
mov r2, r8mp
100
mov r3, r9mp
101
%if UNIX64
102
mov r4, r10mp
103
mov r5, r11mp
104
%assign i 6
105
%rep max_args-6
106
mov r9, [rsp+stack_offset+(i+1)*8]
107
mov [rsp+(i-6)*8], r9
108
%assign i i+1
109
%endrep
110
%else
111
%assign i 4
112
%rep max_args-4
113
mov r9, [rsp+stack_offset+(i+7)*8]
114
mov [rsp+i*8], r9
115
%assign i i+1
116
%endrep
117
%endif
118
119
%if WIN64
120
%assign i 6
121
%rep 16-6
122
mova m %+ i, [x %+ i]
123
%assign i i+1
124
%endrep
125
%endif
126
127
%assign i 14
128
%rep 15-free_regs
129
mov r %+ i, [n %+ i]
130
%assign i i-1
131
%endrep
132
call r6
133
%assign i 14
134
%rep 15-free_regs
135
xor r %+ i, [n %+ i]
136
or r14, r %+ i
137
%assign i i-1
138
%endrep
139
140
%if WIN64
141
%assign i 6
142
%rep 16-6
143
pxor m %+ i, [x %+ i]
144
por m6, m %+ i
145
%assign i i+1
146
%endrep
147
packsswb m6, m6
148
movq r5, m6
149
or r14, r5
150
%endif
151
152
jz .ok
153
mov r9, rax
154
mov r10, rdx
155
lea r0, [error_message]
156
call puts
157
mov r1, [rsp+max_args*8]
158
mov dword [r1], 0
159
mov rdx, r10
160
mov rax, r9
161
.ok:
162
RET
163
164
%else
165
166
; just random numbers to reduce the chance of incidental match
167
%define n3 dword 0x6549315c
168
%define n4 dword 0xe02f3e23
169
%define n5 dword 0xb78d0d1d
170
%define n6 dword 0x33627ba7
171
172
;-----------------------------------------------------------------------------
173
; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
174
;-----------------------------------------------------------------------------
175
cglobal checkasm_call, 1,7
176
mov r3, n3
177
mov r4, n4
178
mov r5, n5
179
mov r6, n6
180
%rep max_args
181
push dword [esp+24+max_args*4]
182
%endrep
183
call r0
184
add esp, max_args*4
185
xor r3, n3
186
xor r4, n4
187
xor r5, n5
188
xor r6, n6
189
or r3, r4
190
or r5, r6
191
or r3, r5
192
jz .ok
193
mov r3, eax
194
mov r4, edx
195
lea r1, [error_message]
196
push r1
197
call puts
198
add esp, 4
199
mov r1, r1m
200
mov dword [r1], 0
201
mov edx, r4
202
mov eax, r3
203
.ok:
204
REP_RET
205
206
%endif ; ARCH_X86_64
207
208
;-----------------------------------------------------------------------------
209
; int x264_stack_pagealign( int (*func)(), int align )
210
;-----------------------------------------------------------------------------
211
cglobal stack_pagealign, 2,2
212
movsxdifnidn r1, r1d
213
push rbp
214
mov rbp, rsp
215
%if WIN64
216
sub rsp, 32 ; shadow space
217
%endif
218
and rsp, ~0xfff
219
sub rsp, r1
220
call r0
221
leave
222
RET
223
224
225