]> git.sesse.net Git - x264/blob - tools/checkasm-a.asm
e737e052954c806d49818cc04ddb72d92a1384c6
[x264] / tools / checkasm-a.asm
1 ;*****************************************************************************
2 ;* checkasm-a.asm: assembly check tool
3 ;*****************************************************************************
4 ;* Copyright (C) 2008-2011 x264 project
5 ;*
6 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
7 ;*
8 ;* This program 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.
12 ;*
13 ;* This program 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.
17 ;*
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 ;*
22 ;* This program is also available under a commercial proprietary license.
23 ;* For more information, contact us at licensing@x264.com.
24 ;*****************************************************************************
25
26 %include "x86inc.asm"
27
28 SECTION_RODATA
29
30 error_message: db "failed to preserve register", 0
31
32 %ifdef WIN64
33 ; just random numbers to reduce the chance of incidental match
34 ALIGN 16
35 n4:   dq 0xa77809bf11b239d1
36 n5:   dq 0x2ba9bf3d2f05b389
37 x6:  ddq 0x79445c159ce790641a1b2550a612b48c
38 x7:  ddq 0x86b2536fcd8cf6362eed899d5a28ddcd
39 x8:  ddq 0x3f2bf84fc0fcca4eb0856806085e7943
40 x9:  ddq 0xd229e1f5b281303facbd382dcf5b8de2
41 x10: ddq 0xab63e2e11fa38ed971aeaff20b095fd9
42 x11: ddq 0x77d410d5c42c882d89b0c0765892729a
43 x12: ddq 0x24b3c1d2a024048bc45ea11a955d8dd5
44 x13: ddq 0xdd7b8919edd427862e8ec680de14b47c
45 x14: ddq 0x11e53e2b2ac655ef135ce6888fa02cbf
46 x15: ddq 0x6de8f4c914c334d5011ff554472a7a10
47 %endif
48
49 SECTION .text
50
51 cextern_naked puts
52
53 ; max number of args used by any x264 asm function.
54 ; (max_args % 4) must equal 3 for stack alignment
55 %define max_args 11
56
57 %ifdef WIN64
58
59 ;-----------------------------------------------------------------------------
60 ; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
61 ;-----------------------------------------------------------------------------
62 INIT_XMM
63 cglobal checkasm_call, 4,7,16
64     sub  rsp, max_args*8
65     %assign stack_offset stack_offset+max_args*8
66     mov  r6, r0
67     mov  [rsp+stack_offset+16], r1
68     mov  r0, r2
69     mov  r1, r3
70     mov r2d, r4m ; FIXME truncates pointer
71     mov r3d, r5m ; FIXME truncates pointer
72 %assign i 4
73 %rep max_args-4
74     mov  r4, [rsp+stack_offset+8+(i+2)*8]
75     mov  [rsp+i*8], r4
76     %assign i i+1
77 %endrep
78 %assign i 6
79 %rep 16-6
80     movdqa xmm %+ i, [x %+ i]
81     %assign i i+1
82 %endrep
83     mov  r4, [n4]
84     mov  r5, [n5]
85     call r6
86     xor  r4, [n4]
87     xor  r5, [n5]
88     or   r4, r5
89     pxor xmm5, xmm5
90 %assign i 6
91 %rep 16-6
92     pxor xmm %+ i, [x %+ i]
93     por  xmm5, xmm %+ i
94     %assign i i+1
95 %endrep
96     packsswb xmm5, xmm5
97     movq r5, xmm5
98     or   r4, r5
99     jz .ok
100     mov  r4, rax
101     lea  r0, [error_message]
102     call puts
103     mov  r1, [rsp+stack_offset+16]
104     mov  dword [r1], 0
105     mov  rax, r4
106 .ok:
107     add  rsp, max_args*8
108     %assign stack_offset stack_offset-max_args*8
109     RET
110
111 %elifndef ARCH_X86_64
112
113 ; just random numbers to reduce the chance of incidental match
114 %define n3 dword 0x6549315c
115 %define n4 dword 0xe02f3e23
116 %define n5 dword 0xb78d0d1d
117 %define n6 dword 0x33627ba7
118
119 ;-----------------------------------------------------------------------------
120 ; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
121 ;-----------------------------------------------------------------------------
122 cglobal checkasm_call, 1,7
123     mov  r3, n3
124     mov  r4, n4
125     mov  r5, n5
126     mov  r6, n6
127 %rep max_args
128     push dword [esp+24+max_args*4]
129 %endrep
130     call r0
131     add  esp, max_args*4
132     xor  r3, n3
133     xor  r4, n4
134     xor  r5, n5
135     xor  r6, n6
136     or   r3, r4
137     or   r5, r6
138     or   r3, r5
139     jz .ok
140     mov  r3, eax
141     lea  r1, [error_message]
142     push r1
143     call puts
144     add  esp, 4
145     mov  r1, r1m
146     mov  dword [r1], 0
147     mov  eax, r3
148 .ok:
149     RET
150
151 %endif ; ARCH_X86_64
152
153 ;-----------------------------------------------------------------------------
154 ; int x264_stack_pagealign( int (*func)(), int align )
155 ;-----------------------------------------------------------------------------
156 cglobal stack_pagealign, 2,2
157     push rbp
158     mov  rbp, rsp
159     and  rsp, ~0xfff
160     sub  rsp, r1
161     call r0
162     leave
163     RET
164