--- /dev/null
+/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding\r
+ * version for AMD64 on Windows using Microsoft C compiler\r
+ *\r
+ * Copyright (C) 1995-2003 Mark Adler\r
+ * For conditions of distribution and use, see copyright notice in zlib.h\r
+ *\r
+ * Copyright (C) 2003 Chris Anderson <christop@charm.net>\r
+ * Please use the copyright conditions above.\r
+ *\r
+ * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant\r
+ *\r
+ * inffas8664.c call function inffas8664fnc in inffasx64.asm\r
+ * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c\r
+ *\r
+ * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also\r
+ * slightly quicker on x86 systems because, instead of using rep movsb to copy\r
+ * data, it uses rep movsw, which moves data in 2-byte chunks instead of single\r
+ * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates\r
+ * from http://fedora.linux.duke.edu/fc1_x86_64\r
+ * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with\r
+ * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version,\r
+ * when decompressing mozilla-source-1.3.tar.gz.\r
+ *\r
+ * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from\r
+ * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at\r
+ * the moment. I have successfully compiled and tested this code with gcc2.96,\r
+ * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S\r
+ * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX\r
+ * enabled. I will attempt to merge the MMX code into this version. Newer\r
+ * versions of this and inffast.S can be found at\r
+ * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/\r
+ *\r
+ */\r
+\r
+#include <stdio.h>\r
+#include "zutil.h"\r
+#include "inftrees.h"\r
+#include "inflate.h"\r
+#include "inffast.h"\r
+\r
+/* Mark Adler's comments from inffast.c: */\r
+\r
+/*\r
+ Decode literal, length, and distance codes and write out the resulting\r
+ literal and match bytes until either not enough input or output is\r
+ available, an end-of-block is encountered, or a data error is encountered.\r
+ When large enough input and output buffers are supplied to inflate(), for\r
+ example, a 16K input buffer and a 64K output buffer, more than 95% of the\r
+ inflate execution time is spent in this routine.\r
+\r
+ Entry assumptions:\r
+\r
+ state->mode == LEN\r
+ strm->avail_in >= 6\r
+ strm->avail_out >= 258\r
+ start >= strm->avail_out\r
+ state->bits < 8\r
+\r
+ On return, state->mode is one of:\r
+\r
+ LEN -- ran out of enough output space or enough available input\r
+ TYPE -- reached end of block code, inflate() to interpret next block\r
+ BAD -- error in block data\r
+\r
+ Notes:\r
+\r
+ - The maximum input bits used by a length/distance pair is 15 bits for the\r
+ length code, 5 bits for the length extra, 15 bits for the distance code,\r
+ and 13 bits for the distance extra. This totals 48 bits, or six bytes.\r
+ Therefore if strm->avail_in >= 6, then there is enough input to avoid\r
+ checking for available input while decoding.\r
+\r
+ - The maximum bytes that a single length/distance pair can output is 258\r
+ bytes, which is the maximum length that can be coded. inflate_fast()\r
+ requires strm->avail_out >= 258 for each loop to avoid checking for\r
+ output space.\r
+ */\r
+\r
+\r
+\r
+ typedef struct inffast_ar {\r
+/* 64 32 x86 x86_64 */\r
+/* ar offset register */\r
+/* 0 0 */ void *esp; /* esp save */\r
+/* 8 4 */ void *ebp; /* ebp save */\r
+/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */\r
+/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */\r
+/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */\r
+/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */\r
+/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */\r
+/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */\r
+/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */\r
+/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */\r
+/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */\r
+/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */\r
+/* 92 48 */ unsigned wsize; /* window size */\r
+/* 96 52 */ unsigned write; /* window write index */\r
+/*100 56 */ unsigned lmask; /* r12 mask for lcode */\r
+/*104 60 */ unsigned dmask; /* r13 mask for dcode */\r
+/*108 64 */ unsigned len; /* r14 match length */\r
+/*112 68 */ unsigned dist; /* r15 match distance */\r
+/*116 72 */ unsigned status; /* set when state chng*/\r
+ } type_ar;\r
+#ifdef ASMINF\r
+\r
+void inflate_fast(strm, start)\r
+z_streamp strm;\r
+unsigned start; /* inflate()'s starting value for strm->avail_out */\r
+{\r
+ struct inflate_state FAR *state;\r
+ type_ar ar;\r
+ void inffas8664fnc(struct inffast_ar * par);\r
+\r
+ \r
+\r
+#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64))\r
+#define PAD_AVAIL_IN 6\r
+#define PAD_AVAIL_OUT 258 \r
+#else\r
+#define PAD_AVAIL_IN 5\r
+#define PAD_AVAIL_OUT 257\r
+#endif\r
+\r
+ /* copy state to local variables */\r
+ state = (struct inflate_state FAR *)strm->state;\r
+\r
+ ar.in = strm->next_in;\r
+ ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN);\r
+ ar.out = strm->next_out;\r
+ ar.beg = ar.out - (start - strm->avail_out);\r
+ ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT);\r
+ ar.wsize = state->wsize;\r
+ ar.write = state->write;\r
+ ar.window = state->window;\r
+ ar.hold = state->hold;\r
+ ar.bits = state->bits;\r
+ ar.lcode = state->lencode;\r
+ ar.dcode = state->distcode;\r
+ ar.lmask = (1U << state->lenbits) - 1;\r
+ ar.dmask = (1U << state->distbits) - 1;\r
+\r
+ /* decode literals and length/distances until end-of-block or not enough\r
+ input data or output space */\r
+\r
+ /* align in on 1/2 hold size boundary */\r
+ while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) {\r
+ ar.hold += (unsigned long)*ar.in++ << ar.bits;\r
+ ar.bits += 8;\r
+ }\r
+\r
+ inffas8664fnc(&ar);\r
+\r
+ if (ar.status > 1) {\r
+ if (ar.status == 2)\r
+ strm->msg = "invalid literal/length code";\r
+ else if (ar.status == 3)\r
+ strm->msg = "invalid distance code";\r
+ else\r
+ strm->msg = "invalid distance too far back";\r
+ state->mode = BAD;\r
+ }\r
+ else if ( ar.status == 1 ) {\r
+ state->mode = TYPE;\r
+ }\r
+\r
+ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */\r
+ ar.len = ar.bits >> 3;\r
+ ar.in -= ar.len;\r
+ ar.bits -= ar.len << 3;\r
+ ar.hold &= (1U << ar.bits) - 1;\r
+\r
+ /* update state and return */\r
+ strm->next_in = ar.in;\r
+ strm->next_out = ar.out;\r
+ strm->avail_in = (unsigned)(ar.in < ar.last ?\r
+ PAD_AVAIL_IN + (ar.last - ar.in) :\r
+ PAD_AVAIL_IN - (ar.in - ar.last));\r
+ strm->avail_out = (unsigned)(ar.out < ar.end ?\r
+ PAD_AVAIL_OUT + (ar.end - ar.out) :\r
+ PAD_AVAIL_OUT - (ar.out - ar.end));\r
+ state->hold = (unsigned long)ar.hold;\r
+ state->bits = ar.bits;\r
+ return;\r
+}\r
+\r
+#endif\r