annotate src/zlib-1.2.8/contrib/masmx64/inffas8664.c @ 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 5b4145a0d408
children
rev   line source
cannam@128 1 /* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding
cannam@128 2 * version for AMD64 on Windows using Microsoft C compiler
cannam@128 3 *
cannam@128 4 * Copyright (C) 1995-2003 Mark Adler
cannam@128 5 * For conditions of distribution and use, see copyright notice in zlib.h
cannam@128 6 *
cannam@128 7 * Copyright (C) 2003 Chris Anderson <christop@charm.net>
cannam@128 8 * Please use the copyright conditions above.
cannam@128 9 *
cannam@128 10 * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant
cannam@128 11 *
cannam@128 12 * inffas8664.c call function inffas8664fnc in inffasx64.asm
cannam@128 13 * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c
cannam@128 14 *
cannam@128 15 * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also
cannam@128 16 * slightly quicker on x86 systems because, instead of using rep movsb to copy
cannam@128 17 * data, it uses rep movsw, which moves data in 2-byte chunks instead of single
cannam@128 18 * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates
cannam@128 19 * from http://fedora.linux.duke.edu/fc1_x86_64
cannam@128 20 * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with
cannam@128 21 * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version,
cannam@128 22 * when decompressing mozilla-source-1.3.tar.gz.
cannam@128 23 *
cannam@128 24 * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
cannam@128 25 * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at
cannam@128 26 * the moment. I have successfully compiled and tested this code with gcc2.96,
cannam@128 27 * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S
cannam@128 28 * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
cannam@128 29 * enabled. I will attempt to merge the MMX code into this version. Newer
cannam@128 30 * versions of this and inffast.S can be found at
cannam@128 31 * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
cannam@128 32 *
cannam@128 33 */
cannam@128 34
cannam@128 35 #include <stdio.h>
cannam@128 36 #include "zutil.h"
cannam@128 37 #include "inftrees.h"
cannam@128 38 #include "inflate.h"
cannam@128 39 #include "inffast.h"
cannam@128 40
cannam@128 41 /* Mark Adler's comments from inffast.c: */
cannam@128 42
cannam@128 43 /*
cannam@128 44 Decode literal, length, and distance codes and write out the resulting
cannam@128 45 literal and match bytes until either not enough input or output is
cannam@128 46 available, an end-of-block is encountered, or a data error is encountered.
cannam@128 47 When large enough input and output buffers are supplied to inflate(), for
cannam@128 48 example, a 16K input buffer and a 64K output buffer, more than 95% of the
cannam@128 49 inflate execution time is spent in this routine.
cannam@128 50
cannam@128 51 Entry assumptions:
cannam@128 52
cannam@128 53 state->mode == LEN
cannam@128 54 strm->avail_in >= 6
cannam@128 55 strm->avail_out >= 258
cannam@128 56 start >= strm->avail_out
cannam@128 57 state->bits < 8
cannam@128 58
cannam@128 59 On return, state->mode is one of:
cannam@128 60
cannam@128 61 LEN -- ran out of enough output space or enough available input
cannam@128 62 TYPE -- reached end of block code, inflate() to interpret next block
cannam@128 63 BAD -- error in block data
cannam@128 64
cannam@128 65 Notes:
cannam@128 66
cannam@128 67 - The maximum input bits used by a length/distance pair is 15 bits for the
cannam@128 68 length code, 5 bits for the length extra, 15 bits for the distance code,
cannam@128 69 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
cannam@128 70 Therefore if strm->avail_in >= 6, then there is enough input to avoid
cannam@128 71 checking for available input while decoding.
cannam@128 72
cannam@128 73 - The maximum bytes that a single length/distance pair can output is 258
cannam@128 74 bytes, which is the maximum length that can be coded. inflate_fast()
cannam@128 75 requires strm->avail_out >= 258 for each loop to avoid checking for
cannam@128 76 output space.
cannam@128 77 */
cannam@128 78
cannam@128 79
cannam@128 80
cannam@128 81 typedef struct inffast_ar {
cannam@128 82 /* 64 32 x86 x86_64 */
cannam@128 83 /* ar offset register */
cannam@128 84 /* 0 0 */ void *esp; /* esp save */
cannam@128 85 /* 8 4 */ void *ebp; /* ebp save */
cannam@128 86 /* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */
cannam@128 87 /* 24 12 */ unsigned char FAR *last; /* r9 while in < last */
cannam@128 88 /* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */
cannam@128 89 /* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */
cannam@128 90 /* 48 24 */ unsigned char FAR *end; /* r10 while out < end */
cannam@128 91 /* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */
cannam@128 92 /* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */
cannam@128 93 /* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */
cannam@128 94 /* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */
cannam@128 95 /* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */
cannam@128 96 /* 92 48 */ unsigned wsize; /* window size */
cannam@128 97 /* 96 52 */ unsigned write; /* window write index */
cannam@128 98 /*100 56 */ unsigned lmask; /* r12 mask for lcode */
cannam@128 99 /*104 60 */ unsigned dmask; /* r13 mask for dcode */
cannam@128 100 /*108 64 */ unsigned len; /* r14 match length */
cannam@128 101 /*112 68 */ unsigned dist; /* r15 match distance */
cannam@128 102 /*116 72 */ unsigned status; /* set when state chng*/
cannam@128 103 } type_ar;
cannam@128 104 #ifdef ASMINF
cannam@128 105
cannam@128 106 void inflate_fast(strm, start)
cannam@128 107 z_streamp strm;
cannam@128 108 unsigned start; /* inflate()'s starting value for strm->avail_out */
cannam@128 109 {
cannam@128 110 struct inflate_state FAR *state;
cannam@128 111 type_ar ar;
cannam@128 112 void inffas8664fnc(struct inffast_ar * par);
cannam@128 113
cannam@128 114
cannam@128 115
cannam@128 116 #if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64))
cannam@128 117 #define PAD_AVAIL_IN 6
cannam@128 118 #define PAD_AVAIL_OUT 258
cannam@128 119 #else
cannam@128 120 #define PAD_AVAIL_IN 5
cannam@128 121 #define PAD_AVAIL_OUT 257
cannam@128 122 #endif
cannam@128 123
cannam@128 124 /* copy state to local variables */
cannam@128 125 state = (struct inflate_state FAR *)strm->state;
cannam@128 126
cannam@128 127 ar.in = strm->next_in;
cannam@128 128 ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN);
cannam@128 129 ar.out = strm->next_out;
cannam@128 130 ar.beg = ar.out - (start - strm->avail_out);
cannam@128 131 ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT);
cannam@128 132 ar.wsize = state->wsize;
cannam@128 133 ar.write = state->wnext;
cannam@128 134 ar.window = state->window;
cannam@128 135 ar.hold = state->hold;
cannam@128 136 ar.bits = state->bits;
cannam@128 137 ar.lcode = state->lencode;
cannam@128 138 ar.dcode = state->distcode;
cannam@128 139 ar.lmask = (1U << state->lenbits) - 1;
cannam@128 140 ar.dmask = (1U << state->distbits) - 1;
cannam@128 141
cannam@128 142 /* decode literals and length/distances until end-of-block or not enough
cannam@128 143 input data or output space */
cannam@128 144
cannam@128 145 /* align in on 1/2 hold size boundary */
cannam@128 146 while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) {
cannam@128 147 ar.hold += (unsigned long)*ar.in++ << ar.bits;
cannam@128 148 ar.bits += 8;
cannam@128 149 }
cannam@128 150
cannam@128 151 inffas8664fnc(&ar);
cannam@128 152
cannam@128 153 if (ar.status > 1) {
cannam@128 154 if (ar.status == 2)
cannam@128 155 strm->msg = "invalid literal/length code";
cannam@128 156 else if (ar.status == 3)
cannam@128 157 strm->msg = "invalid distance code";
cannam@128 158 else
cannam@128 159 strm->msg = "invalid distance too far back";
cannam@128 160 state->mode = BAD;
cannam@128 161 }
cannam@128 162 else if ( ar.status == 1 ) {
cannam@128 163 state->mode = TYPE;
cannam@128 164 }
cannam@128 165
cannam@128 166 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
cannam@128 167 ar.len = ar.bits >> 3;
cannam@128 168 ar.in -= ar.len;
cannam@128 169 ar.bits -= ar.len << 3;
cannam@128 170 ar.hold &= (1U << ar.bits) - 1;
cannam@128 171
cannam@128 172 /* update state and return */
cannam@128 173 strm->next_in = ar.in;
cannam@128 174 strm->next_out = ar.out;
cannam@128 175 strm->avail_in = (unsigned)(ar.in < ar.last ?
cannam@128 176 PAD_AVAIL_IN + (ar.last - ar.in) :
cannam@128 177 PAD_AVAIL_IN - (ar.in - ar.last));
cannam@128 178 strm->avail_out = (unsigned)(ar.out < ar.end ?
cannam@128 179 PAD_AVAIL_OUT + (ar.end - ar.out) :
cannam@128 180 PAD_AVAIL_OUT - (ar.out - ar.end));
cannam@128 181 state->hold = (unsigned long)ar.hold;
cannam@128 182 state->bits = ar.bits;
cannam@128 183 return;
cannam@128 184 }
cannam@128 185
cannam@128 186 #endif