Skip to content

Commit

Permalink
Reorder 'inflate_state' struct to improve cache-locality of variables
Browse files Browse the repository at this point in the history
needed by inffast (from 6 cachelines to 1).
Also fill in some unnecessary holes.
  • Loading branch information
Dead2 committed Oct 8, 2024
1 parent a5c20ed commit 18af700
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,57 +97,58 @@ typedef struct inflate_allocs_s {
/* State maintained between inflate() calls -- approximately 7K bytes, not
including the allocated sliding window, which is up to 32K bytes. */
struct ALIGNED_(64) inflate_state {
PREFIX3(stream) *strm; /* pointer back to this zlib stream */
PREFIX3(stream) *strm; /* pointer back to this zlib stream */
inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags, 0 if zlib, or
-1 if raw or no header yet */
unsigned was; /* initial length of match, for inflateMark */
unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */
PREFIX(gz_headerp) head; /* where to save gzip header information */
int back; /* bits back of last unprocessed length/lit */

/* sliding window */
unsigned wbits; /* log base 2 of requested window size */
uint32_t wsize; /* window size or zero if not using window */
uint32_t wbufsize; /* real size of the allocated window buffer, including padding */
uint32_t whave; /* valid bytes in the window */
uint32_t wnext; /* window write index */
unsigned char *window; /* allocated sliding window, if needed */
#if defined(_M_IX86) || defined(_M_ARM)
uint32_t padding;
#else
uint32_t padding[2];
#endif

struct crc32_fold_s ALIGNED_(16) crc_fold;
uint32_t chunksize; /* size of memory copying chunk */

/* bit accumulator */
uint32_t hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */
/* fixed and dynamic code tables */
unsigned lenbits; /* index bits for lencode */
code const *lencode; /* starting table for length/literal codes */
code const *distcode; /* starting table for distance codes */
unsigned distbits; /* index bits for distcode */
/* for string and stored block copying */
uint32_t length; /* literal or length of data to copy */
unsigned offset; /* distance back to copy string from */
/* for table and code decoding */
unsigned extra; /* extra bits needed */
/* fixed and dynamic code tables */
code const *lencode; /* starting table for length/literal codes */
code const *distcode; /* starting table for distance codes */
unsigned lenbits; /* index bits for lencode */
unsigned distbits; /* index bits for distcode */
/* dynamic table building */
unsigned ncode; /* number of code length code lengths */
unsigned nlen; /* number of length code lengths */
unsigned ndist; /* number of distance code lengths */
uint32_t have; /* number of code lengths in lens[] */
code *next; /* next available space in codes[] */

#if defined(_M_IX86) || defined(_M_ARM)
uint32_t padding[2];
#endif
struct crc32_fold_s ALIGNED_(16) crc_fold;

uint16_t lens[320]; /* temporary storage for code lengths */
uint16_t work[288]; /* work area for code table building */
code codes[ENOUGH]; /* space for code tables */
int back; /* bits back of last unprocessed length/lit */
unsigned was; /* initial length of match */
uint32_t chunksize; /* size of memory copying chunk */

inflate_allocs *alloc_bufs; /* struct for handling memory allocations */

#ifdef INFLATE_STRICT
Expand Down

0 comments on commit 18af700

Please sign in to comment.