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