annotate src/zlib-1.2.8/contrib/inflate86/inffast.S @ 155:54abead6ecce

Opus for Windows (MSVC)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 25 Jan 2019 12:15:58 +0000
parents 5b4145a0d408
children
rev   line source
cannam@128 1 /*
cannam@128 2 * inffast.S is a hand tuned assembler version of:
cannam@128 3 *
cannam@128 4 * inffast.c -- fast decoding
cannam@128 5 * Copyright (C) 1995-2003 Mark Adler
cannam@128 6 * For conditions of distribution and use, see copyright notice in zlib.h
cannam@128 7 *
cannam@128 8 * Copyright (C) 2003 Chris Anderson <christop@charm.net>
cannam@128 9 * Please use the copyright conditions above.
cannam@128 10 *
cannam@128 11 * This version (Jan-23-2003) of inflate_fast was coded and tested under
cannam@128 12 * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that
cannam@128 13 * machine, I found that gzip style archives decompressed about 20% faster than
cannam@128 14 * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will
cannam@128 15 * depend on how large of a buffer is used for z_stream.next_in & next_out
cannam@128 16 * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in
cannam@128 17 * stream processing I/O and crc32/addler32. In my case, this routine used
cannam@128 18 * 70% of the cpu time and crc32 used 20%.
cannam@128 19 *
cannam@128 20 * I am confident that this version will work in the general case, but I have
cannam@128 21 * not tested a wide variety of datasets or a wide variety of platforms.
cannam@128 22 *
cannam@128 23 * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating.
cannam@128 24 * It should be a runtime flag instead of compile time flag...
cannam@128 25 *
cannam@128 26 * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction.
cannam@128 27 * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code
cannam@128 28 * is compiled. Without either option, runtime detection is enabled. Runtime
cannam@128 29 * detection should work on all modern cpus and the recomended algorithm (flip
cannam@128 30 * ID bit on eflags and then use the cpuid instruction) is used in many
cannam@128 31 * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12
cannam@128 32 * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o
cannam@128 33 * inffast.obj generates a COFF object which can then be linked with MSVC++
cannam@128 34 * compiled code. Tested under FreeBSD 4.7 with gcc-2.95.
cannam@128 35 *
cannam@128 36 * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and
cannam@128 37 * slower than compiler generated code). Adjusted cpuid check to use the MMX
cannam@128 38 * code only for Pentiums < P4 until I have more data on the P4. Speed
cannam@128 39 * improvment is only about 15% on the Athlon when compared with code generated
cannam@128 40 * with MSVC++. Not sure yet, but I think the P4 will also be slower using the
cannam@128 41 * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and
cannam@128 42 * have less latency than MMX ops. Added code to buffer the last 11 bytes of
cannam@128 43 * the input stream since the MMX code grabs bits in chunks of 32, which
cannam@128 44 * differs from the inffast.c algorithm. I don't think there would have been
cannam@128 45 * read overruns where a page boundary was crossed (a segfault), but there
cannam@128 46 * could have been overruns when next_in ends on unaligned memory (unintialized
cannam@128 47 * memory read).
cannam@128 48 *
cannam@128 49 * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C
cannam@128 50 * version of the non-MMX code so that it doesn't depend on zstrm and zstate
cannam@128 51 * structure offsets which are hard coded in this file. This was last tested
cannam@128 52 * with zlib-1.2.0 which is currently in beta testing, newer versions of this
cannam@128 53 * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and
cannam@128 54 * http://www.charm.net/~christop/zlib/
cannam@128 55 */
cannam@128 56
cannam@128 57
cannam@128 58 /*
cannam@128 59 * if you have underscore linking problems (_inflate_fast undefined), try
cannam@128 60 * using -DGAS_COFF
cannam@128 61 */
cannam@128 62 #if ! defined( GAS_COFF ) && ! defined( GAS_ELF )
cannam@128 63
cannam@128 64 #if defined( WIN32 ) || defined( __CYGWIN__ )
cannam@128 65 #define GAS_COFF /* windows object format */
cannam@128 66 #else
cannam@128 67 #define GAS_ELF
cannam@128 68 #endif
cannam@128 69
cannam@128 70 #endif /* ! GAS_COFF && ! GAS_ELF */
cannam@128 71
cannam@128 72
cannam@128 73 #if defined( GAS_COFF )
cannam@128 74
cannam@128 75 /* coff externals have underscores */
cannam@128 76 #define inflate_fast _inflate_fast
cannam@128 77 #define inflate_fast_use_mmx _inflate_fast_use_mmx
cannam@128 78
cannam@128 79 #endif /* GAS_COFF */
cannam@128 80
cannam@128 81
cannam@128 82 .file "inffast.S"
cannam@128 83
cannam@128 84 .globl inflate_fast
cannam@128 85
cannam@128 86 .text
cannam@128 87 .align 4,0
cannam@128 88 .L_invalid_literal_length_code_msg:
cannam@128 89 .string "invalid literal/length code"
cannam@128 90
cannam@128 91 .align 4,0
cannam@128 92 .L_invalid_distance_code_msg:
cannam@128 93 .string "invalid distance code"
cannam@128 94
cannam@128 95 .align 4,0
cannam@128 96 .L_invalid_distance_too_far_msg:
cannam@128 97 .string "invalid distance too far back"
cannam@128 98
cannam@128 99 #if ! defined( NO_MMX )
cannam@128 100 .align 4,0
cannam@128 101 .L_mask: /* mask[N] = ( 1 << N ) - 1 */
cannam@128 102 .long 0
cannam@128 103 .long 1
cannam@128 104 .long 3
cannam@128 105 .long 7
cannam@128 106 .long 15
cannam@128 107 .long 31
cannam@128 108 .long 63
cannam@128 109 .long 127
cannam@128 110 .long 255
cannam@128 111 .long 511
cannam@128 112 .long 1023
cannam@128 113 .long 2047
cannam@128 114 .long 4095
cannam@128 115 .long 8191
cannam@128 116 .long 16383
cannam@128 117 .long 32767
cannam@128 118 .long 65535
cannam@128 119 .long 131071
cannam@128 120 .long 262143
cannam@128 121 .long 524287
cannam@128 122 .long 1048575
cannam@128 123 .long 2097151
cannam@128 124 .long 4194303
cannam@128 125 .long 8388607
cannam@128 126 .long 16777215
cannam@128 127 .long 33554431
cannam@128 128 .long 67108863
cannam@128 129 .long 134217727
cannam@128 130 .long 268435455
cannam@128 131 .long 536870911
cannam@128 132 .long 1073741823
cannam@128 133 .long 2147483647
cannam@128 134 .long 4294967295
cannam@128 135 #endif /* NO_MMX */
cannam@128 136
cannam@128 137 .text
cannam@128 138
cannam@128 139 /*
cannam@128 140 * struct z_stream offsets, in zlib.h
cannam@128 141 */
cannam@128 142 #define next_in_strm 0 /* strm->next_in */
cannam@128 143 #define avail_in_strm 4 /* strm->avail_in */
cannam@128 144 #define next_out_strm 12 /* strm->next_out */
cannam@128 145 #define avail_out_strm 16 /* strm->avail_out */
cannam@128 146 #define msg_strm 24 /* strm->msg */
cannam@128 147 #define state_strm 28 /* strm->state */
cannam@128 148
cannam@128 149 /*
cannam@128 150 * struct inflate_state offsets, in inflate.h
cannam@128 151 */
cannam@128 152 #define mode_state 0 /* state->mode */
cannam@128 153 #define wsize_state 32 /* state->wsize */
cannam@128 154 #define write_state 40 /* state->write */
cannam@128 155 #define window_state 44 /* state->window */
cannam@128 156 #define hold_state 48 /* state->hold */
cannam@128 157 #define bits_state 52 /* state->bits */
cannam@128 158 #define lencode_state 68 /* state->lencode */
cannam@128 159 #define distcode_state 72 /* state->distcode */
cannam@128 160 #define lenbits_state 76 /* state->lenbits */
cannam@128 161 #define distbits_state 80 /* state->distbits */
cannam@128 162
cannam@128 163 /*
cannam@128 164 * inflate_fast's activation record
cannam@128 165 */
cannam@128 166 #define local_var_size 64 /* how much local space for vars */
cannam@128 167 #define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */
cannam@128 168 #define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */
cannam@128 169
cannam@128 170 /*
cannam@128 171 * offsets for local vars on stack
cannam@128 172 */
cannam@128 173 #define out 60 /* unsigned char* */
cannam@128 174 #define window 56 /* unsigned char* */
cannam@128 175 #define wsize 52 /* unsigned int */
cannam@128 176 #define write 48 /* unsigned int */
cannam@128 177 #define in 44 /* unsigned char* */
cannam@128 178 #define beg 40 /* unsigned char* */
cannam@128 179 #define buf 28 /* char[ 12 ] */
cannam@128 180 #define len 24 /* unsigned int */
cannam@128 181 #define last 20 /* unsigned char* */
cannam@128 182 #define end 16 /* unsigned char* */
cannam@128 183 #define dcode 12 /* code* */
cannam@128 184 #define lcode 8 /* code* */
cannam@128 185 #define dmask 4 /* unsigned int */
cannam@128 186 #define lmask 0 /* unsigned int */
cannam@128 187
cannam@128 188 /*
cannam@128 189 * typedef enum inflate_mode consts, in inflate.h
cannam@128 190 */
cannam@128 191 #define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */
cannam@128 192 #define INFLATE_MODE_BAD 26
cannam@128 193
cannam@128 194
cannam@128 195 #if ! defined( USE_MMX ) && ! defined( NO_MMX )
cannam@128 196
cannam@128 197 #define RUN_TIME_MMX
cannam@128 198
cannam@128 199 #define CHECK_MMX 1
cannam@128 200 #define DO_USE_MMX 2
cannam@128 201 #define DONT_USE_MMX 3
cannam@128 202
cannam@128 203 .globl inflate_fast_use_mmx
cannam@128 204
cannam@128 205 .data
cannam@128 206
cannam@128 207 .align 4,0
cannam@128 208 inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */
cannam@128 209 .long CHECK_MMX
cannam@128 210
cannam@128 211 #if defined( GAS_ELF )
cannam@128 212 /* elf info */
cannam@128 213 .type inflate_fast_use_mmx,@object
cannam@128 214 .size inflate_fast_use_mmx,4
cannam@128 215 #endif
cannam@128 216
cannam@128 217 #endif /* RUN_TIME_MMX */
cannam@128 218
cannam@128 219 #if defined( GAS_COFF )
cannam@128 220 /* coff info: scl 2 = extern, type 32 = function */
cannam@128 221 .def inflate_fast; .scl 2; .type 32; .endef
cannam@128 222 #endif
cannam@128 223
cannam@128 224 .text
cannam@128 225
cannam@128 226 .align 32,0x90
cannam@128 227 inflate_fast:
cannam@128 228 pushl %edi
cannam@128 229 pushl %esi
cannam@128 230 pushl %ebp
cannam@128 231 pushl %ebx
cannam@128 232 pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */
cannam@128 233 subl $local_var_size, %esp
cannam@128 234 cld
cannam@128 235
cannam@128 236 #define strm_r %esi
cannam@128 237 #define state_r %edi
cannam@128 238
cannam@128 239 movl strm_sp(%esp), strm_r
cannam@128 240 movl state_strm(strm_r), state_r
cannam@128 241
cannam@128 242 /* in = strm->next_in;
cannam@128 243 * out = strm->next_out;
cannam@128 244 * last = in + strm->avail_in - 11;
cannam@128 245 * beg = out - (start - strm->avail_out);
cannam@128 246 * end = out + (strm->avail_out - 257);
cannam@128 247 */
cannam@128 248 movl avail_in_strm(strm_r), %edx
cannam@128 249 movl next_in_strm(strm_r), %eax
cannam@128 250
cannam@128 251 addl %eax, %edx /* avail_in += next_in */
cannam@128 252 subl $11, %edx /* avail_in -= 11 */
cannam@128 253
cannam@128 254 movl %eax, in(%esp)
cannam@128 255 movl %edx, last(%esp)
cannam@128 256
cannam@128 257 movl start_sp(%esp), %ebp
cannam@128 258 movl avail_out_strm(strm_r), %ecx
cannam@128 259 movl next_out_strm(strm_r), %ebx
cannam@128 260
cannam@128 261 subl %ecx, %ebp /* start -= avail_out */
cannam@128 262 negl %ebp /* start = -start */
cannam@128 263 addl %ebx, %ebp /* start += next_out */
cannam@128 264
cannam@128 265 subl $257, %ecx /* avail_out -= 257 */
cannam@128 266 addl %ebx, %ecx /* avail_out += out */
cannam@128 267
cannam@128 268 movl %ebx, out(%esp)
cannam@128 269 movl %ebp, beg(%esp)
cannam@128 270 movl %ecx, end(%esp)
cannam@128 271
cannam@128 272 /* wsize = state->wsize;
cannam@128 273 * write = state->write;
cannam@128 274 * window = state->window;
cannam@128 275 * hold = state->hold;
cannam@128 276 * bits = state->bits;
cannam@128 277 * lcode = state->lencode;
cannam@128 278 * dcode = state->distcode;
cannam@128 279 * lmask = ( 1 << state->lenbits ) - 1;
cannam@128 280 * dmask = ( 1 << state->distbits ) - 1;
cannam@128 281 */
cannam@128 282
cannam@128 283 movl lencode_state(state_r), %eax
cannam@128 284 movl distcode_state(state_r), %ecx
cannam@128 285
cannam@128 286 movl %eax, lcode(%esp)
cannam@128 287 movl %ecx, dcode(%esp)
cannam@128 288
cannam@128 289 movl $1, %eax
cannam@128 290 movl lenbits_state(state_r), %ecx
cannam@128 291 shll %cl, %eax
cannam@128 292 decl %eax
cannam@128 293 movl %eax, lmask(%esp)
cannam@128 294
cannam@128 295 movl $1, %eax
cannam@128 296 movl distbits_state(state_r), %ecx
cannam@128 297 shll %cl, %eax
cannam@128 298 decl %eax
cannam@128 299 movl %eax, dmask(%esp)
cannam@128 300
cannam@128 301 movl wsize_state(state_r), %eax
cannam@128 302 movl write_state(state_r), %ecx
cannam@128 303 movl window_state(state_r), %edx
cannam@128 304
cannam@128 305 movl %eax, wsize(%esp)
cannam@128 306 movl %ecx, write(%esp)
cannam@128 307 movl %edx, window(%esp)
cannam@128 308
cannam@128 309 movl hold_state(state_r), %ebp
cannam@128 310 movl bits_state(state_r), %ebx
cannam@128 311
cannam@128 312 #undef strm_r
cannam@128 313 #undef state_r
cannam@128 314
cannam@128 315 #define in_r %esi
cannam@128 316 #define from_r %esi
cannam@128 317 #define out_r %edi
cannam@128 318
cannam@128 319 movl in(%esp), in_r
cannam@128 320 movl last(%esp), %ecx
cannam@128 321 cmpl in_r, %ecx
cannam@128 322 ja .L_align_long /* if in < last */
cannam@128 323
cannam@128 324 addl $11, %ecx /* ecx = &in[ avail_in ] */
cannam@128 325 subl in_r, %ecx /* ecx = avail_in */
cannam@128 326 movl $12, %eax
cannam@128 327 subl %ecx, %eax /* eax = 12 - avail_in */
cannam@128 328 leal buf(%esp), %edi
cannam@128 329 rep movsb /* memcpy( buf, in, avail_in ) */
cannam@128 330 movl %eax, %ecx
cannam@128 331 xorl %eax, %eax
cannam@128 332 rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */
cannam@128 333 leal buf(%esp), in_r /* in = buf */
cannam@128 334 movl in_r, last(%esp) /* last = in, do just one iteration */
cannam@128 335 jmp .L_is_aligned
cannam@128 336
cannam@128 337 /* align in_r on long boundary */
cannam@128 338 .L_align_long:
cannam@128 339 testl $3, in_r
cannam@128 340 jz .L_is_aligned
cannam@128 341 xorl %eax, %eax
cannam@128 342 movb (in_r), %al
cannam@128 343 incl in_r
cannam@128 344 movl %ebx, %ecx
cannam@128 345 addl $8, %ebx
cannam@128 346 shll %cl, %eax
cannam@128 347 orl %eax, %ebp
cannam@128 348 jmp .L_align_long
cannam@128 349
cannam@128 350 .L_is_aligned:
cannam@128 351 movl out(%esp), out_r
cannam@128 352
cannam@128 353 #if defined( NO_MMX )
cannam@128 354 jmp .L_do_loop
cannam@128 355 #endif
cannam@128 356
cannam@128 357 #if defined( USE_MMX )
cannam@128 358 jmp .L_init_mmx
cannam@128 359 #endif
cannam@128 360
cannam@128 361 /*** Runtime MMX check ***/
cannam@128 362
cannam@128 363 #if defined( RUN_TIME_MMX )
cannam@128 364 .L_check_mmx:
cannam@128 365 cmpl $DO_USE_MMX, inflate_fast_use_mmx
cannam@128 366 je .L_init_mmx
cannam@128 367 ja .L_do_loop /* > 2 */
cannam@128 368
cannam@128 369 pushl %eax
cannam@128 370 pushl %ebx
cannam@128 371 pushl %ecx
cannam@128 372 pushl %edx
cannam@128 373 pushf
cannam@128 374 movl (%esp), %eax /* copy eflags to eax */
cannam@128 375 xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21)
cannam@128 376 * to see if cpu supports cpuid...
cannam@128 377 * ID bit method not supported by NexGen but
cannam@128 378 * bios may load a cpuid instruction and
cannam@128 379 * cpuid may be disabled on Cyrix 5-6x86 */
cannam@128 380 popf
cannam@128 381 pushf
cannam@128 382 popl %edx /* copy new eflags to edx */
cannam@128 383 xorl %eax, %edx /* test if ID bit is flipped */
cannam@128 384 jz .L_dont_use_mmx /* not flipped if zero */
cannam@128 385 xorl %eax, %eax
cannam@128 386 cpuid
cannam@128 387 cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */
cannam@128 388 jne .L_dont_use_mmx
cannam@128 389 cmpl $0x6c65746e, %ecx
cannam@128 390 jne .L_dont_use_mmx
cannam@128 391 cmpl $0x49656e69, %edx
cannam@128 392 jne .L_dont_use_mmx
cannam@128 393 movl $1, %eax
cannam@128 394 cpuid /* get cpu features */
cannam@128 395 shrl $8, %eax
cannam@128 396 andl $15, %eax
cannam@128 397 cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */
cannam@128 398 jne .L_dont_use_mmx
cannam@128 399 testl $0x800000, %edx /* test if MMX feature is set (bit 23) */
cannam@128 400 jnz .L_use_mmx
cannam@128 401 jmp .L_dont_use_mmx
cannam@128 402 .L_use_mmx:
cannam@128 403 movl $DO_USE_MMX, inflate_fast_use_mmx
cannam@128 404 jmp .L_check_mmx_pop
cannam@128 405 .L_dont_use_mmx:
cannam@128 406 movl $DONT_USE_MMX, inflate_fast_use_mmx
cannam@128 407 .L_check_mmx_pop:
cannam@128 408 popl %edx
cannam@128 409 popl %ecx
cannam@128 410 popl %ebx
cannam@128 411 popl %eax
cannam@128 412 jmp .L_check_mmx
cannam@128 413 #endif
cannam@128 414
cannam@128 415
cannam@128 416 /*** Non-MMX code ***/
cannam@128 417
cannam@128 418 #if defined ( NO_MMX ) || defined( RUN_TIME_MMX )
cannam@128 419
cannam@128 420 #define hold_r %ebp
cannam@128 421 #define bits_r %bl
cannam@128 422 #define bitslong_r %ebx
cannam@128 423
cannam@128 424 .align 32,0x90
cannam@128 425 .L_while_test:
cannam@128 426 /* while (in < last && out < end)
cannam@128 427 */
cannam@128 428 cmpl out_r, end(%esp)
cannam@128 429 jbe .L_break_loop /* if (out >= end) */
cannam@128 430
cannam@128 431 cmpl in_r, last(%esp)
cannam@128 432 jbe .L_break_loop
cannam@128 433
cannam@128 434 .L_do_loop:
cannam@128 435 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
cannam@128 436 *
cannam@128 437 * do {
cannam@128 438 * if (bits < 15) {
cannam@128 439 * hold |= *((unsigned short *)in)++ << bits;
cannam@128 440 * bits += 16
cannam@128 441 * }
cannam@128 442 * this = lcode[hold & lmask]
cannam@128 443 */
cannam@128 444 cmpb $15, bits_r
cannam@128 445 ja .L_get_length_code /* if (15 < bits) */
cannam@128 446
cannam@128 447 xorl %eax, %eax
cannam@128 448 lodsw /* al = *(ushort *)in++ */
cannam@128 449 movb bits_r, %cl /* cl = bits, needs it for shifting */
cannam@128 450 addb $16, bits_r /* bits += 16 */
cannam@128 451 shll %cl, %eax
cannam@128 452 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
cannam@128 453
cannam@128 454 .L_get_length_code:
cannam@128 455 movl lmask(%esp), %edx /* edx = lmask */
cannam@128 456 movl lcode(%esp), %ecx /* ecx = lcode */
cannam@128 457 andl hold_r, %edx /* edx &= hold */
cannam@128 458 movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */
cannam@128 459
cannam@128 460 .L_dolen:
cannam@128 461 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
cannam@128 462 *
cannam@128 463 * dolen:
cannam@128 464 * bits -= this.bits;
cannam@128 465 * hold >>= this.bits
cannam@128 466 */
cannam@128 467 movb %ah, %cl /* cl = this.bits */
cannam@128 468 subb %ah, bits_r /* bits -= this.bits */
cannam@128 469 shrl %cl, hold_r /* hold >>= this.bits */
cannam@128 470
cannam@128 471 /* check if op is a literal
cannam@128 472 * if (op == 0) {
cannam@128 473 * PUP(out) = this.val;
cannam@128 474 * }
cannam@128 475 */
cannam@128 476 testb %al, %al
cannam@128 477 jnz .L_test_for_length_base /* if (op != 0) 45.7% */
cannam@128 478
cannam@128 479 shrl $16, %eax /* output this.val char */
cannam@128 480 stosb
cannam@128 481 jmp .L_while_test
cannam@128 482
cannam@128 483 .L_test_for_length_base:
cannam@128 484 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len
cannam@128 485 *
cannam@128 486 * else if (op & 16) {
cannam@128 487 * len = this.val
cannam@128 488 * op &= 15
cannam@128 489 * if (op) {
cannam@128 490 * if (op > bits) {
cannam@128 491 * hold |= *((unsigned short *)in)++ << bits;
cannam@128 492 * bits += 16
cannam@128 493 * }
cannam@128 494 * len += hold & mask[op];
cannam@128 495 * bits -= op;
cannam@128 496 * hold >>= op;
cannam@128 497 * }
cannam@128 498 */
cannam@128 499 #define len_r %edx
cannam@128 500 movl %eax, len_r /* len = this */
cannam@128 501 shrl $16, len_r /* len = this.val */
cannam@128 502 movb %al, %cl
cannam@128 503
cannam@128 504 testb $16, %al
cannam@128 505 jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
cannam@128 506 andb $15, %cl /* op &= 15 */
cannam@128 507 jz .L_save_len /* if (!op) */
cannam@128 508 cmpb %cl, bits_r
cannam@128 509 jae .L_add_bits_to_len /* if (op <= bits) */
cannam@128 510
cannam@128 511 movb %cl, %ch /* stash op in ch, freeing cl */
cannam@128 512 xorl %eax, %eax
cannam@128 513 lodsw /* al = *(ushort *)in++ */
cannam@128 514 movb bits_r, %cl /* cl = bits, needs it for shifting */
cannam@128 515 addb $16, bits_r /* bits += 16 */
cannam@128 516 shll %cl, %eax
cannam@128 517 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
cannam@128 518 movb %ch, %cl /* move op back to ecx */
cannam@128 519
cannam@128 520 .L_add_bits_to_len:
cannam@128 521 movl $1, %eax
cannam@128 522 shll %cl, %eax
cannam@128 523 decl %eax
cannam@128 524 subb %cl, bits_r
cannam@128 525 andl hold_r, %eax /* eax &= hold */
cannam@128 526 shrl %cl, hold_r
cannam@128 527 addl %eax, len_r /* len += hold & mask[op] */
cannam@128 528
cannam@128 529 .L_save_len:
cannam@128 530 movl len_r, len(%esp) /* save len */
cannam@128 531 #undef len_r
cannam@128 532
cannam@128 533 .L_decode_distance:
cannam@128 534 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 535 *
cannam@128 536 * if (bits < 15) {
cannam@128 537 * hold |= *((unsigned short *)in)++ << bits;
cannam@128 538 * bits += 16
cannam@128 539 * }
cannam@128 540 * this = dcode[hold & dmask];
cannam@128 541 * dodist:
cannam@128 542 * bits -= this.bits;
cannam@128 543 * hold >>= this.bits;
cannam@128 544 * op = this.op;
cannam@128 545 */
cannam@128 546
cannam@128 547 cmpb $15, bits_r
cannam@128 548 ja .L_get_distance_code /* if (15 < bits) */
cannam@128 549
cannam@128 550 xorl %eax, %eax
cannam@128 551 lodsw /* al = *(ushort *)in++ */
cannam@128 552 movb bits_r, %cl /* cl = bits, needs it for shifting */
cannam@128 553 addb $16, bits_r /* bits += 16 */
cannam@128 554 shll %cl, %eax
cannam@128 555 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
cannam@128 556
cannam@128 557 .L_get_distance_code:
cannam@128 558 movl dmask(%esp), %edx /* edx = dmask */
cannam@128 559 movl dcode(%esp), %ecx /* ecx = dcode */
cannam@128 560 andl hold_r, %edx /* edx &= hold */
cannam@128 561 movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */
cannam@128 562
cannam@128 563 #define dist_r %edx
cannam@128 564 .L_dodist:
cannam@128 565 movl %eax, dist_r /* dist = this */
cannam@128 566 shrl $16, dist_r /* dist = this.val */
cannam@128 567 movb %ah, %cl
cannam@128 568 subb %ah, bits_r /* bits -= this.bits */
cannam@128 569 shrl %cl, hold_r /* hold >>= this.bits */
cannam@128 570
cannam@128 571 /* if (op & 16) {
cannam@128 572 * dist = this.val
cannam@128 573 * op &= 15
cannam@128 574 * if (op > bits) {
cannam@128 575 * hold |= *((unsigned short *)in)++ << bits;
cannam@128 576 * bits += 16
cannam@128 577 * }
cannam@128 578 * dist += hold & mask[op];
cannam@128 579 * bits -= op;
cannam@128 580 * hold >>= op;
cannam@128 581 */
cannam@128 582 movb %al, %cl /* cl = this.op */
cannam@128 583
cannam@128 584 testb $16, %al /* if ((op & 16) == 0) */
cannam@128 585 jz .L_test_for_second_level_dist
cannam@128 586 andb $15, %cl /* op &= 15 */
cannam@128 587 jz .L_check_dist_one
cannam@128 588 cmpb %cl, bits_r
cannam@128 589 jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */
cannam@128 590
cannam@128 591 movb %cl, %ch /* stash op in ch, freeing cl */
cannam@128 592 xorl %eax, %eax
cannam@128 593 lodsw /* al = *(ushort *)in++ */
cannam@128 594 movb bits_r, %cl /* cl = bits, needs it for shifting */
cannam@128 595 addb $16, bits_r /* bits += 16 */
cannam@128 596 shll %cl, %eax
cannam@128 597 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
cannam@128 598 movb %ch, %cl /* move op back to ecx */
cannam@128 599
cannam@128 600 .L_add_bits_to_dist:
cannam@128 601 movl $1, %eax
cannam@128 602 shll %cl, %eax
cannam@128 603 decl %eax /* (1 << op) - 1 */
cannam@128 604 subb %cl, bits_r
cannam@128 605 andl hold_r, %eax /* eax &= hold */
cannam@128 606 shrl %cl, hold_r
cannam@128 607 addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */
cannam@128 608 jmp .L_check_window
cannam@128 609
cannam@128 610 .L_check_window:
cannam@128 611 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 612 * %ecx = nbytes
cannam@128 613 *
cannam@128 614 * nbytes = out - beg;
cannam@128 615 * if (dist <= nbytes) {
cannam@128 616 * from = out - dist;
cannam@128 617 * do {
cannam@128 618 * PUP(out) = PUP(from);
cannam@128 619 * } while (--len > 0) {
cannam@128 620 * }
cannam@128 621 */
cannam@128 622
cannam@128 623 movl in_r, in(%esp) /* save in so from can use it's reg */
cannam@128 624 movl out_r, %eax
cannam@128 625 subl beg(%esp), %eax /* nbytes = out - beg */
cannam@128 626
cannam@128 627 cmpl dist_r, %eax
cannam@128 628 jb .L_clip_window /* if (dist > nbytes) 4.2% */
cannam@128 629
cannam@128 630 movl len(%esp), %ecx
cannam@128 631 movl out_r, from_r
cannam@128 632 subl dist_r, from_r /* from = out - dist */
cannam@128 633
cannam@128 634 subl $3, %ecx
cannam@128 635 movb (from_r), %al
cannam@128 636 movb %al, (out_r)
cannam@128 637 movb 1(from_r), %al
cannam@128 638 movb 2(from_r), %dl
cannam@128 639 addl $3, from_r
cannam@128 640 movb %al, 1(out_r)
cannam@128 641 movb %dl, 2(out_r)
cannam@128 642 addl $3, out_r
cannam@128 643 rep movsb
cannam@128 644
cannam@128 645 movl in(%esp), in_r /* move in back to %esi, toss from */
cannam@128 646 jmp .L_while_test
cannam@128 647
cannam@128 648 .align 16,0x90
cannam@128 649 .L_check_dist_one:
cannam@128 650 cmpl $1, dist_r
cannam@128 651 jne .L_check_window
cannam@128 652 cmpl out_r, beg(%esp)
cannam@128 653 je .L_check_window
cannam@128 654
cannam@128 655 decl out_r
cannam@128 656 movl len(%esp), %ecx
cannam@128 657 movb (out_r), %al
cannam@128 658 subl $3, %ecx
cannam@128 659
cannam@128 660 movb %al, 1(out_r)
cannam@128 661 movb %al, 2(out_r)
cannam@128 662 movb %al, 3(out_r)
cannam@128 663 addl $4, out_r
cannam@128 664 rep stosb
cannam@128 665
cannam@128 666 jmp .L_while_test
cannam@128 667
cannam@128 668 .align 16,0x90
cannam@128 669 .L_test_for_second_level_length:
cannam@128 670 /* else if ((op & 64) == 0) {
cannam@128 671 * this = lcode[this.val + (hold & mask[op])];
cannam@128 672 * }
cannam@128 673 */
cannam@128 674 testb $64, %al
cannam@128 675 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
cannam@128 676
cannam@128 677 movl $1, %eax
cannam@128 678 shll %cl, %eax
cannam@128 679 decl %eax
cannam@128 680 andl hold_r, %eax /* eax &= hold */
cannam@128 681 addl %edx, %eax /* eax += this.val */
cannam@128 682 movl lcode(%esp), %edx /* edx = lcode */
cannam@128 683 movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */
cannam@128 684 jmp .L_dolen
cannam@128 685
cannam@128 686 .align 16,0x90
cannam@128 687 .L_test_for_second_level_dist:
cannam@128 688 /* else if ((op & 64) == 0) {
cannam@128 689 * this = dcode[this.val + (hold & mask[op])];
cannam@128 690 * }
cannam@128 691 */
cannam@128 692 testb $64, %al
cannam@128 693 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
cannam@128 694
cannam@128 695 movl $1, %eax
cannam@128 696 shll %cl, %eax
cannam@128 697 decl %eax
cannam@128 698 andl hold_r, %eax /* eax &= hold */
cannam@128 699 addl %edx, %eax /* eax += this.val */
cannam@128 700 movl dcode(%esp), %edx /* edx = dcode */
cannam@128 701 movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */
cannam@128 702 jmp .L_dodist
cannam@128 703
cannam@128 704 .align 16,0x90
cannam@128 705 .L_clip_window:
cannam@128 706 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 707 * %ecx = nbytes
cannam@128 708 *
cannam@128 709 * else {
cannam@128 710 * if (dist > wsize) {
cannam@128 711 * invalid distance
cannam@128 712 * }
cannam@128 713 * from = window;
cannam@128 714 * nbytes = dist - nbytes;
cannam@128 715 * if (write == 0) {
cannam@128 716 * from += wsize - nbytes;
cannam@128 717 */
cannam@128 718 #define nbytes_r %ecx
cannam@128 719 movl %eax, nbytes_r
cannam@128 720 movl wsize(%esp), %eax /* prepare for dist compare */
cannam@128 721 negl nbytes_r /* nbytes = -nbytes */
cannam@128 722 movl window(%esp), from_r /* from = window */
cannam@128 723
cannam@128 724 cmpl dist_r, %eax
cannam@128 725 jb .L_invalid_distance_too_far /* if (dist > wsize) */
cannam@128 726
cannam@128 727 addl dist_r, nbytes_r /* nbytes = dist - nbytes */
cannam@128 728 cmpl $0, write(%esp)
cannam@128 729 jne .L_wrap_around_window /* if (write != 0) */
cannam@128 730
cannam@128 731 subl nbytes_r, %eax
cannam@128 732 addl %eax, from_r /* from += wsize - nbytes */
cannam@128 733
cannam@128 734 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 735 * %ecx = nbytes, %eax = len
cannam@128 736 *
cannam@128 737 * if (nbytes < len) {
cannam@128 738 * len -= nbytes;
cannam@128 739 * do {
cannam@128 740 * PUP(out) = PUP(from);
cannam@128 741 * } while (--nbytes);
cannam@128 742 * from = out - dist;
cannam@128 743 * }
cannam@128 744 * }
cannam@128 745 */
cannam@128 746 #define len_r %eax
cannam@128 747 movl len(%esp), len_r
cannam@128 748 cmpl nbytes_r, len_r
cannam@128 749 jbe .L_do_copy1 /* if (nbytes >= len) */
cannam@128 750
cannam@128 751 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 752 rep movsb
cannam@128 753 movl out_r, from_r
cannam@128 754 subl dist_r, from_r /* from = out - dist */
cannam@128 755 jmp .L_do_copy1
cannam@128 756
cannam@128 757 cmpl nbytes_r, len_r
cannam@128 758 jbe .L_do_copy1 /* if (nbytes >= len) */
cannam@128 759
cannam@128 760 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 761 rep movsb
cannam@128 762 movl out_r, from_r
cannam@128 763 subl dist_r, from_r /* from = out - dist */
cannam@128 764 jmp .L_do_copy1
cannam@128 765
cannam@128 766 .L_wrap_around_window:
cannam@128 767 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 768 * %ecx = nbytes, %eax = write, %eax = len
cannam@128 769 *
cannam@128 770 * else if (write < nbytes) {
cannam@128 771 * from += wsize + write - nbytes;
cannam@128 772 * nbytes -= write;
cannam@128 773 * if (nbytes < len) {
cannam@128 774 * len -= nbytes;
cannam@128 775 * do {
cannam@128 776 * PUP(out) = PUP(from);
cannam@128 777 * } while (--nbytes);
cannam@128 778 * from = window;
cannam@128 779 * nbytes = write;
cannam@128 780 * if (nbytes < len) {
cannam@128 781 * len -= nbytes;
cannam@128 782 * do {
cannam@128 783 * PUP(out) = PUP(from);
cannam@128 784 * } while(--nbytes);
cannam@128 785 * from = out - dist;
cannam@128 786 * }
cannam@128 787 * }
cannam@128 788 * }
cannam@128 789 */
cannam@128 790 #define write_r %eax
cannam@128 791 movl write(%esp), write_r
cannam@128 792 cmpl write_r, nbytes_r
cannam@128 793 jbe .L_contiguous_in_window /* if (write >= nbytes) */
cannam@128 794
cannam@128 795 addl wsize(%esp), from_r
cannam@128 796 addl write_r, from_r
cannam@128 797 subl nbytes_r, from_r /* from += wsize + write - nbytes */
cannam@128 798 subl write_r, nbytes_r /* nbytes -= write */
cannam@128 799 #undef write_r
cannam@128 800
cannam@128 801 movl len(%esp), len_r
cannam@128 802 cmpl nbytes_r, len_r
cannam@128 803 jbe .L_do_copy1 /* if (nbytes >= len) */
cannam@128 804
cannam@128 805 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 806 rep movsb
cannam@128 807 movl window(%esp), from_r /* from = window */
cannam@128 808 movl write(%esp), nbytes_r /* nbytes = write */
cannam@128 809 cmpl nbytes_r, len_r
cannam@128 810 jbe .L_do_copy1 /* if (nbytes >= len) */
cannam@128 811
cannam@128 812 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 813 rep movsb
cannam@128 814 movl out_r, from_r
cannam@128 815 subl dist_r, from_r /* from = out - dist */
cannam@128 816 jmp .L_do_copy1
cannam@128 817
cannam@128 818 .L_contiguous_in_window:
cannam@128 819 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
cannam@128 820 * %ecx = nbytes, %eax = write, %eax = len
cannam@128 821 *
cannam@128 822 * else {
cannam@128 823 * from += write - nbytes;
cannam@128 824 * if (nbytes < len) {
cannam@128 825 * len -= nbytes;
cannam@128 826 * do {
cannam@128 827 * PUP(out) = PUP(from);
cannam@128 828 * } while (--nbytes);
cannam@128 829 * from = out - dist;
cannam@128 830 * }
cannam@128 831 * }
cannam@128 832 */
cannam@128 833 #define write_r %eax
cannam@128 834 addl write_r, from_r
cannam@128 835 subl nbytes_r, from_r /* from += write - nbytes */
cannam@128 836 #undef write_r
cannam@128 837
cannam@128 838 movl len(%esp), len_r
cannam@128 839 cmpl nbytes_r, len_r
cannam@128 840 jbe .L_do_copy1 /* if (nbytes >= len) */
cannam@128 841
cannam@128 842 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 843 rep movsb
cannam@128 844 movl out_r, from_r
cannam@128 845 subl dist_r, from_r /* from = out - dist */
cannam@128 846
cannam@128 847 .L_do_copy1:
cannam@128 848 /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out
cannam@128 849 * %eax = len
cannam@128 850 *
cannam@128 851 * while (len > 0) {
cannam@128 852 * PUP(out) = PUP(from);
cannam@128 853 * len--;
cannam@128 854 * }
cannam@128 855 * }
cannam@128 856 * } while (in < last && out < end);
cannam@128 857 */
cannam@128 858 #undef nbytes_r
cannam@128 859 #define in_r %esi
cannam@128 860 movl len_r, %ecx
cannam@128 861 rep movsb
cannam@128 862
cannam@128 863 movl in(%esp), in_r /* move in back to %esi, toss from */
cannam@128 864 jmp .L_while_test
cannam@128 865
cannam@128 866 #undef len_r
cannam@128 867 #undef dist_r
cannam@128 868
cannam@128 869 #endif /* NO_MMX || RUN_TIME_MMX */
cannam@128 870
cannam@128 871
cannam@128 872 /*** MMX code ***/
cannam@128 873
cannam@128 874 #if defined( USE_MMX ) || defined( RUN_TIME_MMX )
cannam@128 875
cannam@128 876 .align 32,0x90
cannam@128 877 .L_init_mmx:
cannam@128 878 emms
cannam@128 879
cannam@128 880 #undef bits_r
cannam@128 881 #undef bitslong_r
cannam@128 882 #define bitslong_r %ebp
cannam@128 883 #define hold_mm %mm0
cannam@128 884 movd %ebp, hold_mm
cannam@128 885 movl %ebx, bitslong_r
cannam@128 886
cannam@128 887 #define used_mm %mm1
cannam@128 888 #define dmask2_mm %mm2
cannam@128 889 #define lmask2_mm %mm3
cannam@128 890 #define lmask_mm %mm4
cannam@128 891 #define dmask_mm %mm5
cannam@128 892 #define tmp_mm %mm6
cannam@128 893
cannam@128 894 movd lmask(%esp), lmask_mm
cannam@128 895 movq lmask_mm, lmask2_mm
cannam@128 896 movd dmask(%esp), dmask_mm
cannam@128 897 movq dmask_mm, dmask2_mm
cannam@128 898 pxor used_mm, used_mm
cannam@128 899 movl lcode(%esp), %ebx /* ebx = lcode */
cannam@128 900 jmp .L_do_loop_mmx
cannam@128 901
cannam@128 902 .align 32,0x90
cannam@128 903 .L_while_test_mmx:
cannam@128 904 /* while (in < last && out < end)
cannam@128 905 */
cannam@128 906 cmpl out_r, end(%esp)
cannam@128 907 jbe .L_break_loop /* if (out >= end) */
cannam@128 908
cannam@128 909 cmpl in_r, last(%esp)
cannam@128 910 jbe .L_break_loop
cannam@128 911
cannam@128 912 .L_do_loop_mmx:
cannam@128 913 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 914
cannam@128 915 cmpl $32, bitslong_r
cannam@128 916 ja .L_get_length_code_mmx /* if (32 < bits) */
cannam@128 917
cannam@128 918 movd bitslong_r, tmp_mm
cannam@128 919 movd (in_r), %mm7
cannam@128 920 addl $4, in_r
cannam@128 921 psllq tmp_mm, %mm7
cannam@128 922 addl $32, bitslong_r
cannam@128 923 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
cannam@128 924
cannam@128 925 .L_get_length_code_mmx:
cannam@128 926 pand hold_mm, lmask_mm
cannam@128 927 movd lmask_mm, %eax
cannam@128 928 movq lmask2_mm, lmask_mm
cannam@128 929 movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */
cannam@128 930
cannam@128 931 .L_dolen_mmx:
cannam@128 932 movzbl %ah, %ecx /* ecx = this.bits */
cannam@128 933 movd %ecx, used_mm
cannam@128 934 subl %ecx, bitslong_r /* bits -= this.bits */
cannam@128 935
cannam@128 936 testb %al, %al
cannam@128 937 jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */
cannam@128 938
cannam@128 939 shrl $16, %eax /* output this.val char */
cannam@128 940 stosb
cannam@128 941 jmp .L_while_test_mmx
cannam@128 942
cannam@128 943 .L_test_for_length_base_mmx:
cannam@128 944 #define len_r %edx
cannam@128 945 movl %eax, len_r /* len = this */
cannam@128 946 shrl $16, len_r /* len = this.val */
cannam@128 947
cannam@128 948 testb $16, %al
cannam@128 949 jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */
cannam@128 950 andl $15, %eax /* op &= 15 */
cannam@128 951 jz .L_decode_distance_mmx /* if (!op) */
cannam@128 952
cannam@128 953 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 954 movd %eax, used_mm
cannam@128 955 movd hold_mm, %ecx
cannam@128 956 subl %eax, bitslong_r
cannam@128 957 andl .L_mask(,%eax,4), %ecx
cannam@128 958 addl %ecx, len_r /* len += hold & mask[op] */
cannam@128 959
cannam@128 960 .L_decode_distance_mmx:
cannam@128 961 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 962
cannam@128 963 cmpl $32, bitslong_r
cannam@128 964 ja .L_get_dist_code_mmx /* if (32 < bits) */
cannam@128 965
cannam@128 966 movd bitslong_r, tmp_mm
cannam@128 967 movd (in_r), %mm7
cannam@128 968 addl $4, in_r
cannam@128 969 psllq tmp_mm, %mm7
cannam@128 970 addl $32, bitslong_r
cannam@128 971 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
cannam@128 972
cannam@128 973 .L_get_dist_code_mmx:
cannam@128 974 movl dcode(%esp), %ebx /* ebx = dcode */
cannam@128 975 pand hold_mm, dmask_mm
cannam@128 976 movd dmask_mm, %eax
cannam@128 977 movq dmask2_mm, dmask_mm
cannam@128 978 movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */
cannam@128 979
cannam@128 980 .L_dodist_mmx:
cannam@128 981 #define dist_r %ebx
cannam@128 982 movzbl %ah, %ecx /* ecx = this.bits */
cannam@128 983 movl %eax, dist_r
cannam@128 984 shrl $16, dist_r /* dist = this.val */
cannam@128 985 subl %ecx, bitslong_r /* bits -= this.bits */
cannam@128 986 movd %ecx, used_mm
cannam@128 987
cannam@128 988 testb $16, %al /* if ((op & 16) == 0) */
cannam@128 989 jz .L_test_for_second_level_dist_mmx
cannam@128 990 andl $15, %eax /* op &= 15 */
cannam@128 991 jz .L_check_dist_one_mmx
cannam@128 992
cannam@128 993 .L_add_bits_to_dist_mmx:
cannam@128 994 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 995 movd %eax, used_mm /* save bit length of current op */
cannam@128 996 movd hold_mm, %ecx /* get the next bits on input stream */
cannam@128 997 subl %eax, bitslong_r /* bits -= op bits */
cannam@128 998 andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */
cannam@128 999 addl %ecx, dist_r /* dist += hold & mask[op] */
cannam@128 1000
cannam@128 1001 .L_check_window_mmx:
cannam@128 1002 movl in_r, in(%esp) /* save in so from can use it's reg */
cannam@128 1003 movl out_r, %eax
cannam@128 1004 subl beg(%esp), %eax /* nbytes = out - beg */
cannam@128 1005
cannam@128 1006 cmpl dist_r, %eax
cannam@128 1007 jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */
cannam@128 1008
cannam@128 1009 movl len_r, %ecx
cannam@128 1010 movl out_r, from_r
cannam@128 1011 subl dist_r, from_r /* from = out - dist */
cannam@128 1012
cannam@128 1013 subl $3, %ecx
cannam@128 1014 movb (from_r), %al
cannam@128 1015 movb %al, (out_r)
cannam@128 1016 movb 1(from_r), %al
cannam@128 1017 movb 2(from_r), %dl
cannam@128 1018 addl $3, from_r
cannam@128 1019 movb %al, 1(out_r)
cannam@128 1020 movb %dl, 2(out_r)
cannam@128 1021 addl $3, out_r
cannam@128 1022 rep movsb
cannam@128 1023
cannam@128 1024 movl in(%esp), in_r /* move in back to %esi, toss from */
cannam@128 1025 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
cannam@128 1026 jmp .L_while_test_mmx
cannam@128 1027
cannam@128 1028 .align 16,0x90
cannam@128 1029 .L_check_dist_one_mmx:
cannam@128 1030 cmpl $1, dist_r
cannam@128 1031 jne .L_check_window_mmx
cannam@128 1032 cmpl out_r, beg(%esp)
cannam@128 1033 je .L_check_window_mmx
cannam@128 1034
cannam@128 1035 decl out_r
cannam@128 1036 movl len_r, %ecx
cannam@128 1037 movb (out_r), %al
cannam@128 1038 subl $3, %ecx
cannam@128 1039
cannam@128 1040 movb %al, 1(out_r)
cannam@128 1041 movb %al, 2(out_r)
cannam@128 1042 movb %al, 3(out_r)
cannam@128 1043 addl $4, out_r
cannam@128 1044 rep stosb
cannam@128 1045
cannam@128 1046 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
cannam@128 1047 jmp .L_while_test_mmx
cannam@128 1048
cannam@128 1049 .align 16,0x90
cannam@128 1050 .L_test_for_second_level_length_mmx:
cannam@128 1051 testb $64, %al
cannam@128 1052 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
cannam@128 1053
cannam@128 1054 andl $15, %eax
cannam@128 1055 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 1056 movd hold_mm, %ecx
cannam@128 1057 andl .L_mask(,%eax,4), %ecx
cannam@128 1058 addl len_r, %ecx
cannam@128 1059 movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */
cannam@128 1060 jmp .L_dolen_mmx
cannam@128 1061
cannam@128 1062 .align 16,0x90
cannam@128 1063 .L_test_for_second_level_dist_mmx:
cannam@128 1064 testb $64, %al
cannam@128 1065 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
cannam@128 1066
cannam@128 1067 andl $15, %eax
cannam@128 1068 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 1069 movd hold_mm, %ecx
cannam@128 1070 andl .L_mask(,%eax,4), %ecx
cannam@128 1071 movl dcode(%esp), %eax /* ecx = dcode */
cannam@128 1072 addl dist_r, %ecx
cannam@128 1073 movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */
cannam@128 1074 jmp .L_dodist_mmx
cannam@128 1075
cannam@128 1076 .align 16,0x90
cannam@128 1077 .L_clip_window_mmx:
cannam@128 1078 #define nbytes_r %ecx
cannam@128 1079 movl %eax, nbytes_r
cannam@128 1080 movl wsize(%esp), %eax /* prepare for dist compare */
cannam@128 1081 negl nbytes_r /* nbytes = -nbytes */
cannam@128 1082 movl window(%esp), from_r /* from = window */
cannam@128 1083
cannam@128 1084 cmpl dist_r, %eax
cannam@128 1085 jb .L_invalid_distance_too_far /* if (dist > wsize) */
cannam@128 1086
cannam@128 1087 addl dist_r, nbytes_r /* nbytes = dist - nbytes */
cannam@128 1088 cmpl $0, write(%esp)
cannam@128 1089 jne .L_wrap_around_window_mmx /* if (write != 0) */
cannam@128 1090
cannam@128 1091 subl nbytes_r, %eax
cannam@128 1092 addl %eax, from_r /* from += wsize - nbytes */
cannam@128 1093
cannam@128 1094 cmpl nbytes_r, len_r
cannam@128 1095 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
cannam@128 1096
cannam@128 1097 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 1098 rep movsb
cannam@128 1099 movl out_r, from_r
cannam@128 1100 subl dist_r, from_r /* from = out - dist */
cannam@128 1101 jmp .L_do_copy1_mmx
cannam@128 1102
cannam@128 1103 cmpl nbytes_r, len_r
cannam@128 1104 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
cannam@128 1105
cannam@128 1106 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 1107 rep movsb
cannam@128 1108 movl out_r, from_r
cannam@128 1109 subl dist_r, from_r /* from = out - dist */
cannam@128 1110 jmp .L_do_copy1_mmx
cannam@128 1111
cannam@128 1112 .L_wrap_around_window_mmx:
cannam@128 1113 #define write_r %eax
cannam@128 1114 movl write(%esp), write_r
cannam@128 1115 cmpl write_r, nbytes_r
cannam@128 1116 jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */
cannam@128 1117
cannam@128 1118 addl wsize(%esp), from_r
cannam@128 1119 addl write_r, from_r
cannam@128 1120 subl nbytes_r, from_r /* from += wsize + write - nbytes */
cannam@128 1121 subl write_r, nbytes_r /* nbytes -= write */
cannam@128 1122 #undef write_r
cannam@128 1123
cannam@128 1124 cmpl nbytes_r, len_r
cannam@128 1125 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
cannam@128 1126
cannam@128 1127 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 1128 rep movsb
cannam@128 1129 movl window(%esp), from_r /* from = window */
cannam@128 1130 movl write(%esp), nbytes_r /* nbytes = write */
cannam@128 1131 cmpl nbytes_r, len_r
cannam@128 1132 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
cannam@128 1133
cannam@128 1134 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 1135 rep movsb
cannam@128 1136 movl out_r, from_r
cannam@128 1137 subl dist_r, from_r /* from = out - dist */
cannam@128 1138 jmp .L_do_copy1_mmx
cannam@128 1139
cannam@128 1140 .L_contiguous_in_window_mmx:
cannam@128 1141 #define write_r %eax
cannam@128 1142 addl write_r, from_r
cannam@128 1143 subl nbytes_r, from_r /* from += write - nbytes */
cannam@128 1144 #undef write_r
cannam@128 1145
cannam@128 1146 cmpl nbytes_r, len_r
cannam@128 1147 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
cannam@128 1148
cannam@128 1149 subl nbytes_r, len_r /* len -= nbytes */
cannam@128 1150 rep movsb
cannam@128 1151 movl out_r, from_r
cannam@128 1152 subl dist_r, from_r /* from = out - dist */
cannam@128 1153
cannam@128 1154 .L_do_copy1_mmx:
cannam@128 1155 #undef nbytes_r
cannam@128 1156 #define in_r %esi
cannam@128 1157 movl len_r, %ecx
cannam@128 1158 rep movsb
cannam@128 1159
cannam@128 1160 movl in(%esp), in_r /* move in back to %esi, toss from */
cannam@128 1161 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
cannam@128 1162 jmp .L_while_test_mmx
cannam@128 1163
cannam@128 1164 #undef hold_r
cannam@128 1165 #undef bitslong_r
cannam@128 1166
cannam@128 1167 #endif /* USE_MMX || RUN_TIME_MMX */
cannam@128 1168
cannam@128 1169
cannam@128 1170 /*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/
cannam@128 1171
cannam@128 1172 .L_invalid_distance_code:
cannam@128 1173 /* else {
cannam@128 1174 * strm->msg = "invalid distance code";
cannam@128 1175 * state->mode = BAD;
cannam@128 1176 * }
cannam@128 1177 */
cannam@128 1178 movl $.L_invalid_distance_code_msg, %ecx
cannam@128 1179 movl $INFLATE_MODE_BAD, %edx
cannam@128 1180 jmp .L_update_stream_state
cannam@128 1181
cannam@128 1182 .L_test_for_end_of_block:
cannam@128 1183 /* else if (op & 32) {
cannam@128 1184 * state->mode = TYPE;
cannam@128 1185 * break;
cannam@128 1186 * }
cannam@128 1187 */
cannam@128 1188 testb $32, %al
cannam@128 1189 jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */
cannam@128 1190
cannam@128 1191 movl $0, %ecx
cannam@128 1192 movl $INFLATE_MODE_TYPE, %edx
cannam@128 1193 jmp .L_update_stream_state
cannam@128 1194
cannam@128 1195 .L_invalid_literal_length_code:
cannam@128 1196 /* else {
cannam@128 1197 * strm->msg = "invalid literal/length code";
cannam@128 1198 * state->mode = BAD;
cannam@128 1199 * }
cannam@128 1200 */
cannam@128 1201 movl $.L_invalid_literal_length_code_msg, %ecx
cannam@128 1202 movl $INFLATE_MODE_BAD, %edx
cannam@128 1203 jmp .L_update_stream_state
cannam@128 1204
cannam@128 1205 .L_invalid_distance_too_far:
cannam@128 1206 /* strm->msg = "invalid distance too far back";
cannam@128 1207 * state->mode = BAD;
cannam@128 1208 */
cannam@128 1209 movl in(%esp), in_r /* from_r has in's reg, put in back */
cannam@128 1210 movl $.L_invalid_distance_too_far_msg, %ecx
cannam@128 1211 movl $INFLATE_MODE_BAD, %edx
cannam@128 1212 jmp .L_update_stream_state
cannam@128 1213
cannam@128 1214 .L_update_stream_state:
cannam@128 1215 /* set strm->msg = %ecx, strm->state->mode = %edx */
cannam@128 1216 movl strm_sp(%esp), %eax
cannam@128 1217 testl %ecx, %ecx /* if (msg != NULL) */
cannam@128 1218 jz .L_skip_msg
cannam@128 1219 movl %ecx, msg_strm(%eax) /* strm->msg = msg */
cannam@128 1220 .L_skip_msg:
cannam@128 1221 movl state_strm(%eax), %eax /* state = strm->state */
cannam@128 1222 movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */
cannam@128 1223 jmp .L_break_loop
cannam@128 1224
cannam@128 1225 .align 32,0x90
cannam@128 1226 .L_break_loop:
cannam@128 1227
cannam@128 1228 /*
cannam@128 1229 * Regs:
cannam@128 1230 *
cannam@128 1231 * bits = %ebp when mmx, and in %ebx when non-mmx
cannam@128 1232 * hold = %hold_mm when mmx, and in %ebp when non-mmx
cannam@128 1233 * in = %esi
cannam@128 1234 * out = %edi
cannam@128 1235 */
cannam@128 1236
cannam@128 1237 #if defined( USE_MMX ) || defined( RUN_TIME_MMX )
cannam@128 1238
cannam@128 1239 #if defined( RUN_TIME_MMX )
cannam@128 1240
cannam@128 1241 cmpl $DO_USE_MMX, inflate_fast_use_mmx
cannam@128 1242 jne .L_update_next_in
cannam@128 1243
cannam@128 1244 #endif /* RUN_TIME_MMX */
cannam@128 1245
cannam@128 1246 movl %ebp, %ebx
cannam@128 1247
cannam@128 1248 .L_update_next_in:
cannam@128 1249
cannam@128 1250 #endif
cannam@128 1251
cannam@128 1252 #define strm_r %eax
cannam@128 1253 #define state_r %edx
cannam@128 1254
cannam@128 1255 /* len = bits >> 3;
cannam@128 1256 * in -= len;
cannam@128 1257 * bits -= len << 3;
cannam@128 1258 * hold &= (1U << bits) - 1;
cannam@128 1259 * state->hold = hold;
cannam@128 1260 * state->bits = bits;
cannam@128 1261 * strm->next_in = in;
cannam@128 1262 * strm->next_out = out;
cannam@128 1263 */
cannam@128 1264 movl strm_sp(%esp), strm_r
cannam@128 1265 movl %ebx, %ecx
cannam@128 1266 movl state_strm(strm_r), state_r
cannam@128 1267 shrl $3, %ecx
cannam@128 1268 subl %ecx, in_r
cannam@128 1269 shll $3, %ecx
cannam@128 1270 subl %ecx, %ebx
cannam@128 1271 movl out_r, next_out_strm(strm_r)
cannam@128 1272 movl %ebx, bits_state(state_r)
cannam@128 1273 movl %ebx, %ecx
cannam@128 1274
cannam@128 1275 leal buf(%esp), %ebx
cannam@128 1276 cmpl %ebx, last(%esp)
cannam@128 1277 jne .L_buf_not_used /* if buf != last */
cannam@128 1278
cannam@128 1279 subl %ebx, in_r /* in -= buf */
cannam@128 1280 movl next_in_strm(strm_r), %ebx
cannam@128 1281 movl %ebx, last(%esp) /* last = strm->next_in */
cannam@128 1282 addl %ebx, in_r /* in += strm->next_in */
cannam@128 1283 movl avail_in_strm(strm_r), %ebx
cannam@128 1284 subl $11, %ebx
cannam@128 1285 addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */
cannam@128 1286
cannam@128 1287 .L_buf_not_used:
cannam@128 1288 movl in_r, next_in_strm(strm_r)
cannam@128 1289
cannam@128 1290 movl $1, %ebx
cannam@128 1291 shll %cl, %ebx
cannam@128 1292 decl %ebx
cannam@128 1293
cannam@128 1294 #if defined( USE_MMX ) || defined( RUN_TIME_MMX )
cannam@128 1295
cannam@128 1296 #if defined( RUN_TIME_MMX )
cannam@128 1297
cannam@128 1298 cmpl $DO_USE_MMX, inflate_fast_use_mmx
cannam@128 1299 jne .L_update_hold
cannam@128 1300
cannam@128 1301 #endif /* RUN_TIME_MMX */
cannam@128 1302
cannam@128 1303 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
cannam@128 1304 movd hold_mm, %ebp
cannam@128 1305
cannam@128 1306 emms
cannam@128 1307
cannam@128 1308 .L_update_hold:
cannam@128 1309
cannam@128 1310 #endif /* USE_MMX || RUN_TIME_MMX */
cannam@128 1311
cannam@128 1312 andl %ebx, %ebp
cannam@128 1313 movl %ebp, hold_state(state_r)
cannam@128 1314
cannam@128 1315 #define last_r %ebx
cannam@128 1316
cannam@128 1317 /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */
cannam@128 1318 movl last(%esp), last_r
cannam@128 1319 cmpl in_r, last_r
cannam@128 1320 jbe .L_last_is_smaller /* if (in >= last) */
cannam@128 1321
cannam@128 1322 subl in_r, last_r /* last -= in */
cannam@128 1323 addl $11, last_r /* last += 11 */
cannam@128 1324 movl last_r, avail_in_strm(strm_r)
cannam@128 1325 jmp .L_fixup_out
cannam@128 1326 .L_last_is_smaller:
cannam@128 1327 subl last_r, in_r /* in -= last */
cannam@128 1328 negl in_r /* in = -in */
cannam@128 1329 addl $11, in_r /* in += 11 */
cannam@128 1330 movl in_r, avail_in_strm(strm_r)
cannam@128 1331
cannam@128 1332 #undef last_r
cannam@128 1333 #define end_r %ebx
cannam@128 1334
cannam@128 1335 .L_fixup_out:
cannam@128 1336 /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/
cannam@128 1337 movl end(%esp), end_r
cannam@128 1338 cmpl out_r, end_r
cannam@128 1339 jbe .L_end_is_smaller /* if (out >= end) */
cannam@128 1340
cannam@128 1341 subl out_r, end_r /* end -= out */
cannam@128 1342 addl $257, end_r /* end += 257 */
cannam@128 1343 movl end_r, avail_out_strm(strm_r)
cannam@128 1344 jmp .L_done
cannam@128 1345 .L_end_is_smaller:
cannam@128 1346 subl end_r, out_r /* out -= end */
cannam@128 1347 negl out_r /* out = -out */
cannam@128 1348 addl $257, out_r /* out += 257 */
cannam@128 1349 movl out_r, avail_out_strm(strm_r)
cannam@128 1350
cannam@128 1351 #undef end_r
cannam@128 1352 #undef strm_r
cannam@128 1353 #undef state_r
cannam@128 1354
cannam@128 1355 .L_done:
cannam@128 1356 addl $local_var_size, %esp
cannam@128 1357 popf
cannam@128 1358 popl %ebx
cannam@128 1359 popl %ebp
cannam@128 1360 popl %esi
cannam@128 1361 popl %edi
cannam@128 1362 ret
cannam@128 1363
cannam@128 1364 #if defined( GAS_ELF )
cannam@128 1365 /* elf info */
cannam@128 1366 .type inflate_fast,@function
cannam@128 1367 .size inflate_fast,.-inflate_fast
cannam@128 1368 #endif