]> git.sesse.net Git - x264/blob - tools/checkasm-a.asm
Major API change: encapsulate NALs within libx264
[x264] / tools / checkasm-a.asm
1 ;*****************************************************************************
2 ;* checkasm-a.asm
3 ;*****************************************************************************
4 ;* Copyright (C) 2008 Loren Merritt <lorenm@u.washington.edu>
5 ;*
6 ;* This program is free software; you can redistribute it and/or modify
7 ;* it under the terms of the GNU General Public License as published by
8 ;* the Free Software Foundation; either version 2 of the License, or
9 ;* (at your option) any later version.
10 ;*
11 ;* This program is distributed in the hope that it will be useful,
12 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;* GNU General Public License for more details.
15 ;*
16 ;* You should have received a copy of the GNU General Public License
17 ;* along with this program; if not, write to the Free Software
18 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19 ;*****************************************************************************
20
21 %include "x86inc.asm"
22
23 SECTION_RODATA
24
25 error_message: db "failed to preserve register", 0
26
27 %ifdef WIN64
28 ; just random numbers to reduce the chance of incidental match
29 ALIGN 16
30 n4:   dq 0xa77809bf11b239d1
31 n5:   dq 0x2ba9bf3d2f05b389
32 x6:  ddq 0x79445c159ce790641a1b2550a612b48c
33 x7:  ddq 0x86b2536fcd8cf6362eed899d5a28ddcd
34 x8:  ddq 0x3f2bf84fc0fcca4eb0856806085e7943
35 x9:  ddq 0xd229e1f5b281303facbd382dcf5b8de2
36 x10: ddq 0xab63e2e11fa38ed971aeaff20b095fd9
37 x11: ddq 0x77d410d5c42c882d89b0c0765892729a
38 x12: ddq 0x24b3c1d2a024048bc45ea11a955d8dd5
39 x13: ddq 0xdd7b8919edd427862e8ec680de14b47c
40 x14: ddq 0x11e53e2b2ac655ef135ce6888fa02cbf
41 x15: ddq 0x6de8f4c914c334d5011ff554472a7a10
42 %endif
43
44 SECTION .text
45
46 cextern puts
47
48 ; max number of args used by any x264 asm function.
49 ; (max_args % 4) must equal 3 for stack alignment
50 %define max_args 11
51
52 %ifdef WIN64
53
54 ;-----------------------------------------------------------------------------
55 ; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
56 ;-----------------------------------------------------------------------------
57 cglobal x264_checkasm_call, 4,7,16
58     sub  rsp, max_args*8
59     %assign stack_offset stack_offset+max_args*8
60     mov  r6, r0
61     mov  [rsp+stack_offset+16], r1
62     mov  r0, r2
63     mov  r1, r3
64     mov r2d, r4m ; FIXME truncates pointer
65     mov r3d, r5m ; FIXME truncates pointer
66 %assign i 4
67 %rep max_args-4
68     mov  r4, [rsp+stack_offset+8+(i+2)*8]
69     mov  [rsp+i*8], r4
70     %assign i i+1
71 %endrep
72 %assign i 6
73 %rep 16-6
74     movdqa xmm %+ i, [x %+ i GLOBAL]
75     %assign i i+1
76 %endrep
77     mov  r4, [n4 GLOBAL]
78     mov  r5, [n5 GLOBAL]
79     call r6
80     xor  r4, [n4 GLOBAL]
81     xor  r5, [n5 GLOBAL]
82     or   r4, r5
83     pxor xmm5, xmm5
84 %assign i 6
85 %rep 16-6
86     pxor xmm %+ i, [x %+ i GLOBAL]
87     por  xmm5, xmm %+ i
88     %assign i i+1
89 %endrep
90     packsswb xmm5, xmm5
91     movq r5, xmm5
92     or   r4, r5
93     jz .ok
94     mov  r4, rax
95     lea  r0, [error_message GLOBAL]
96     call puts
97     mov  r1, [rsp+stack_offset+16]
98     mov  dword [r1], 0
99     mov  rax, r4
100 .ok:
101     add  rsp, max_args*8
102     %assign stack_offset stack_offset-max_args*8
103     RET
104
105 %elifndef ARCH_X86_64
106
107 ; just random numbers to reduce the chance of incidental match
108 %define n3 dword 0x6549315c
109 %define n4 dword 0xe02f3e23
110 %define n5 dword 0xb78d0d1d
111 %define n6 dword 0x33627ba7
112
113 ;-----------------------------------------------------------------------------
114 ; intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... )
115 ;-----------------------------------------------------------------------------
116 cglobal x264_checkasm_call, 1,7
117     mov  r3, n3
118     mov  r4, n4
119     mov  r5, n5
120     mov  r6, n6
121 %rep max_args
122     push dword [esp+24+max_args*4]
123 %endrep
124     call r0
125     add  esp, max_args*4
126     xor  r3, n3
127     xor  r4, n4
128     xor  r5, n5
129     xor  r6, n6
130     or   r3, r4
131     or   r5, r6
132     or   r3, r5
133     jz .ok
134     mov  r3, eax
135     lea  r1, [error_message GLOBAL]
136     push r1
137     call puts
138     add  esp, 4
139     mov  r1, r1m
140     mov  dword [r1], 0
141     mov  eax, r3
142 .ok:
143     RET
144
145 %endif ; ARCH_X86_64
146
147 ;-----------------------------------------------------------------------------
148 ; int x264_stack_pagealign( int (*func)(), int align )
149 ;-----------------------------------------------------------------------------
150 cglobal x264_stack_pagealign, 2,2
151     push rbp
152     mov  rbp, rsp
153     and  rsp, ~0xfff
154     sub  rsp, r1
155     call r0
156     leave
157     RET
158