Rev 6851 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6851 | Rev 6873 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | NMAX equ 5552 |
7 | NMAX equ 5552 |
8 | ; NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 |
8 | ; NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | macro DO1 buf,i |
10 | macro DO1 buf,i |
11 | { |
- | |
12 | mov eax,buf |
- | |
13 | add eax,i |
11 | { |
14 | movzx eax,byte[eax] |
12 | movzx eax,byte[buf+i] |
15 | add [adler],eax |
13 | add [adler],eax |
16 | mov eax,[adler] |
- | |
17 | add [sum2],eax |
14 | add edi,[adler] |
18 | } |
15 | } |
19 | macro DO2 buf,i |
16 | macro DO2 buf,i |
20 | { |
17 | { |
21 | DO1 buf,i |
18 | DO1 buf,i |
Line 111... | Line 108... | ||
111 | pop edx ecx eax |
108 | pop edx ecx eax |
112 | end if |
109 | end if |
113 | } |
110 | } |
Line 114... | Line 111... | ||
114 | 111 | ||
115 | ; ========================================================================= |
112 | ; ========================================================================= |
116 | ;uLong (adler, buf, len) |
- | |
117 | ; uLong adler |
- | |
118 | ; const Bytef *buf |
- | |
119 | ; uInt len |
113 | ;uLong (uLong adler, const Bytef *buf, uInt len) |
120 | align 4 |
114 | align 16 |
121 | proc adler32 uses ebx edx, adler:dword, buf:dword, len:dword |
- | |
122 | locals |
- | |
123 | sum2 dd ? ;uLong |
- | |
124 | endl |
- | |
125 | ;zlib_debug 'adler32 adler = %d',[adler] |
115 | proc adler32 uses ebx ecx edx edi, adler:dword, buf:dword, len:dword |
126 | ; split Adler-32 into component sums |
116 | ; split Adler-32 into component sums |
127 | mov eax,[adler] |
117 | mov edi,[adler] |
128 | shr eax,16 |
- | |
129 | mov [sum2],eax |
118 | shr edi,16 |
130 | and [adler],0xffff |
119 | and dword[adler],0xffff |
- | 120 | mov ebx,[buf] |
|
Line 131... | Line 121... | ||
131 | mov ebx,[buf] |
121 | mov ecx,[len] |
132 | 122 | ||
133 | ; in case user likes doing a byte at a time, keep it fast |
123 | ; in case user likes doing a byte at a time, keep it fast |
134 | cmp dword[len],1 |
124 | cmp ecx,1 |
135 | jne .end0 ;if (..==..) |
125 | jne .end0 ;if (..==..) |
136 | movzx eax,byte[ebx] |
126 | movzx eax,byte[ebx] |
137 | add [adler],eax |
127 | add [adler],eax |
138 | cmp dword[adler],BASE |
128 | cmp dword[adler],BASE |
139 | jb @f ;if (..>=..) |
129 | jb @f ;if (..>=..) |
140 | sub dword[adler],BASE |
130 | sub dword[adler],BASE |
141 | @@: |
- | |
142 | mov eax,[adler] |
131 | @@: |
143 | add [sum2],eax |
132 | add edi,[adler] |
144 | cmp dword[sum2],BASE |
133 | cmp edi,BASE |
145 | jb @f ;if (..>=..) |
- | |
146 | sub dword[sum2],BASE |
134 | jae .combine ;if (..>=..) |
147 | @@: |
135 | sub edi,BASE |
148 | jmp .combine |
136 | jmp .combine |
Line 149... | Line 137... | ||
149 | align 4 |
137 | align 4 |
Line 157... | Line 145... | ||
157 | jmp .end_f |
145 | jmp .end_f |
158 | align 4 |
146 | align 4 |
159 | @@: |
147 | @@: |
Line 160... | Line 148... | ||
160 | 148 | ||
161 | ; in case short lengths are provided, keep it somewhat fast |
149 | ; in case short lengths are provided, keep it somewhat fast |
162 | cmp dword[len],16 |
150 | cmp ecx,16 |
163 | jge .end1 ;if (..<..) |
151 | jae .cycle3 ;if (..<..) |
164 | .cycle0: |
152 | .cycle0: |
- | 153 | mov eax,ecx |
|
- | 154 | dec ecx |
|
165 | cmp dword[len],0 |
155 | test eax,eax |
166 | jne @f ;while (..) |
156 | je @f ;while (..) |
167 | movzx eax,byte[ebx] |
- | |
168 | inc ebx |
157 | movzx eax,byte[ebx] |
169 | add [adler],eax |
- | |
170 | mov eax,[adler] |
158 | add [adler],eax |
171 | add [sum2],eax |
159 | inc ebx |
172 | dec dword[len] |
160 | add edi,[adler] |
173 | jmp .cycle0 |
161 | jmp .cycle0 |
174 | align 4 |
162 | align 4 |
175 | @@: |
163 | @@: |
176 | cmp dword[adler],BASE |
164 | cmp dword[adler],BASE |
177 | jl @f ;if (..>=..) |
165 | jb @f ;if (..>=..) |
178 | sub dword[adler],BASE |
166 | sub dword[adler],BASE |
179 | @@: |
167 | @@: |
180 | MOD28 dword[sum2] ;only added so many BASE's |
168 | MOD28 edi ;only added so many BASE's |
181 | jmp .combine |
- | |
182 | align 4 |
- | |
Line 183... | Line 169... | ||
183 | .end1: |
169 | jmp .combine |
- | 170 | ||
184 | 171 | ; do length NMAX blocks -- requires just one modulo operation |
|
185 | ; do length NMAX blocks -- requires just one modulo operation |
172 | align 4 |
186 | .cycle3: |
173 | .cycle3: |
187 | cmp dword[len],NMAX |
174 | cmp ecx,NMAX |
188 | jl .cycle3end ;while (..>=..) |
175 | jb .cycle3end ;while (..>=..) |
189 | sub dword[len],NMAX |
176 | sub ecx,NMAX |
190 | mov edx,NMAX/16 ;NMAX is divisible by 16 |
177 | mov edx,NMAX/16 ;NMAX is divisible by 16 |
191 | .cycle1: ;do |
178 | .cycle1: ;do |
192 | DO16 ebx ;16 sums unrolled |
179 | DO16 ebx ;16 sums unrolled |
193 | add ebx,16 |
- | |
194 | dec edx |
180 | add ebx,16 |
195 | cmp edx,0 |
181 | dec edx |
196 | jg .cycle1 ;while (..) |
182 | jne .cycle1 ;while (..) |
197 | MOD [adler] |
183 | MOD [adler] |
198 | MOD [sum2] |
184 | MOD edi |
199 | jmp .cycle3 |
185 | jmp .cycle3 |
Line 200... | Line 186... | ||
200 | align 4 |
186 | align 4 |
201 | .cycle3end: |
187 | .cycle3end: |
202 | 188 | ||
203 | ; do remaining bytes (less than NMAX, still just one modulo) |
189 | ; do remaining bytes (less than NMAX, still just one modulo) |
204 | cmp dword[len],0 |
190 | cmp ecx,0 |
205 | jne .end2 ;if (..) ;avoid modulos if none remaining |
191 | je .combine ;if (..) ;avoid modulos if none remaining |
206 | @@: |
192 | @@: |
207 | cmp dword[len],16 |
193 | cmp ecx,16 |
208 | jl .cycle2 ;while (..>=..) |
194 | jb .cycle2 ;while (..>=..) |
209 | sub dword[len],16 |
195 | sub ecx,16 |
210 | DO16 ebx |
196 | DO16 ebx |
211 | add ebx,16 |
197 | add ebx,16 |
212 | jmp @b |
198 | jmp @b |
- | 199 | align 4 |
|
- | 200 | .cycle2: |
|
213 | align 4 |
201 | mov eax,ecx |
214 | .cycle2: |
202 | dec ecx |
215 | cmp dword[len],0 |
- | |
216 | jne @f ;while (..) |
203 | test eax,eax |
217 | movzx eax,byte[ebx] |
- | |
218 | inc ebx |
204 | je @f ;while (..) |
219 | add [adler],eax |
205 | movzx eax,byte[ebx] |
220 | mov eax,[adler] |
206 | add [adler],eax |
221 | add [sum2],eax |
207 | inc ebx |
222 | dec dword[len] |
208 | add edi,[adler] |
223 | jmp .cycle2 |
209 | jmp .cycle2 |
224 | align 4 |
210 | align 4 |
225 | @@: |
- | |
Line 226... | Line 211... | ||
226 | MOD [adler] |
211 | @@: |
227 | MOD [sum2] |
212 | MOD [adler] |
228 | .end2: |
213 | MOD edi |
229 | 214 | ||
230 | ; return recombined sums |
215 | ; return recombined sums |
231 | .combine: |
216 | .combine: |
232 | mov eax,[sum2] |
- | |
233 | shl eax,16 |
217 | mov eax,edi |
234 | or eax,[adler] |
218 | shl eax,16 |
Line 235... | Line 219... | ||
235 | .end_f: |
219 | or eax,[adler] |
236 | ;zlib_debug ' adler32.ret = %d',eax |
220 | .end_f: |
237 | ret |
- | |
238 | endp |
- | |
239 | - | ||
240 | ; ========================================================================= |
221 | ret |
241 | ;uLong (adler1, adler2, len2) |
222 | endp |
242 | ; uLong adler1 |
223 | |
243 | ; uLong adler2 |
224 | ; ========================================================================= |
244 | ; z_off64_t len2 |
225 | ;uLong (uLong adler1, uLong adler2, z_off64_t len2) |