Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / lzo / asm / i386 / src / lzo1x_d.ash
blob782b47fe1329437ec6befed712f67140edc6a276
1 /* lzo1x_d.ash -- assembler implementation of the LZO1X decompression algorithm
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/
41  */
44 #if !defined(LZO1X) && !defined(LZO1Y)
45 #  define LZO1X
46 #endif
48 #if defined(LZO_FAST)
49 #  define NN    3
50 #else
51 #  define NN    0
52 #endif
55 /***********************************************************************
56 // init
57 ************************************************************************/
59         xorl    %eax,%eax
60         xorl    %ebx,%ebx       /* high bits 9-32 stay 0 */
61         lodsb
62         cmpb    $17,%al
63         jbe     .L01
64         subb    $17-NN,%al
65 #if defined(LZO_FAST)
66         jmp     .LFLR
67 #else
68         cmpb    $4,%al
69         jae     .LFLR
70 #if 1
71         TEST_OP((%edi,%eax),%edx)
72         TEST_IP((%esi,%eax),%edx)
73         movl    %eax,%ecx
74         jmp     .LFLR2
75 #else
76         jmp     .LFLR3
77 #endif
78 #endif
81 /***********************************************************************
82 // literal run
83 ************************************************************************/
85 0:      addl    N_255,%eax
86         TEST_IP(18(%esi,%eax),%edx)     /* minimum */
87 1:      movb    (%esi),%bl
88         incl    %esi
89         orb     %bl,%bl
90         jz      0b
91         leal    18+NN(%eax,%ebx),%eax
92         jmp     3f
95         ALIGN3
96 .L00:
97 #ifdef LZO_DEBUG
98     andl $0xffffff00,%eax ; jnz .L_assert_fail
99     andl $0xffffff00,%ebx ; jnz .L_assert_fail
100     xorl %eax,%eax ; xorl %ebx,%ebx
101     xorl %ecx,%ecx ; xorl %edx,%edx
102 #endif
103         TEST_IP_R(%esi)
104         LODSB
105 .L01:
106         cmpb    $16,%al
107         jae     .LMATCH
109 /* a literal run */
110         orb     %al,%al
111         jz      1b
112         addl    $3+NN,%eax
114 .LFLR:
115         TEST_OP(-NN(%edi,%eax),%edx)
116         TEST_IP(-NN(%esi,%eax),%edx)
117 #if defined(LZO_FAST)
118         movl    %eax,%ecx
119         NOTL_3(%eax)
120         shrl    $2,%ecx
121         andl    N_3,%eax
122         COPYL(%esi,%edi,%edx)
123         subl    %eax,%esi
124         subl    %eax,%edi
125 #else
126         movl    %eax,%ecx
127         shrl    $2,%eax
128         andl    N_3,%ecx
129         COPYL_C(%esi,%edi,%edx,%eax)
130 .LFLR2:
131         rep
132         movsb
133 #endif
135 #ifdef LZO_DEBUG
136     andl $0xffffff00,%eax ; jnz .L_assert_fail
137     andl $0xffffff00,%ebx ; jnz .L_assert_fail
138     xorl %eax,%eax ; xorl %ebx,%ebx
139     xorl %ecx,%ecx ; xorl %edx,%edx
140 #endif
141         LODSB
142         cmpb    $16,%al
143         jae     .LMATCH
146 /***********************************************************************
147 // R1
148 ************************************************************************/
150         TEST_OP(3(%edi),%edx)
151         shrl    $2,%eax
152         movb    (%esi),%bl
153 #if defined(LZO1X)
154         leal    -0x801(%edi),%edx
155 #elif defined(LZO1Y)
156         leal    -0x401(%edi),%edx
157 #endif
158         leal    (%eax,%ebx,4),%eax
159         incl    %esi
160         subl    %eax,%edx
161         TEST_LOOKBEHIND(%edx)
162 #if defined(LZO_FAST)
163         movl    (%edx),%ecx
164         movl    %ecx,(%edi)
165 #else
166         movb    (%edx),%al
167         movb    %al,(%edi)
168         movb    1(%edx),%al
169         movb    %al,1(%edi)
170         movb    2(%edx),%al
171         movb    %al,2(%edi)
172 #endif
173         addl    N_3,%edi
174         jmp     .LMDONE
177 /***********************************************************************
178 // M2
179 ************************************************************************/
181         ALIGN3
182 .LMATCH:
183         cmpb    $64,%al
184         jb      .LM3MATCH
186 /* a M2 match */
187         movl    %eax,%ecx
188         shrl    $2,%eax
189         leal    -1(%edi),%edx
190 #if defined(LZO1X)
191         andl    $7,%eax
192         movb    (%esi),%bl
193         shrl    $5,%ecx
194         leal    (%eax,%ebx,8),%eax
195 #elif defined(LZO1Y)
196         andl    N_3,%eax
197         movb    (%esi),%bl
198         shrl    $4,%ecx
199         leal    (%eax,%ebx,4),%eax
200 #endif
201         incl    %esi
202         subl    %eax,%edx
204 #if defined(LZO_FAST)
205 #if defined(LZO1X)
206         addl    $1+3,%ecx
207 #elif defined(LZO1Y)
208         addl    $2,%ecx
209 #endif
210 #else
211 #if defined(LZO1X)
212         incl    %ecx
213 #elif defined(LZO1Y)
214         decl    %ecx
215 #endif
216 #endif
218         cmpl    N_3,%eax
219         jae     .LCOPYLONG
220         jmp     .LCOPYBYTE
223 /***********************************************************************
224 // M3
225 ************************************************************************/
227 0:      addl    N_255,%eax
228         TEST_IP(3(%esi),%edx)       /* minimum */
229 1:      movb    (%esi),%bl
230         incl    %esi
231         orb     %bl,%bl
232         jz      0b
233         leal    33+NN(%eax,%ebx),%ecx
234         xorl    %eax,%eax
235         jmp     3f
238         ALIGN3
239 .LM3MATCH:
240         cmpb    $32,%al
241         jb      .LM4MATCH
243 /* a M3 match */
244         andl    $31,%eax
245         jz      1b
246         lea     2+NN(%eax),%ecx
248 #ifdef LZO_DEBUG
249     andl $0xffff0000,%eax ; jnz .L_assert_fail
250 #endif
251         movw    (%esi),%ax
252         leal    -1(%edi),%edx
253         shrl    $2,%eax
254         addl    $2,%esi
255         subl    %eax,%edx
257         cmpl    N_3,%eax
258         jb      .LCOPYBYTE
261 /***********************************************************************
262 // copy match
263 ************************************************************************/
265         ALIGN1
266 .LCOPYLONG:                      /* copy match using longwords */
267         TEST_LOOKBEHIND(%edx)
268 #if defined(LZO_FAST)
269         leal    -3(%edi,%ecx),%eax
270         shrl    $2,%ecx
271         TEST_OP_R(%eax)
272         COPYL(%edx,%edi,%ebx)
273         movl    %eax,%edi
274         xorl    %ebx,%ebx
275 #else
276         TEST_OP((%edi,%ecx),%eax)
277         movl    %ecx,%ebx
278         shrl    $2,%ebx
279         jz      2f
280         COPYL_C(%edx,%edi,%eax,%ebx)
281         andl    N_3,%ecx
282         jz      1f
283 2:      COPYB_C(%edx,%edi,%al,%ecx)
285 #endif
287 .LMDONE:
288         movb    -2(%esi),%al
289         andl    N_3,%eax
290         jz      .L00
291 .LFLR3:
292         TEST_OP((%edi,%eax),%edx)
293         TEST_IP((%esi,%eax),%edx)
294 #if defined(LZO_FAST)
295         movl    (%esi),%edx
296         addl    %eax,%esi
297         movl    %edx,(%edi)
298         addl    %eax,%edi
299 #else
300         COPYB_C(%esi,%edi,%cl,%eax)
301 #endif
303 #ifdef LZO_DEBUG
304     andl $0xffffff00,%eax ; jnz .L_assert_fail
305     andl $0xffffff00,%ebx ; jnz .L_assert_fail
306     xorl %eax,%eax ; xorl %ebx,%ebx
307     xorl %ecx,%ecx ; xorl %edx,%edx
308 #endif
309         LODSB
310         jmp     .LMATCH
313         ALIGN3
314 .LCOPYBYTE:                      /* copy match using bytes */
315         TEST_LOOKBEHIND(%edx)
316         TEST_OP(-NN(%edi,%ecx),%eax)
317         xchgl   %edx,%esi
318 #if defined(LZO_FAST)
319         subl    N_3,%ecx
320 #endif
321         rep
322         movsb
323         movl    %edx,%esi
324         jmp     .LMDONE
327 /***********************************************************************
328 // M4
329 ************************************************************************/
331 0:      addl    N_255,%ecx
332         TEST_IP(3(%esi),%edx)       /* minimum */
333 1:      movb    (%esi),%bl
334         incl    %esi
335         orb     %bl,%bl
336         jz      0b
337         leal    9+NN(%ebx,%ecx),%ecx
338         jmp     3f
341         ALIGN3
342 .LM4MATCH:
343         cmpb    $16,%al
344         jb      .LM1MATCH
346 /* a M4 match */
347         movl    %eax,%ecx
348         andl    $8,%eax
349         shll    $13,%eax        /* save in bit 16 */
350         andl    $7,%ecx
351         jz      1b
352         addl    $2+NN,%ecx
354 #ifdef LZO_DEBUG
355     movl %eax,%edx ; andl $0xfffe0000,%edx ; jnz .L_assert_fail
356 #endif
357         movw    (%esi),%ax
358         addl    $2,%esi
359         leal    -0x4000(%edi),%edx
360         shrl    $2,%eax
361         jz      .LEOF
362         subl    %eax,%edx
363         jmp     .LCOPYLONG
366 /***********************************************************************
367 // M1
368 ************************************************************************/
370         ALIGN3
371 .LM1MATCH:
372 /* a M1 match */
373         TEST_OP(2(%edi),%edx)
374         shrl    $2,%eax
375         movb    (%esi),%bl
376         leal    -1(%edi),%edx
377         leal    (%eax,%ebx,4),%eax
378         incl    %esi
379         subl    %eax,%edx
380         TEST_LOOKBEHIND(%edx)
382         movb    (%edx),%al      /* we must use this because edx can be edi-1 */
383         movb    %al,(%edi)
384         movb    1(%edx),%bl
385         movb    %bl,1(%edi)
386         addl    $2,%edi
387         jmp     .LMDONE
390 /***********************************************************************
392 ************************************************************************/
394 .LEOF:
395 /****   xorl    %eax,%eax          eax=0 from above */
397         cmpl    $3+NN,%ecx      /* ecx must be 3/6 */
398         setnz   %al
402 vi:ts=4