1 ;*****************************************************************************
2 ;* Assembly testing and benchmarking tool
3 ;* Copyright (c) 2008 Loren Merritt
4 ;* Copyright (c) 2012 Henrik Gramner
6 ;* This file is part of FFmpeg.
8 ;* FFmpeg is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
13 ;* FFmpeg is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;* GNU General Public License for more details.
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 ;*****************************************************************************
23 %define private_prefix checkasm
24 %include "libavutil/x86/x86inc.asm"
28 error_message: db "failed to preserve register", 0
29 error_message_emms: db "failed to issue emms", 0
32 ; just random numbers to reduce the chance of incidental match
34 x6: dq 0x1a1b2550a612b48c,0x79445c159ce79064
35 x7: dq 0x2eed899d5a28ddcd,0x86b2536fcd8cf636
36 x8: dq 0xb0856806085e7943,0x3f2bf84fc0fcca4e
37 x9: dq 0xacbd382dcf5b8de2,0xd229e1f5b281303f
38 x10: dq 0x71aeaff20b095fd9,0xab63e2e11fa38ed9
39 x11: dq 0x89b0c0765892729a,0x77d410d5c42c882d
40 x12: dq 0xc45ea11a955d8dd5,0x24b3c1d2a024048b
41 x13: dq 0x2e8ec680de14b47c,0xdd7b8919edd42786
42 x14: dq 0x135ce6888fa02cbf,0x11e53e2b2ac655ef
43 x15: dq 0x011ff554472a7a10,0x6de8f4c914c334d5
44 n7: dq 0x21f86d66c8ca00ce
45 n8: dq 0x75b6ba21077c48ad
46 n9: dq 0xed56bb2dcb3c7736
47 n10: dq 0x8bda43d3fd1a7e06
48 n11: dq 0xb64a9c9e5d318408
49 n12: dq 0xdf9a54b303f1d3a3
50 n13: dq 0x4a75479abd64e097
51 n14: dq 0x249214109d5d1c88
58 ; max number of args used by any asm function.
59 ; (max_args % 4) must equal 3 for stack alignment
64 ;-----------------------------------------------------------------------------
65 ; int checkasm_stack_clobber(uint64_t clobber, ...)
66 ;-----------------------------------------------------------------------------
67 cglobal stack_clobber, 1,2
68 ; Clobber the stack with junk below the stack pointer
69 %define argsize (max_args+6)*8
97 ;-----------------------------------------------------------------------------
98 ; void checkasm_checked_call(void *func, ...)
99 ;-----------------------------------------------------------------------------
101 %macro CHECKED_CALL 0-1
102 cglobal checked_call%1, 2,15,16,max_args*8+8
105 ; All arguments have been pushed on the stack instead of registers in order to
106 ; test for incorrect assumptions that 32-bit ints are zero-extended to 64-bit.
116 mov r9, [rsp+stack_offset+(i+1)*8]
117 mov [rsp+(i-6)*8], r9
123 mov r9, [rsp+stack_offset+(i+7)*8]
128 ; Move possible floating-point arguments to the correct registers
136 mova m %+ i, [x %+ i]
157 pxor m %+ i, [x %+ i]
166 ; Call fail_func() with a descriptive message to mark it as a failure
167 ; if the called function didn't preserve all callee-saved registers.
168 ; Save the return value located in rdx:rax first to prevent clobbering.
170 report_fail error_message
176 cmp word [rsp + 8], 0xffff
178 report_fail error_message_emms
187 ; just random numbers to reduce the chance of incidental match
188 %define n3 dword 0x6549315c
189 %define n4 dword 0xe02f3e23
190 %define n5 dword 0xb78d0d1d
191 %define n6 dword 0x33627ba7
203 %macro CHECKED_CALL 0-1
204 ;-----------------------------------------------------------------------------
205 ; void checkasm_checked_call(void *func, ...)
206 ;-----------------------------------------------------------------------------
207 cglobal checked_call%1, 1,7
213 PUSH dword [esp+20+max_args*4]
224 report_fail error_message
230 cmp word [esp + 8], 0xffff
232 report_fail error_message_emms