22# Use of this source code is governed by a BSD-style license that can be
33# found in the LICENSE file.
44
5+
6+ if (current_cpu == " arm" || current_cpu == " arm64" ) {
7+ import (" //build/config/arm.gni" )
8+ }
9+
510config (" zlib_config" ) {
611 include_dirs = [ " ." ]
712}
813
9- static_library (" zlib_x86_simd" ) {
10- if (! is_ios && (current_cpu == " x86" || current_cpu == " x64" )) {
14+ config (" zlib_internal_config" ) {
15+ defines = [ " ZLIB_IMPLEMENTATION" ]
16+ }
17+
18+ use_arm_neon_optimizations = false
19+ if ((current_cpu == " arm" || current_cpu == " arm64" ) &&
20+ ! (is_win && ! is_clang )) {
21+ # TODO(richard.townsend@arm.com): Optimizations temporarily disabled for
22+ # Windows on Arm MSVC builds, see http://crbug.com/v8/10012.
23+ if (arm_use_neon ) {
24+ use_arm_neon_optimizations = true
25+ }
26+ }
27+
28+ use_x86_x64_optimizations =
29+ (current_cpu == " x86" || current_cpu == " x64" ) && ! is_ios
30+
31+ config (" zlib_adler32_simd_config" ) {
32+ if (use_x86_x64_optimizations ) {
33+ defines = [ " ADLER32_SIMD_SSSE3" ]
34+ if (is_win ) {
35+ defines += [ " X86_WINDOWS" ]
36+ } else {
37+ defines += [ " X86_NOT_WINDOWS" ]
38+ }
39+ }
40+
41+ if (use_arm_neon_optimizations ) {
42+ defines = [ " ADLER32_SIMD_NEON" ]
43+ }
44+ }
45+
46+ source_set (" zlib_adler32_simd" ) {
47+ visibility = [ " :*" ]
48+
49+ if (use_x86_x64_optimizations ) {
1150 sources = [
12- " crc_folding .c" ,
13- " fill_window_sse.c " ,
51+ " adler32_simd .c" ,
52+ " adler32_simd.h " ,
1453 ]
54+
1555 if (! is_win || is_clang ) {
16- cflags = [
17- " -msse4.2" ,
18- " -mpclmul" ,
56+ cflags = [ " -mssse3" ]
57+ }
58+ }
59+
60+ if (use_arm_neon_optimizations ) {
61+ sources = [
62+ " adler32_simd.c" ,
63+ " adler32_simd.h" ,
64+ ]
65+ }
66+
67+ configs += [ " :zlib_internal_config" ]
68+
69+ public_configs = [ " :zlib_adler32_simd_config" ]
70+ }
71+
72+ if (use_arm_neon_optimizations ) {
73+ config (" zlib_arm_crc32_config" ) {
74+ # Disabled for iPhone, as described in DDI0487C_a_armv8_arm:
75+ # "All implementations of the ARMv8.1 architecture are required to
76+ # implement the CRC32* instructions. These are optional in ARMv8.0."
77+ if (! is_ios ) {
78+ defines = [ " CRC32_ARMV8_CRC32" ]
79+ if (is_android ) {
80+ defines += [ " ARMV8_OS_ANDROID" ]
81+ } else if (is_linux || is_chromeos ) {
82+ defines += [ " ARMV8_OS_LINUX" ]
83+ } else if (is_mac ) {
84+ defines += [ " ARMV8_OS_MACOS" ]
85+ } else if (is_fuchsia ) {
86+ defines += [ " ARMV8_OS_FUCHSIA" ]
87+ } else if (is_win ) {
88+ defines += [ " ARMV8_OS_WINDOWS" ]
89+ } else {
90+ assert (false , " Unsupported ARM OS" )
91+ }
92+ }
93+ }
94+
95+ source_set (" zlib_arm_crc32" ) {
96+ visibility = [ " :*" ]
97+
98+ if (! is_ios ) {
99+ include_dirs = [ " ." ]
100+
101+ if (! is_win && ! is_clang ) {
102+ assert (! use_thin_lto ,
103+ " ThinLTO fails mixing different module-level targets" )
104+ cflags_c = [ " -march=armv8-a+crc" ]
105+ }
106+
107+ sources = [
108+ " crc32_simd.c" ,
109+ " crc32_simd.h" ,
19110 ]
20111 }
21- } else {
112+
113+ configs += [ " :zlib_internal_config" ]
114+
115+ public_configs = [ " :zlib_arm_crc32_config" ]
116+ }
117+ }
118+
119+ config (" zlib_inflate_chunk_simd_config" ) {
120+ if (use_x86_x64_optimizations ) {
121+ defines = [ " INFLATE_CHUNK_SIMD_SSE2" ]
122+
123+ if (current_cpu == " x64" ) {
124+ defines += [ " INFLATE_CHUNK_READ_64LE" ]
125+ }
126+ }
127+
128+ if (use_arm_neon_optimizations ) {
129+ defines = [ " INFLATE_CHUNK_SIMD_NEON" ]
130+
131+ if (current_cpu == " arm64" ) {
132+ defines += [ " INFLATE_CHUNK_READ_64LE" ]
133+ }
134+ }
135+ }
136+
137+ source_set (" zlib_inflate_chunk_simd" ) {
138+ visibility = [ " :*" ]
139+
140+ if (use_x86_x64_optimizations || use_arm_neon_optimizations ) {
141+ include_dirs = [ " ." ]
142+
22143 sources = [
23- " simd_stub.c" ,
144+ " contrib/optimizations/chunkcopy.h" ,
145+ " contrib/optimizations/inffast_chunk.c" ,
146+ " contrib/optimizations/inffast_chunk.h" ,
147+ " contrib/optimizations/inflate.c" ,
24148 ]
25149 }
26150
151+ configs += [ " :zlib_internal_config" ]
152+
153+ # Needed for MSVC, which is still supported by V8 and PDFium. zlib uses K&R C
154+ # style function declarations, which triggers warning C4131.
27155 configs -= [ " //build/config/compiler:chromium_code" ]
28156 configs += [ " //build/config/compiler:no_chromium_code" ]
157+
158+ public_configs = [ " :zlib_inflate_chunk_simd_config" ]
29159}
30160
31- config (" zlib_warnings" ) {
161+ config (" zlib_crc32_simd_config" ) {
162+ if (use_x86_x64_optimizations ) {
163+ defines = [ " CRC32_SIMD_SSE42_PCLMUL" ]
164+ }
165+ }
166+
167+ source_set (" zlib_crc32_simd" ) {
32168 visibility = [ " :*" ]
33- if (is_clang ) {
34- cflags = [
35- " -Wno-incompatible-pointer-types" ,
36- " -Wno-shift-negative-value" ,
169+
170+ if (use_x86_x64_optimizations ) {
171+ sources = [
172+ " crc32_simd.c" ,
173+ " crc32_simd.h" ,
37174 ]
175+
176+ if (! is_win || is_clang ) {
177+ cflags = [
178+ " -msse4.2" ,
179+ " -mpclmul" ,
180+ ]
181+ }
182+ }
183+
184+ configs += [ " :zlib_internal_config" ]
185+
186+ public_configs = [ " :zlib_crc32_simd_config" ]
187+ }
188+
189+ config (" zlib_x86_simd_config" ) {
190+ if (use_x86_x64_optimizations ) {
191+ defines = [
192+ " CRC32_SIMD_SSE42_PCLMUL" ,
193+ " DEFLATE_FILL_WINDOW_SSE2" ,
194+ ]
195+ }
196+ }
197+
198+ source_set (" zlib_x86_simd" ) {
199+ visibility = [ " :*" ]
200+
201+ if (use_x86_x64_optimizations ) {
202+ sources = [
203+ " crc_folding.c" ,
204+ " fill_window_sse.c" ,
205+ ]
206+
207+ if (! is_win || is_clang ) {
208+ cflags = [
209+ " -msse4.2" ,
210+ " -mpclmul" ,
211+ ]
212+ }
213+ }
214+
215+ configs += [ " :zlib_internal_config" ]
216+
217+ public_configs = [ " :zlib_x86_simd_config" ]
218+ }
219+
220+ config (" zlib_warnings" ) {
221+ if (is_clang && use_x86_x64_optimizations ) {
222+ cflags = [ " -Wno-incompatible-pointer-types" ]
38223 }
39224}
40225
41- static_library (" zlib" ) {
226+ component (" zlib" ) {
42227 if (! is_win ) {
43228 # Don't stomp on "libzlib" on other platforms.
44229 output_name = " chrome_zlib"
45230 }
46231
47232 sources = [
48233 " adler32.c" ,
234+ " chromeconf.h" ,
49235 " compress.c" ,
236+ " contrib/optimizations/insert_string.h" ,
237+ " cpu_features.c" ,
238+ " cpu_features.h" ,
50239 " crc32.c" ,
51240 " crc32.h" ,
52241 " deflate.c" ,
@@ -60,37 +249,80 @@ static_library("zlib") {
60249 " inffast.c" ,
61250 " inffast.h" ,
62251 " inffixed.h" ,
63- " inflate.c" ,
64252 " inflate.h" ,
65253 " inftrees.c" ,
66254 " inftrees.h" ,
67- " mozzconf.h" ,
68255 " trees.c" ,
69256 " trees.h" ,
70257 " uncompr.c" ,
71- " x86.h" ,
72258 " zconf.h" ,
73259 " zlib.h" ,
74260 " zutil.c" ,
75261 " zutil.h" ,
76262 ]
77263
78- if (! is_ios && (current_cpu == " x86" || current_cpu == " x64" )) {
79- sources += [ " x86.c" ]
264+ defines = []
265+ deps = []
266+
267+ if (! use_x86_x64_optimizations && ! use_arm_neon_optimizations ) {
268+ # Apparently android_cronet bot builds with NEON disabled and
269+ # we also should disable optimizations for iOS@x86 (a.k.a. simulator).
270+ defines += [ " CPU_NO_SIMD" ]
271+ }
272+
273+ if (is_ios ) {
274+ # iOS@ARM is a special case where we always have NEON but don't check
275+ # for crypto extensions.
276+ # TODO(cavalcantii ): verify what is the current state of CPU features
277+ # shipped on latest iOS devices.
278+ defines += [ " ARM_OS_IOS" ]
279+ }
280+
281+ if (use_x86_x64_optimizations || use_arm_neon_optimizations ) {
282+ deps += [
283+ " :zlib_adler32_simd" ,
284+ " :zlib_inflate_chunk_simd" ,
285+ ]
286+
287+ if (use_x86_x64_optimizations ) {
288+ deps += [ " :zlib_crc32_simd" ]
289+ } else if (use_arm_neon_optimizations ) {
290+ sources += [ " contrib/optimizations/slide_hash_neon.h" ]
291+ deps += [ " :zlib_arm_crc32" ]
292+ }
293+ } else {
294+ sources += [ " inflate.c" ]
295+ }
296+
297+ deps += [ " :zlib_x86_simd" ]
298+
299+ if (is_android ) {
300+ import (" //build/config/android/config.gni" )
301+ if (defined (android_ndk_root ) && android_ndk_root != " " ) {
302+ deps += [ " //third_party/android_tools:cpu_features" ]
303+ } else {
304+ assert (false , " CPU detection requires the Android NDK" )
305+ }
80306 }
81- configs += [ " :zlib_warnings" ]
82307
83308 configs -= [ " //build/config/compiler:chromium_code" ]
84309 configs += [ " //build/config/compiler:no_chromium_code" ]
85310
86311 public_configs = [ " :zlib_config" ]
87- deps = [
88- " :zlib_x86_simd" ,
312+
313+ configs += [
314+ " :zlib_internal_config" ,
315+
316+ # Must be after no_chromium_code for warning flags to be ordered correctly.
317+ " :zlib_warnings" ,
89318 ]
319+
320+ allow_circular_includes_from = deps
90321}
91322
92323config (" minizip_warnings" ) {
93324 visibility = [ " :*" ]
325+
94326 if (is_clang ) {
95327 # zlib uses `if ((a == b))` for some reason.
96328 cflags = [ " -Wno-parentheses-equality" ]
@@ -115,32 +347,33 @@ static_library("minizip") {
115347 " contrib/minizip/iowin32.h" ,
116348 ]
117349 }
350+
118351 if (is_mac || is_ios || is_android || is_fuchsia ) {
119352 # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
120353 # use fopen, ftell, and fseek instead on these systems.
121354 defines = [ " USE_FILE32API" ]
122355 }
123356
124- deps = [
125- " :zlib" ,
126- ]
357+ deps = [ " :zlib" ]
127358
128359 configs -= [ " //build/config/compiler:chromium_code" ]
129360 configs += [ " //build/config/compiler:no_chromium_code" ]
130- configs += [ " :minizip_warnings " ]
361+
131362 public_configs = [ " :zlib_config" ]
132- }
133363
134- static_library (" zip" ) {
135- sources = [
136- " google/zip.cc" ,
137- " google/zip.h" ,
138- " google/zip_internal.cc" ,
139- " google/zip_internal.h" ,
140- " google/zip_reader.cc" ,
141- " google/zip_reader.h" ,
142- ]
143- deps = [
144- " :minizip" ,
364+ configs += [
365+ # Must be after no_chromium_code for warning flags to be ordered correctly.
366+ " :minizip_warnings" ,
145367 ]
146368}
369+
370+ executable (" zlib_bench" ) {
371+ include_dirs = [ " ." ]
372+
373+ sources = [ " contrib/bench/zlib_bench.cc" ]
374+
375+ deps = [ " :zlib" ]
376+
377+ configs -= [ " //build/config/compiler:chromium_code" ]
378+ configs += [ " //build/config/compiler:no_chromium_code" ]
379+ }
0 commit comments