~peter-pearse/ubuntu/natty/unzip/prop001

« back to all changes in this revision

Viewing changes to win32/crc_i386.asm

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2009-05-08 20:02:40 UTC
  • mfrom: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090508200240-7l4gypruop5863bd
* New upstream release. Closes: #496989.
* Enabled new Unicode support. Closes: #197427. This may or may not work
  for your already created zipfiles, but it's not a bug unless they were
  created using the Unicode feature present in zip 3.0.
* Built using DATE_FORMAT=DF_YMD so that unzip -l show dates in ISO format,
  as that's the only available one which makes sense. Closes: #312886.
* Enabled new bzip2 support. Closes: #426798.
* Exit code for zipgrep should now be the right one. Closes: #441997.
* The reason why a file may not be created is now shown. Closes: #478791.
* Summary of changes in this version not being the debian/* files:
- Manpages in section 1, not 1L.
- Branding patch. UnZip by Debian. Original by Info-ZIP.
- Always #include <unistd.h>. Debian GNU/kFreeBSD needs it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;===========================================================================
2
 
; Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.
 
2
; Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
3
3
;
4
4
; See the accompanying file LICENSE, version 2000-Apr-09 or later
5
5
; (the contents of which are also included in zip.h) for terms of use.
7
7
; also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8
8
;===========================================================================
9
9
; crc_i386.asm, optimized CRC calculation function for Zip and UnZip,
10
 
; created by Paul Kienitz and Christian Spieler.  Last revised 16 Jan 2005.
 
10
; created by Paul Kienitz and Christian Spieler.  Last revised 07 Jan 2007.
11
11
;
12
12
; Revised 06-Oct-96, Scott Field (sfield@microsoft.com)
13
13
;   fixed to assemble with masm by not using .model directive which makes
47
47
;   Enabled the 686 build by default, because there are hardly any pre-686 CPUs
48
48
;   in serious use nowadays. (See the 12-Oct-97 note above.)
49
49
;
 
50
; Revised 03-Jan-2006, Chr. Spieler
 
51
;   Enlarged unrolling loops to "do 16 bytes per turn"; optimized access to
 
52
;   data buffer in loop body (adjust pointer only once in loop body and use
 
53
;   offsets to access each item); added additional support for the "unfolded
 
54
;   tables" optimization variant (enabled by IZ_CRCOPTIM_UNFOLDTBL).
 
55
;
 
56
; Revised 07-Jan-2007, Chr. Spieler
 
57
;   Recognize additional conditional flag CRC_TABLE_ONLY that prevents
 
58
;   compilation of the crc32() function.
 
59
;
50
60
; FLAT memory model assumed.
51
61
;
52
62
; Loop unrolling can be disabled by defining the macro NO_UNROLLED_LOOPS.
54
64
;
55
65
;==============================================================================
56
66
;
57
 
; Do NOT assemble this source if external crc32 routine from zlib gets used.
 
67
; Do NOT assemble this source if external crc32 routine from zlib gets used,
 
68
; or only the precomputed CRC_32_Table is needed.
58
69
;
59
70
    IFNDEF USE_ZLIB
 
71
    IFNDEF CRC_TABLE_ONLY
60
72
;
61
73
        .386p
62
74
        name    crc_i386
122
134
        ENDM
123
135
    ELSE ; __686 : optimize for Pentium Pro, Pentium II and compatible CPUs
124
136
Do_CRC  MACRO
125
 
                movzx   ebx,al               ; tmp = c & 0xFF
126
 
                shr     eax,8                ; c = (c >> 8)
127
 
                xor     eax,[edi+ebx*4]      ;  ^ table[tmp]
 
137
                movzx   ebx,al                 ; tmp = c & 0xFF
 
138
                shr     eax,8                  ; c = (c >> 8)
 
139
                xor     eax,[edi+ebx*4]        ;  ^ table[tmp]
128
140
        ENDM
129
141
    ENDIF ; ?__686
130
142
Do_CRC_byte     MACRO
131
 
                xor     al, byte ptr [esi]   ; c ^= *buf
132
 
                inc     esi                  ; buf++
133
 
                Do_CRC                       ; c = (c >> 8) ^ table[c & 0xFF]
 
143
                xor     al, byte ptr [esi]     ; c ^= *buf
 
144
                inc     esi                    ; buf++
 
145
                Do_CRC                         ; c = (c >> 8) ^ table[c & 0xFF]
 
146
        ENDM
 
147
Do_CRC_byteof   MACRO   ofs
 
148
                xor     al, byte ptr [esi+ofs] ; c ^= *(buf+ofs)
 
149
                Do_CRC                         ; c = (c >> 8) ^ table[c & 0xFF]
134
150
        ENDM
135
151
    IFNDEF  NO_32_BIT_LOADS
 
152
      IFDEF IZ_CRCOPTIM_UNFOLDTBL
 
153
        ; the edx register is needed in crc calculation
 
154
        SavLen  EQU     Arg3
 
155
 
 
156
UpdCRC_dword    MACRO
 
157
                movzx   ebx,al                 ; tmp = c & 0xFF
 
158
                mov     edx,[edi+ebx*4+3072]   ;  table[256*3+tmp]
 
159
                movzx   ebx,ah                 ; tmp = (c>>8) & 0xFF
 
160
                shr     eax,16                 ;
 
161
                xor     edx,[edi+ebx*4+2048]   ;  ^ table[256*2+tmp]
 
162
                movzx   ebx,al                 ; tmp = (c>>16) & 0xFF
 
163
                shr     eax,8                  ; tmp = (c>>24)
 
164
                xor     edx,[edi+ebx*4+1024]   ;  ^ table[256*1+tmp]
 
165
                mov     eax,[edi+eax*4]        ;  ^ table[256*0+tmp]
 
166
                xor     eax,edx                ; ..
 
167
        ENDM
 
168
UpdCRC_dword_sh MACRO   dwPtrIncr
 
169
                movzx   ebx,al                 ; tmp = c & 0xFF
 
170
                mov     edx,[edi+ebx*4+3072]   ;  table[256*3+tmp]
 
171
                movzx   ebx,ah                 ; tmp = (c>>8) & 0xFF
 
172
                xor     edx,[edi+ebx*4+2048]   ;  ^ table[256*2+tmp]
 
173
                shr     eax,16                 ;
 
174
                movzx   ebx,al                 ; tmp = (c>>16) & 0xFF
 
175
                add     esi, 4*dwPtrIncr       ; ((ulg *)buf) += dwPtrIncr
 
176
                shr     eax,8                  ; tmp = (c>>24)
 
177
                xor     edx,[edi+ebx*4+1024]   ;  ^ table[256*1+tmp]
 
178
                mov     eax,[edi+eax*4]        ;  ^ table[256*0+tmp]
 
179
                xor     eax,edx                ; ..
 
180
        ENDM
 
181
      ELSE ; IZ_CRCOPTIM_UNFOLDTBL
 
182
        ; the edx register is not needed anywhere else
 
183
        SavLen  EQU     edx
 
184
 
 
185
UpdCRC_dword    MACRO
 
186
                Do_CRC
 
187
                Do_CRC
 
188
                Do_CRC
 
189
                Do_CRC
 
190
        ENDM
 
191
UpdCRC_dword_sh MACRO   dwPtrIncr
 
192
                Do_CRC
 
193
                Do_CRC
 
194
                add     esi, 4*dwPtrIncr       ; ((ulg *)buf) += dwPtrIncr
 
195
                Do_CRC
 
196
                Do_CRC
 
197
        ENDM
 
198
      ENDIF ; ?IZ_CRCOPTIM_UNFOLDTBL
136
199
Do_CRC_dword    MACRO
137
 
                xor     eax, dword ptr [esi] ; c ^= *(ulg *)buf
138
 
                add     esi, 4               ; ((ulg *)buf)++
139
 
                Do_CRC
140
 
                Do_CRC
141
 
                Do_CRC
142
 
                Do_CRC
 
200
                xor     eax, dword ptr [esi]   ; c ^= *(ulg *)buf
 
201
                UpdCRC_dword_sh 1              ; ... ((ulg *)buf)++
 
202
        ENDM
 
203
Do_CRC_4dword   MACRO
 
204
                xor     eax, dword ptr [esi]    ; c ^= *(ulg *)buf
 
205
                UpdCRC_dword
 
206
                xor     eax, dword ptr [esi+4]  ; c ^= *((ulg *)buf+1)
 
207
                UpdCRC_dword
 
208
                xor     eax, dword ptr [esi+8]  ; c ^= *((ulg *)buf+2)
 
209
                UpdCRC_dword
 
210
                xor     eax, dword ptr [esi+12] ; c ^= *((ulg *)buf]+3
 
211
                UpdCRC_dword_sh 4               ; ... ((ulg *)buf)+=4
143
212
        ENDM
144
213
    ENDIF ; !NO_32_BIT_LOADS
145
214
 
159
228
                push    edx
160
229
                push    ecx
161
230
 
162
 
                mov     esi,Arg2             ; 2nd arg: uch *buf
163
 
                sub     eax,eax              ;> if (!buf)
164
 
                test    esi,esi              ;>   return 0;
165
 
                jz      fine                 ;> else {
 
231
                mov     esi,Arg2            ; 2nd arg: uch *buf
 
232
                sub     eax,eax             ;> if (!buf)
 
233
                test    esi,esi             ;>   return 0;
 
234
                jz      fine                ;> else {
166
235
 
167
236
                call    _get_crc_table
168
237
                mov     edi,eax
169
 
                mov     eax,Arg1             ; 1st arg: ulg crc
 
238
                mov     eax,Arg1            ; 1st arg: ulg crc
170
239
    IFNDEF __686
171
 
                sub     ebx,ebx              ; ebx=0; make bl usable as a dword
 
240
                sub     ebx,ebx             ; ebx=0; make bl usable as a dword
172
241
    ENDIF
173
 
                mov     ecx,Arg3             ; 3rd arg: extent len
174
 
                not     eax                  ;>   c = ~crc;
 
242
                mov     ecx,Arg3            ; 3rd arg: extent len
 
243
                not     eax                 ;>   c = ~crc;
175
244
 
176
245
                test    ecx,ecx
177
246
    IFNDEF  NO_UNROLLED_LOOPS
178
247
                jz      bail
179
248
    IFNDEF  NO_32_BIT_LOADS
180
249
align_loop:
181
 
                test    esi,3                ; align buf pointer on next
182
 
                jz      SHORT aligned_now    ;  dword boundary
 
250
                test    esi,3               ; align buf pointer on next
 
251
                jz      SHORT aligned_now   ;  dword boundary
183
252
                Do_CRC_byte
184
253
                dec     ecx
185
254
                jnz     align_loop
186
255
aligned_now:
187
256
    ENDIF ; !NO_32_BIT_LOADS
188
 
                mov     edx,ecx              ; save len in edx
189
 
                shr     ecx,3                ; ecx = len / 8
190
 
                jz      SHORT No_Eights
 
257
                mov     SavLen,ecx          ; save current len for later
 
258
                shr     ecx,4               ; ecx = len / 16
 
259
                jz      No_Sixteens
191
260
    IFNDEF NO_ALIGN
192
261
; align loop head at start of 486 internal cache line !!
193
262
                align   16
194
263
    ENDIF
195
 
Next_Eight:
 
264
Next_Sixteen:
196
265
    IFNDEF  NO_32_BIT_LOADS
197
 
                Do_CRC_dword
198
 
                Do_CRC_dword
 
266
                Do_CRC_4dword
199
267
    ELSE ; NO_32_BIT_LOADS
200
 
                Do_CRC_byte
201
 
                Do_CRC_byte
202
 
                Do_CRC_byte
203
 
                Do_CRC_byte
204
 
                Do_CRC_byte
205
 
                Do_CRC_byte
206
 
                Do_CRC_byte
207
 
                Do_CRC_byte
 
268
                Do_CRC_byteof   0
 
269
                Do_CRC_byteof   1
 
270
                Do_CRC_byteof   2
 
271
                Do_CRC_byteof   3
 
272
                Do_CRC_byteof   4
 
273
                Do_CRC_byteof   5
 
274
                Do_CRC_byteof   6
 
275
                Do_CRC_byteof   7
 
276
                Do_CRC_byteof   8
 
277
                Do_CRC_byteof   9
 
278
                Do_CRC_byteof   10
 
279
                Do_CRC_byteof   11
 
280
                Do_CRC_byteof   12
 
281
                Do_CRC_byteof   13
 
282
                Do_CRC_byteof   14
 
283
                Do_CRC_byteof   15
 
284
                add     esi, 16                 ; buf += 16
208
285
    ENDIF ; ?NO_32_BIT_LOADS
209
286
                dec     ecx
210
 
                jnz     Next_Eight
211
 
No_Eights:
212
 
                mov     ecx,edx
213
 
                and     ecx,000000007H       ; ecx = len % 8
 
287
                jnz     Next_Sixteen
 
288
No_Sixteens:
 
289
                mov     ecx,SavLen
 
290
                and     ecx,00000000FH      ; ecx = len % 16
 
291
    IFNDEF  NO_32_BIT_LOADS
 
292
                shr     ecx,2               ; ecx = len / 4
 
293
                jz      SHORT No_Fours
 
294
Next_Four:
 
295
                Do_CRC_dword
 
296
                dec     ecx
 
297
                jnz     Next_Four
 
298
No_Fours:
 
299
                mov     ecx,SavLen
 
300
                and     ecx,000000003H      ; ecx = len % 4
 
301
    ENDIF ; !NO_32_BIT_LOADS
214
302
    ENDIF ; !NO_UNROLLED_LOOPS
215
 
                jz      SHORT bail           ;>   if (len)
 
303
                jz      SHORT bail          ;>   if (len)
216
304
    IFNDEF NO_ALIGN
217
305
; align loop head at start of 486 internal cache line !!
218
306
                align   16
219
307
    ENDIF
220
 
loupe:                                       ;>     do {
221
 
                Do_CRC_byte                  ;        c = CRC32(c, *buf++);
222
 
                dec     ecx                  ;>     } while (--len);
 
308
loupe:                                      ;>     do {
 
309
                Do_CRC_byte                 ;        c = CRC32(c,*buf++,crctab);
 
310
                dec     ecx                 ;>     } while (--len);
223
311
                jnz     loupe
224
312
 
225
 
bail:                                        ;> }
226
 
                not     eax                  ;> return ~c;
 
313
bail:                                       ;> }
 
314
                not     eax                 ;> return ~c;
227
315
fine:
228
316
                pop     ecx
229
317
                pop     edx
236
324
 
237
325
_TEXT   ends
238
326
;
 
327
    ENDIF ; !CRC_TABLE_ONLY
239
328
    ENDIF ; !USE_ZLIB
240
329
;
241
330
end