annotate src/zlib-1.2.8/contrib/inflate86/inffast.S @ 56:af97cad61ff0

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