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