Index: third_party/zlib/simd.patch |
diff --git a/third_party/zlib/simd.patch b/third_party/zlib/simd.patch |
index c60946b306d2ffa76b1b3aa05fb7dacf094b3107..75828d26ea59a282d4ea433ce7a5dc7b8b954b4a 100644 |
--- a/third_party/zlib/simd.patch |
+++ b/third_party/zlib/simd.patch |
@@ -1,7 +1,7 @@ |
-diff --git a/third_party/zlib/crc32.c b/third_party/zlib/crc32.c |
-index 979a7190a3ca..09228ed9c76f 100644 |
---- a/third_party/zlib/crc32.c |
-+++ b/third_party/zlib/crc32.c |
+diff --git a/crc32.c b/crc32.c |
+index 9580440c0e6b..9162429cc7b4 100644 |
+--- a/crc32.c |
++++ b/crc32.c |
@@ -28,6 +28,8 @@ |
# endif /* !DYNAMIC_CRC_TABLE */ |
#endif /* MAKECRCH */ |
@@ -10,8 +10,8 @@ index 979a7190a3ca..09228ed9c76f 100644 |
+#include "x86.h" |
#include "zutil.h" /* for STDC and FAR definitions */ |
- #define local static |
-@@ -423,3 +425,28 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2) |
+ /* Definitions for doing the crc four data bytes at a time. */ |
+@@ -440,3 +442,28 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2) |
{ |
return crc32_combine_(crc1, crc2, len2); |
} |
@@ -40,10 +40,11 @@ index 979a7190a3ca..09228ed9c76f 100644 |
+ zmemcpy(dst, strm->next_in, size); |
+ strm->adler = crc32(strm->adler, dst, size); |
+} |
-diff --git a/third_party/zlib/crc_folding.c b/third_party/zlib/crc_folding.c |
-index e69de29bb2d1..48d77744aaf4 100644 |
---- a/third_party/zlib/crc_folding.c |
-+++ b/third_party/zlib/crc_folding.c |
+diff --git a/crc_folding.c b/crc_folding.c |
+new file mode 100644 |
+index 000000000000..48d77744aaf4 |
+--- /dev/null |
++++ b/crc_folding.c |
@@ -0,0 +1,493 @@ |
+/* |
+ * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ |
@@ -538,10 +539,10 @@ index e69de29bb2d1..48d77744aaf4 100644 |
+ return ~crc; |
+ CRC_SAVE(s) |
+} |
-diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c |
-index 696957705b75..02fa2f64f83e 100644 |
---- a/third_party/zlib/deflate.c |
-+++ b/third_party/zlib/deflate.c |
+diff --git a/deflate.c b/deflate.c |
+index 1ec761448de9..aa0c9c67a6dc 100644 |
+--- a/deflate.c |
++++ b/deflate.c |
@@ -48,8 +48,9 @@ |
*/ |
@@ -552,23 +553,20 @@ index 696957705b75..02fa2f64f83e 100644 |
+#include "x86.h" |
const char deflate_copyright[] = |
- " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; |
-@@ -84,7 +85,7 @@ local block_state deflate_huff OF((deflate_state *s, int flush)); |
+ " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; |
+@@ -86,7 +87,7 @@ local block_state deflate_huff OF((deflate_state *s, int flush)); |
local void lm_init OF((deflate_state *s)); |
local void putShortMSB OF((deflate_state *s, uInt b)); |
local void flush_pending OF((z_streamp strm)); |
--local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
-+ |
+-local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
++unsigned ZLIB_INTERNAL read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
#ifdef ASMV |
+ # pragma message("Assembler code may have bugs -- use at your own risk") |
void match_init OF((void)); /* asm code initialization */ |
- uInt longest_match OF((deflate_state *s, IPos cur_match)); |
-@@ -97,6 +98,23 @@ local void check_match OF((deflate_state *s, IPos start, IPos match, |
+@@ -100,6 +101,20 @@ local void check_match OF((deflate_state *s, IPos start, IPos match, |
int length)); |
#endif |
-+/* For fill_window_sse.c to use */ |
-+ZLIB_INTERNAL int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
-+ |
+/* From crc32.c */ |
+extern void ZLIB_INTERNAL crc_reset(deflate_state *const s); |
+extern void ZLIB_INTERNAL crc_finalize(deflate_state *const s); |
@@ -586,7 +584,7 @@ index 696957705b75..02fa2f64f83e 100644 |
/* =========================================================================== |
* Local data |
*/ |
-@@ -166,7 +184,6 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ |
+@@ -162,7 +177,6 @@ local const config configuration_table[10] = { |
*/ |
#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) |
@@ -594,9 +592,9 @@ index 696957705b75..02fa2f64f83e 100644 |
/* =========================================================================== |
* Insert string str in the dictionary and set match_head to the previous head |
* of the hash chain (the most recent string with same hash key). Return |
-@@ -177,17 +194,28 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ |
- * input characters and the first MIN_MATCH bytes of str are valid |
- * (except for the last MIN_MATCH-1 bytes of the input file). |
+@@ -173,17 +187,28 @@ local const config configuration_table[10] = { |
+ * characters and the first MIN_MATCH bytes of str are valid (except for |
+ * the last MIN_MATCH-1 bytes of the input file). |
*/ |
+local INLINE Pos insert_string_c(deflate_state *const s, const Pos str) |
+{ |
@@ -631,7 +629,7 @@ index 696957705b75..02fa2f64f83e 100644 |
/* =========================================================================== |
* Initialize the hash table (avoiding 64K overflow for 16 bit systems). |
-@@ -221,6 +249,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
+@@ -248,6 +273,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
const char *version; |
int stream_size; |
{ |
@@ -639,7 +637,7 @@ index 696957705b75..02fa2f64f83e 100644 |
deflate_state *s; |
int wrap = 1; |
static const char my_version[] = ZLIB_VERSION; |
-@@ -230,6 +259,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
+@@ -257,6 +283,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
* output size for (length,distance) codes is <= 24 bits. |
*/ |
@@ -648,11 +646,11 @@ index 696957705b75..02fa2f64f83e 100644 |
if (version == Z_NULL || version[0] != my_version[0] || |
stream_size != sizeof(z_stream)) { |
return Z_VERSION_ERROR; |
-@@ -285,12 +316,17 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
+@@ -313,12 +341,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
s->w_size = 1 << s->w_bits; |
s->w_mask = s->w_size - 1; |
-- s->hash_bits = memLevel + 7; |
+- s->hash_bits = (uInt)memLevel + 7; |
+ if (x86_cpu_enable_simd) { |
+ s->hash_bits = 15; |
+ } else { |
@@ -664,11 +662,13 @@ index 696957705b75..02fa2f64f83e 100644 |
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); |
- s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); |
-+ s->window = (Bytef *) ZALLOC(strm, s->w_size + window_padding, 2*sizeof(Byte)); |
++ s->window = (Bytef *) ZALLOC(strm, |
++ s->w_size + window_padding, |
++ 2*sizeof(Byte)); |
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); |
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); |
-@@ -365,11 +401,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
+@@ -418,11 +453,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
str = s->strstart; |
n = s->lookahead - (MIN_MATCH-1); |
do { |
@@ -681,16 +681,16 @@ index 696957705b75..02fa2f64f83e 100644 |
str++; |
} while (--n); |
s->strstart = str; |
-@@ -690,7 +722,7 @@ int ZEXPORT deflate (strm, flush) |
- if (s->status == INIT_STATE) { |
+@@ -848,7 +879,7 @@ int ZEXPORT deflate (strm, flush) |
#ifdef GZIP |
- if (s->wrap == 2) { |
-- strm->adler = crc32(0L, Z_NULL, 0); |
-+ crc_reset(s); |
- put_byte(s, 31); |
- put_byte(s, 139); |
- put_byte(s, 8); |
-@@ -952,6 +984,7 @@ int ZEXPORT deflate (strm, flush) |
+ if (s->status == GZIP_STATE) { |
+ /* gzip header */ |
+- strm->adler = crc32(0L, Z_NULL, 0); |
++ crc_reset(s); |
+ put_byte(s, 31); |
+ put_byte(s, 139); |
+ put_byte(s, 8); |
+@@ -1049,6 +1080,7 @@ int ZEXPORT deflate (strm, flush) |
/* Write the trailer */ |
#ifdef GZIP |
if (s->wrap == 2) { |
@@ -698,16 +698,16 @@ index 696957705b75..02fa2f64f83e 100644 |
put_byte(s, (Byte)(strm->adler & 0xff)); |
put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); |
put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); |
-@@ -1073,7 +1106,7 @@ int ZEXPORT deflateCopy (dest, source) |
+@@ -1161,7 +1193,7 @@ int ZEXPORT deflateCopy (dest, source) |
* allocating a large strm->next_in buffer and copying from it. |
* (See also flush_pending()). |
*/ |
--local int read_buf(strm, buf, size) |
-+ZLIB_INTERNAL int read_buf(strm, buf, size) |
+-local unsigned read_buf(strm, buf, size) |
++ZLIB_INTERNAL unsigned read_buf(strm, buf, size) |
z_streamp strm; |
Bytef *buf; |
unsigned size; |
-@@ -1085,15 +1118,16 @@ local int read_buf(strm, buf, size) |
+@@ -1173,15 +1205,16 @@ local unsigned read_buf(strm, buf, size) |
strm->avail_in -= len; |
@@ -731,7 +731,7 @@ index 696957705b75..02fa2f64f83e 100644 |
strm->next_in += len; |
strm->total_in += len; |
-@@ -1387,7 +1421,19 @@ local void check_match(s, start, match, length) |
+@@ -1479,7 +1512,19 @@ local void check_match(s, start, match, length) |
* performed for at least two bytes (required for the zip translate_eol |
* option -- not supported here). |
*/ |
@@ -751,8 +751,8 @@ index 696957705b75..02fa2f64f83e 100644 |
+local void fill_window_c(s) |
deflate_state *s; |
{ |
- register unsigned n, m; |
-@@ -1651,7 +1697,7 @@ local block_state deflate_fast(s, flush) |
+ unsigned n; |
+@@ -1847,7 +1892,7 @@ local block_state deflate_fast(s, flush) |
*/ |
hash_head = NIL; |
if (s->lookahead >= MIN_MATCH) { |
@@ -761,7 +761,7 @@ index 696957705b75..02fa2f64f83e 100644 |
} |
/* Find the longest match, discarding those <= prev_length. |
-@@ -1682,7 +1728,7 @@ local block_state deflate_fast(s, flush) |
+@@ -1878,7 +1923,7 @@ local block_state deflate_fast(s, flush) |
s->match_length--; /* string at strstart already in table */ |
do { |
s->strstart++; |
@@ -770,7 +770,7 @@ index 696957705b75..02fa2f64f83e 100644 |
/* strstart never exceeds WSIZE-MAX_MATCH, so there are |
* always MIN_MATCH bytes ahead. |
*/ |
-@@ -1754,7 +1800,7 @@ local block_state deflate_slow(s, flush) |
+@@ -1950,7 +1995,7 @@ local block_state deflate_slow(s, flush) |
*/ |
hash_head = NIL; |
if (s->lookahead >= MIN_MATCH) { |
@@ -779,7 +779,7 @@ index 696957705b75..02fa2f64f83e 100644 |
} |
/* Find the longest match, discarding those <= prev_length. |
-@@ -1805,7 +1851,7 @@ local block_state deflate_slow(s, flush) |
+@@ -2001,7 +2046,7 @@ local block_state deflate_slow(s, flush) |
s->prev_length -= 2; |
do { |
if (++s->strstart <= max_insert) { |
@@ -788,7 +788,7 @@ index 696957705b75..02fa2f64f83e 100644 |
} |
} while (--s->prev_length != 0); |
s->match_available = 0; |
-@@ -1965,3 +2011,37 @@ local block_state deflate_huff(s, flush) |
+@@ -2161,3 +2206,37 @@ local block_state deflate_huff(s, flush) |
FLUSH_BLOCK(s, 0); |
return block_done; |
} |
@@ -826,12 +826,12 @@ index 696957705b75..02fa2f64f83e 100644 |
+ s->prev[str & s->w_mask] = ret; |
+ return ret; |
+} |
-diff --git a/third_party/zlib/deflate.h b/third_party/zlib/deflate.h |
-index ce0299edd191..022d9c326ecc 100644 |
---- a/third_party/zlib/deflate.h |
-+++ b/third_party/zlib/deflate.h |
-@@ -106,7 +106,7 @@ typedef struct internal_state { |
- uInt gzindex; /* where in extra, name, or comment */ |
+diff --git a/deflate.h b/deflate.h |
+index 23ecdd312bc0..ab56df7663b6 100644 |
+--- a/deflate.h |
++++ b/deflate.h |
+@@ -109,7 +109,7 @@ typedef struct internal_state { |
+ ulg gzindex; /* where in extra, name, or comment */ |
Byte method; /* can only be DEFLATED */ |
int last_flush; /* value of flush param for previous deflate call */ |
- |
@@ -839,7 +839,7 @@ index ce0299edd191..022d9c326ecc 100644 |
/* used by deflate.c: */ |
uInt w_size; /* LZ77 window size (32K by default) */ |
-@@ -343,4 +343,14 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, |
+@@ -346,4 +346,14 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, |
flush = _tr_tally(s, distance, length) |
#endif |
@@ -854,10 +854,11 @@ index ce0299edd191..022d9c326ecc 100644 |
+void ZLIB_INTERNAL fill_window_sse(deflate_state* s); |
+ |
#endif /* DEFLATE_H */ |
-diff --git a/third_party/zlib/fill_window_sse.c b/third_party/zlib/fill_window_sse.c |
-index e69de29bb2d1..949ccce1ba9c 100644 |
---- a/third_party/zlib/fill_window_sse.c |
-+++ b/third_party/zlib/fill_window_sse.c |
+diff --git a/fill_window_sse.c b/fill_window_sse.c |
+new file mode 100644 |
+index 000000000000..949ccce1ba9c |
+--- /dev/null |
++++ b/fill_window_sse.c |
@@ -0,0 +1,175 @@ |
+/* |
+ * Fill Window with SSE2-optimized hash shifting |
@@ -1034,29 +1035,32 @@ index e69de29bb2d1..949ccce1ba9c 100644 |
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, |
+ "not enough room for search"); |
+} |
-diff --git a/third_party/zlib/mozzconf.h b/third_party/zlib/mozzconf.h |
-index d7e9f91c5a12..10aca44b29a4 100644 |
---- a/third_party/zlib/mozzconf.h |
-+++ b/third_party/zlib/mozzconf.h |
-@@ -169,6 +169,14 @@ |
- #define inflateResetKeep MOZ_Z_inflateResetKeep |
- #define gzopen_w MOZ_Z_gzopen_w |
+diff --git a/names.h b/names.h |
+index f18df5684dc5..3436baa4eb57 100644 |
+--- a/names.h |
++++ b/names.h |
+@@ -152,4 +152,16 @@ |
+ /* An exported symbol that isn't handled by Z_PREFIX in zconf.h */ |
+ #define z_errmsg Cr_z_z_errmsg |
-+/* Chromium-specific modifications */ |
-+#define copy_with_crc MOZ_Z__copy_with_crc |
-+#define crc_finalize MOZ_Z__crc_finalize |
-+#define crc_reset MOZ_Z__crc_reset |
-+// read_buf used to be local, but this was changed in simd.patch. |
-+#define read_buf MOZ_Z__read_buf |
-+#define x86_check_features MOZ_Z__x86_check_features |
-+ |
- /* Mangle Byte types except on Mac. */ |
- #if !defined(__MACTYPES__) |
- #define Byte MOZ_Z_Byte |
-diff --git a/third_party/zlib/simd_stub.c b/third_party/zlib/simd_stub.c |
-index e69de29bb2d1..796f1f63f690 100644 |
---- a/third_party/zlib/simd_stub.c |
-+++ b/third_party/zlib/simd_stub.c |
++/* Symbols added in simd.patch */ |
++#define copy_with_crc Cr_z_copy_with_crc |
++#define crc_finalize Cr_z_crc_finalize |
++#define crc_fold_512to32 Cr_z_crc_fold_512to32 |
++#define crc_fold_copy Cr_z_crc_fold_copy |
++#define crc_fold_init Cr_z_crc_fold_init |
++#define crc_reset Cr_z_crc_reset |
++#define fill_window_sse Cr_z_fill_window_sse |
++#define read_buf Cr_z_read_buf |
++#define x86_check_features Cr_z_x86_check_features |
++#define x86_cpu_enable_simd Cr_z_x86_cpu_enable_simd |
++ |
+ #endif /* THIRD_PARTY_ZLIB_NAMES_H_ */ |
+diff --git a/simd_stub.c b/simd_stub.c |
+new file mode 100644 |
+index 000000000000..c6d46051498f |
+--- /dev/null |
++++ b/simd_stub.c |
@@ -0,0 +1,35 @@ |
+/* simd_stub.c -- stub implementations |
+* Copyright (C) 2014 Intel Corporation |
@@ -1067,7 +1071,7 @@ index e69de29bb2d1..796f1f63f690 100644 |
+#include "deflate.h" |
+#include "x86.h" |
+ |
-+int x86_cpu_enable_simd = 0; |
++int ZLIB_INTERNAL x86_cpu_enable_simd = 0; |
+ |
+void ZLIB_INTERNAL crc_fold_init(deflate_state *const s) { |
+ assert(0); |
@@ -1093,11 +1097,12 @@ index e69de29bb2d1..796f1f63f690 100644 |
+void x86_check_features(void) |
+{ |
+} |
-diff --git a/third_party/zlib/x86.c b/third_party/zlib/x86.c |
-index e69de29bb2d1..e6532fd10ddb 100644 |
---- a/third_party/zlib/x86.c |
-+++ b/third_party/zlib/x86.c |
-@@ -0,0 +1,91 @@ |
+diff --git a/x86.c b/x86.c |
+new file mode 100644 |
+index 000000000000..e56fe8b85a39 |
+--- /dev/null |
++++ b/x86.c |
+@@ -0,0 +1,92 @@ |
+/* |
+ * x86 feature check |
+ * |
@@ -1109,8 +1114,9 @@ index e69de29bb2d1..e6532fd10ddb 100644 |
+ */ |
+ |
+#include "x86.h" |
++#include "zutil.h" |
+ |
-+int x86_cpu_enable_simd = 0; |
++int ZLIB_INTERNAL x86_cpu_enable_simd = 0; |
+ |
+#ifndef _MSC_VER |
+#include <pthread.h> |
@@ -1189,10 +1195,11 @@ index e69de29bb2d1..e6532fd10ddb 100644 |
+ return TRUE; |
+} |
+#endif /* _MSC_VER */ |
-diff --git a/third_party/zlib/x86.h b/third_party/zlib/x86.h |
-index e69de29bb2d1..ebcf10ab09d2 100644 |
---- a/third_party/zlib/x86.h |
-+++ b/third_party/zlib/x86.h |
+diff --git a/x86.h b/x86.h |
+new file mode 100644 |
+index 000000000000..ebcf10ab09d2 |
+--- /dev/null |
++++ b/x86.h |
@@ -0,0 +1,15 @@ |
+/* x86.h -- check for x86 CPU features |
+* Copyright (C) 2013 Intel Corporation Jim Kukunas |
@@ -1209,3 +1216,18 @@ index e69de29bb2d1..ebcf10ab09d2 100644 |
+void x86_check_features(void); |
+ |
+#endif /* X86_H */ |
+diff --git a/zutil.h b/zutil.h |
+index 80375b8b6109..4425bcf75eb3 100644 |
+--- a/zutil.h |
++++ b/zutil.h |
+@@ -283,4 +283,10 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ |
+ #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ |
+ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) |
+ |
++#ifdef _MSC_VER |
++#define zalign(x) __declspec(align(x)) |
++#else |
++#define zalign(x) __attribute__((aligned((x)))) |
++#endif |
++ |
+ #endif /* ZUTIL_H */ |