annotate src/zlib-1.2.7/contrib/inflate86/inffast.S @ 148:b4bfdf10c4b3

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