1 | /* lzo_asm.h -- LZO assembler stuff |
---|
2 | |
---|
3 | This file is part of the LZO real-time data compression library. |
---|
4 | |
---|
5 | Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer |
---|
6 | All Rights Reserved. |
---|
7 | |
---|
8 | The LZO library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of |
---|
11 | the License, or (at your option) any later version. |
---|
12 | |
---|
13 | The LZO library 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 the LZO library; see the file COPYING. |
---|
20 | If not, write to the Free Software Foundation, Inc., |
---|
21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
22 | |
---|
23 | Markus F.X.J. Oberhumer |
---|
24 | <markus@oberhumer.com> |
---|
25 | http://www.oberhumer.com/opensource/lzo/ |
---|
26 | */ |
---|
27 | |
---|
28 | |
---|
29 | /*********************************************************************** |
---|
30 | // <asmconfig.h> |
---|
31 | ************************************************************************/ |
---|
32 | |
---|
33 | #if !defined(__i386__) |
---|
34 | # error |
---|
35 | #endif |
---|
36 | |
---|
37 | #if !defined(IN_CONFIGURE) |
---|
38 | #if defined(LZO_HAVE_CONFIG_H) |
---|
39 | # include <config.h> |
---|
40 | #else |
---|
41 | /* manual configuration - see defaults below */ |
---|
42 | # if defined(__ELF__) |
---|
43 | # define MFX_ASM_HAVE_TYPE 1 |
---|
44 | # define MFX_ASM_NAME_NO_UNDERSCORES 1 |
---|
45 | # elif defined(__linux__) /* Linux a.out */ |
---|
46 | # define MFX_ASM_ALIGN_PTWO 1 |
---|
47 | # elif defined(__DJGPP__) |
---|
48 | # define MFX_ASM_ALIGN_PTWO 1 |
---|
49 | # elif defined(__GO32__) /* djgpp v1 */ |
---|
50 | # define MFX_ASM_CANNOT_USE_EBP 1 |
---|
51 | # elif defined(__EMX__) |
---|
52 | # define MFX_ASM_ALIGN_PTWO 1 |
---|
53 | # define MFX_ASM_CANNOT_USE_EBP 1 |
---|
54 | # endif |
---|
55 | #endif |
---|
56 | #endif |
---|
57 | |
---|
58 | #if 1 && defined(__ELF__) |
---|
59 | .section .note.GNU-stack,"",@progbits |
---|
60 | #endif |
---|
61 | #if 0 && defined(__ELF__) |
---|
62 | #undef i386 |
---|
63 | .arch i386 |
---|
64 | .code32 |
---|
65 | #endif |
---|
66 | |
---|
67 | |
---|
68 | /*********************************************************************** |
---|
69 | // name always uses underscores |
---|
70 | // [ OLD: name (default: with underscores) ] |
---|
71 | ************************************************************************/ |
---|
72 | |
---|
73 | #if !defined(LZO_ASM_NAME) |
---|
74 | # define LZO_ASM_NAME(n) _ ## n |
---|
75 | #if 0 |
---|
76 | # if defined(MFX_ASM_NAME_NO_UNDERSCORES) |
---|
77 | # define LZO_ASM_NAME(n) n |
---|
78 | # else |
---|
79 | # define LZO_ASM_NAME(n) _ ## n |
---|
80 | # endif |
---|
81 | #endif |
---|
82 | #endif |
---|
83 | |
---|
84 | |
---|
85 | /*********************************************************************** |
---|
86 | // .type (default: do not use) |
---|
87 | ************************************************************************/ |
---|
88 | |
---|
89 | #if !defined(LZO_PUBLIC) |
---|
90 | #if defined(__LZO_DB__) |
---|
91 | # define LZO_PUBLIC(func) \ |
---|
92 | .p2align 4 ; .byte 0,0,0,0,0,0,0 ; .ascii "LZO_START" |
---|
93 | # define LZO_PUBLIC_END(func) \ |
---|
94 | .p2align 4,0x90 ; .ascii "LZO_END" |
---|
95 | #elif defined(MFX_ASM_HAVE_TYPE) |
---|
96 | # define LZO_PUBLIC(func) \ |
---|
97 | ALIGN3 ; .type LZO_ASM_NAME(func),@function ; \ |
---|
98 | .globl LZO_ASM_NAME(func) ; LZO_ASM_NAME(func): |
---|
99 | # define LZO_PUBLIC_END(func) \ |
---|
100 | .size LZO_ASM_NAME(func),.-LZO_ASM_NAME(func) |
---|
101 | #else |
---|
102 | # define LZO_PUBLIC(func) \ |
---|
103 | ALIGN3 ; .globl LZO_ASM_NAME(func) ; LZO_ASM_NAME(func): |
---|
104 | # define LZO_PUBLIC_END(func) |
---|
105 | #endif |
---|
106 | #endif |
---|
107 | |
---|
108 | |
---|
109 | /*********************************************************************** |
---|
110 | // .align (default: bytes) |
---|
111 | ************************************************************************/ |
---|
112 | |
---|
113 | #if !defined(MFX_ASM_ALIGN_BYTES) && !defined(MFX_ASM_ALIGN_PTWO) |
---|
114 | # define MFX_ASM_ALIGN_BYTES 1 |
---|
115 | #endif |
---|
116 | |
---|
117 | #if !defined(LZO_ASM_ALIGN) |
---|
118 | # if defined(MFX_ASM_ALIGN_PTWO) |
---|
119 | # define LZO_ASM_ALIGN(x) .align x |
---|
120 | # else |
---|
121 | # define LZO_ASM_ALIGN(x) .align (1 << (x)) |
---|
122 | # endif |
---|
123 | #endif |
---|
124 | |
---|
125 | #define ALIGN1 LZO_ASM_ALIGN(1) |
---|
126 | #define ALIGN2 LZO_ASM_ALIGN(2) |
---|
127 | #define ALIGN3 LZO_ASM_ALIGN(3) |
---|
128 | |
---|
129 | |
---|
130 | /*********************************************************************** |
---|
131 | // ebp usage (default: can use) |
---|
132 | ************************************************************************/ |
---|
133 | |
---|
134 | #if !defined(MFX_ASM_CANNOT_USE_EBP) |
---|
135 | # if 1 && !defined(N_3_EBP) && !defined(N_255_EBP) |
---|
136 | # define N_3_EBP 1 |
---|
137 | # endif |
---|
138 | # if 0 && !defined(N_3_EBP) && !defined(N_255_EBP) |
---|
139 | # define N_255_EBP 1 |
---|
140 | # endif |
---|
141 | #endif |
---|
142 | |
---|
143 | #if defined(N_3_EBP) && defined(N_255_EBP) |
---|
144 | # error |
---|
145 | #endif |
---|
146 | #if defined(MFX_ASM_CANNOT_USE_EBP) |
---|
147 | # if defined(N_3_EBP) || defined(N_255_EBP) |
---|
148 | # error |
---|
149 | # endif |
---|
150 | #endif |
---|
151 | |
---|
152 | #if !defined(N_3) |
---|
153 | # if defined(N_3_EBP) |
---|
154 | # define N_3 %ebp |
---|
155 | # else |
---|
156 | # define N_3 $3 |
---|
157 | # endif |
---|
158 | #endif |
---|
159 | |
---|
160 | #if !defined(N_255) |
---|
161 | # if defined(N_255_EBP) |
---|
162 | # define N_255 %ebp |
---|
163 | # define NOTL_3(r) xorl %ebp,r |
---|
164 | # else |
---|
165 | # define N_255 $255 |
---|
166 | # endif |
---|
167 | #endif |
---|
168 | |
---|
169 | #if !defined(NOTL_3) |
---|
170 | # define NOTL_3(r) xorl N_3,r |
---|
171 | #endif |
---|
172 | |
---|
173 | |
---|
174 | /*********************************************************************** |
---|
175 | // |
---|
176 | ************************************************************************/ |
---|
177 | |
---|
178 | #ifndef INP |
---|
179 | #define INP 4+36(%esp) |
---|
180 | #define INS 8+36(%esp) |
---|
181 | #define OUTP 12+36(%esp) |
---|
182 | #define OUTS 16+36(%esp) |
---|
183 | #endif |
---|
184 | |
---|
185 | #define INEND 4(%esp) |
---|
186 | #define OUTEND (%esp) |
---|
187 | |
---|
188 | |
---|
189 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
---|
190 | # define TEST_IP_R(r) cmpl r,INEND ; jb .L_input_overrun |
---|
191 | # define TEST_IP(addr,r) leal addr,r ; TEST_IP_R(r) |
---|
192 | #else |
---|
193 | # define TEST_IP_R(r) |
---|
194 | # define TEST_IP(addr,r) |
---|
195 | #endif |
---|
196 | |
---|
197 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
---|
198 | # define TEST_OP_R(r) cmpl r,OUTEND ; jb .L_output_overrun |
---|
199 | # define TEST_OP(addr,r) leal addr,r ; TEST_OP_R(r) |
---|
200 | #else |
---|
201 | # define TEST_OP_R(r) |
---|
202 | # define TEST_OP(addr,r) |
---|
203 | #endif |
---|
204 | |
---|
205 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
---|
206 | # define TEST_LOOKBEHIND(r) cmpl OUTP,r ; jb .L_lookbehind_overrun |
---|
207 | #else |
---|
208 | # define TEST_LOOKBEHIND(r) |
---|
209 | #endif |
---|
210 | |
---|
211 | |
---|
212 | /*********************************************************************** |
---|
213 | // |
---|
214 | ************************************************************************/ |
---|
215 | |
---|
216 | #define LODSB movb (%esi),%al ; incl %esi |
---|
217 | |
---|
218 | #define MOVSB(r1,r2,x) movb (r1),x ; incl r1 ; movb x,(r2) ; incl r2 |
---|
219 | #define MOVSW(r1,r2,x) movb (r1),x ; movb x,(r2) ; \ |
---|
220 | movb 1(r1),x ; addl $2,r1 ; \ |
---|
221 | movb x,1(r2) ; addl $2,r2 |
---|
222 | #define MOVSL(r1,r2,x) movl (r1),x ; addl $4,r1 ; movl x,(r2) ; addl $4,r2 |
---|
223 | |
---|
224 | #if defined(LZO_DEBUG) |
---|
225 | #define COPYB_C(r1,r2,x,rc) \ |
---|
226 | cmpl $0,rc ; jz .L_assert_fail; \ |
---|
227 | 9: MOVSB(r1,r2,x) ; decl rc ; jnz 9b |
---|
228 | #define COPYL_C(r1,r2,x,rc) \ |
---|
229 | cmpl $0,rc ; jz .L_assert_fail; \ |
---|
230 | 9: MOVSL(r1,r2,x) ; decl rc ; jnz 9b |
---|
231 | #else |
---|
232 | #define COPYB_C(r1,r2,x,rc) \ |
---|
233 | 9: MOVSB(r1,r2,x) ; decl rc ; jnz 9b |
---|
234 | #define COPYL_C(r1,r2,x,rc) \ |
---|
235 | 9: MOVSL(r1,r2,x) ; decl rc ; jnz 9b |
---|
236 | #endif |
---|
237 | |
---|
238 | #define COPYB(r1,r2,x) COPYB_C(r1,r2,x,%ecx) |
---|
239 | #define COPYL(r1,r2,x) COPYL_C(r1,r2,x,%ecx) |
---|
240 | |
---|
241 | |
---|
242 | /*********************************************************************** |
---|
243 | // not used |
---|
244 | ************************************************************************/ |
---|
245 | |
---|
246 | #if 0 |
---|
247 | |
---|
248 | #if 0 |
---|
249 | #define REP_MOVSB(x) rep ; movsb |
---|
250 | #define REP_MOVSL(x) shrl $2,%ecx ; rep ; movsl |
---|
251 | #elif 1 |
---|
252 | #define REP_MOVSB(x) COPYB(%esi,%edi,x) |
---|
253 | #define REP_MOVSL(x) shrl $2,%ecx ; COPYL(%esi,%edi,x) |
---|
254 | #else |
---|
255 | #define REP_MOVSB(x) rep ; movsb |
---|
256 | #define REP_MOVSL(x) jmp 9f ; 8: movsb ; decl %ecx ; \ |
---|
257 | 9: testl $3,%edi ; jnz 8b ; \ |
---|
258 | movl %ecx,x ; shrl $2,%ecx ; andl $3,x ; \ |
---|
259 | rep ; movsl ; movl x,%ecx ; rep ; movsb |
---|
260 | #endif |
---|
261 | |
---|
262 | #if 1 |
---|
263 | #define NEGL(x) negl x |
---|
264 | #else |
---|
265 | #define NEGL(x) xorl $-1,x ; incl x |
---|
266 | #endif |
---|
267 | |
---|
268 | #endif |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | /* |
---|
273 | vi:ts=4 |
---|
274 | */ |
---|
275 | |
---|