• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/compiler/compiler.gni")
6
7if (current_cpu == "arm" || current_cpu == "arm64") {
8  import("//build/config/arm.gni")
9}
10
11config("zlib_config") {
12  include_dirs = [ "." ]
13}
14
15config("zlib_internal_config") {
16  defines = [ "ZLIB_IMPLEMENTATION" ]
17}
18
19use_arm_neon_optimizations = false
20if (current_cpu == "arm" || current_cpu == "arm64") {
21  if (arm_use_neon) {
22    use_arm_neon_optimizations = true
23  }
24}
25
26use_x86_x64_optimizations =
27    (current_cpu == "x86" || current_cpu == "x64") && !is_ios
28
29config("zlib_adler32_simd_config") {
30  if (use_x86_x64_optimizations) {
31    defines = [ "ADLER32_SIMD_SSSE3" ]
32    if (is_win) {
33      defines += [ "X86_WINDOWS" ]
34    } else {
35      defines += [ "X86_NOT_WINDOWS" ]
36    }
37  } else if (use_arm_neon_optimizations) {
38    defines = [ "ADLER32_SIMD_NEON" ]
39  }
40}
41
42source_set("zlib_adler32_simd") {
43  visibility = [ ":*" ]
44
45  if (use_x86_x64_optimizations) {
46    sources = [
47      "adler32_simd.c",
48      "adler32_simd.h",
49    ]
50
51    if (!is_win || is_clang) {
52      cflags = [ "-mssse3" ]
53    }
54  }
55
56  if (use_arm_neon_optimizations) {
57    sources = [
58      "adler32_simd.c",
59      "adler32_simd.h",
60    ]
61    if (!is_debug) {
62      # Use optimize_speed (-O3) to output the _smallest_ code.
63      configs -= [ "//build/config/compiler:default_optimization" ]
64      configs += [ "//build/config/compiler:optimize_speed" ]
65    }
66  }
67
68  configs += [ ":zlib_internal_config" ]
69
70  public_configs = [ ":zlib_adler32_simd_config" ]
71}
72
73if (use_arm_neon_optimizations) {
74  config("zlib_arm_crc32_config") {
75    # Disabled for iPhone, as described in DDI0487C_a_armv8_arm:
76    #  "All implementations of the ARMv8.1 architecture are required to
77    #   implement the CRC32* instructions. These are optional in ARMv8.0."
78    if (!is_ios) {
79      defines = [ "CRC32_ARMV8_CRC32" ]
80      if (is_android) {
81        defines += [ "ARMV8_OS_ANDROID" ]
82      } else if (is_linux || is_chromeos) {
83        defines += [ "ARMV8_OS_LINUX" ]
84      } else if (is_fuchsia) {
85        defines += [ "ARMV8_OS_FUCHSIA" ]
86      } else if (is_win) {
87        defines += [ "ARMV8_OS_WINDOWS" ]
88      } else {
89        assert(false, "Unsupported ARM OS")
90      }
91    }
92  }
93
94  source_set("zlib_arm_crc32") {
95    visibility = [ ":*" ]
96
97    if (!is_ios) {
98      include_dirs = [ "." ]
99
100      if (!is_win && !is_clang) {
101        assert(!use_thin_lto,
102               "ThinLTO fails mixing different module-level targets")
103        cflags_c = [ "-march=armv8-a+crc" ]
104      }
105
106      sources = [
107        "crc32_simd.c",
108        "crc32_simd.h",
109      ]
110
111      if (!is_debug) {
112        configs -= [ "//build/config/compiler:default_optimization" ]
113        configs += [ "//build/config/compiler:optimize_speed" ]
114      }
115    }
116
117    configs += [ ":zlib_internal_config" ]
118
119    public_configs = [ ":zlib_arm_crc32_config" ]
120  }
121}
122
123config("zlib_inflate_chunk_simd_config") {
124  if (use_x86_x64_optimizations) {
125    defines = [ "INFLATE_CHUNK_SIMD_SSE2" ]
126
127    if (current_cpu == "x64") {
128      defines += [ "INFLATE_CHUNK_READ_64LE" ]
129    }
130  }
131
132  if (use_arm_neon_optimizations) {
133    defines = [ "INFLATE_CHUNK_SIMD_NEON" ]
134    if (current_cpu == "arm64") {
135      defines += [ "INFLATE_CHUNK_READ_64LE" ]
136    }
137  }
138}
139
140source_set("zlib_inflate_chunk_simd") {
141  visibility = [ ":*" ]
142
143  if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
144    include_dirs = [ "." ]
145
146    sources = [
147      "contrib/optimizations/chunkcopy.h",
148      "contrib/optimizations/inffast_chunk.c",
149      "contrib/optimizations/inffast_chunk.h",
150      "contrib/optimizations/inflate.c",
151    ]
152
153    if (use_arm_neon_optimizations && !is_debug) {
154      # Here we trade better performance on newer/bigger ARMv8 cores
155      # for less perf on ARMv7, per crbug.com/772870#c40
156      configs -= [ "//build/config/compiler:default_optimization" ]
157      configs += [ "//build/config/compiler:optimize_speed" ]
158    }
159  }
160
161  configs -= [ "//build/config/compiler:chromium_code" ]
162  configs += [
163    ":zlib_internal_config",
164    "//build/config/compiler:no_chromium_code",
165  ]
166
167  public_configs = [ ":zlib_inflate_chunk_simd_config" ]
168}
169
170config("zlib_crc32_simd_config") {
171  if (use_x86_x64_optimizations) {
172    defines = [ "CRC32_SIMD_SSE42_PCLMUL" ]
173  }
174}
175
176source_set("zlib_crc32_simd") {
177  visibility = [ ":*" ]
178
179  if (use_x86_x64_optimizations) {
180    sources = [
181      "crc32_simd.c",
182      "crc32_simd.h",
183    ]
184
185    if (!is_win || is_clang) {
186      cflags = [
187        "-msse4.2",
188        "-mpclmul",
189      ]
190    }
191  }
192
193  configs += [ ":zlib_internal_config" ]
194
195  public_configs = [ ":zlib_crc32_simd_config" ]
196}
197
198source_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 -= [ "//build/config/compiler:chromium_code" ]
216  configs += [
217    ":zlib_internal_config",
218    "//build/config/compiler:no_chromium_code",
219  ]
220}
221
222config("zlib_warnings") {
223  if (is_clang && use_x86_x64_optimizations) {
224    cflags = [ "-Wno-incompatible-pointer-types" ]
225  }
226}
227
228component("zlib") {
229  if (!is_win) {
230    # Don't stomp on "libzlib" on other platforms.
231    output_name = "chrome_zlib"
232  }
233
234  sources = [
235    "adler32.c",
236    "chromeconf.h",
237    "compress.c",
238    "contrib/optimizations/insert_string.h",
239    "cpu_features.c",
240    "cpu_features.h",
241    "crc32.c",
242    "crc32.h",
243    "deflate.c",
244    "deflate.h",
245    "gzclose.c",
246    "gzguts.h",
247    "gzlib.c",
248    "gzread.c",
249    "gzwrite.c",
250    "infback.c",
251    "inffast.c",
252    "inffast.h",
253    "inffixed.h",
254    "inflate.h",
255    "inftrees.c",
256    "inftrees.h",
257    "trees.c",
258    "trees.h",
259    "uncompr.c",
260    "zconf.h",
261    "zlib.h",
262    "zutil.c",
263    "zutil.h",
264  ]
265
266  defines = []
267  deps = []
268  if (!use_x86_x64_optimizations && !use_arm_neon_optimizations) {
269    # Apparently android_cronet bot builds with NEON disabled and
270    # we also should disable optimizations for iOS@x86 (a.k.a. simulator).
271    defines += [ "CPU_NO_SIMD" ]
272  }
273
274  if (is_ios) {
275    # iOS@ARM is a special case where we always have NEON but don't check
276    # for crypto extensions.
277    # TODO(cavalcantii): verify what is the current state of CPU features shipped
278    # on latest iOS devices.
279    defines += [ "ARM_OS_IOS" ]
280  }
281
282  if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
283    deps += [
284      ":zlib_adler32_simd",
285      ":zlib_inflate_chunk_simd",
286    ]
287
288    if (use_x86_x64_optimizations) {
289      deps += [ ":zlib_crc32_simd" ]
290    } else if (use_arm_neon_optimizations) {
291      sources += [ "contrib/optimizations/slide_hash_neon.h" ]
292      deps += [ ":zlib_arm_crc32" ]
293    }
294  } else {
295    sources += [ "inflate.c" ]
296  }
297
298  if (is_android) {
299    import("//build/config/android/config.gni")
300    if (defined(android_ndk_root) && android_ndk_root != "") {
301      deps += [ "//third_party/android_ndk:cpu_features" ]
302    } else {
303      assert(false, "CPU detection requires the Android NDK")
304    }
305  }
306
307  configs -= [ "//build/config/compiler:chromium_code" ]
308  configs += [
309    ":zlib_internal_config",
310    "//build/config/compiler:no_chromium_code",
311
312    # Must be after no_chromium_code for warning flags to be ordered correctly.
313    ":zlib_warnings",
314  ]
315
316  public_configs = [ ":zlib_config" ]
317
318  deps += [ ":zlib_x86_simd" ]
319  allow_circular_includes_from = deps
320}
321
322config("minizip_warnings") {
323  visibility = [ ":*" ]
324
325  if (is_clang) {
326    # zlib uses `if ((a == b))` for some reason.
327    cflags = [ "-Wno-parentheses-equality" ]
328  }
329}
330
331static_library("minizip") {
332  sources = [
333    "contrib/minizip/ioapi.c",
334    "contrib/minizip/ioapi.h",
335    "contrib/minizip/iowin32.c",
336    "contrib/minizip/iowin32.h",
337    "contrib/minizip/unzip.c",
338    "contrib/minizip/unzip.h",
339    "contrib/minizip/zip.c",
340    "contrib/minizip/zip.h",
341  ]
342
343  if (!is_win) {
344    sources -= [
345      "contrib/minizip/iowin32.c",
346      "contrib/minizip/iowin32.h",
347    ]
348  }
349
350  if (is_mac || is_ios || is_android || is_nacl) {
351    # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
352    # use fopen, ftell, and fseek instead on these systems.
353    defines = [ "USE_FILE32API" ]
354  }
355
356  deps = [ ":zlib" ]
357
358  configs -= [ "//build/config/compiler:chromium_code" ]
359  configs += [
360    "//build/config/compiler:no_chromium_code",
361
362    # Must be after no_chromium_code for warning flags to be ordered correctly.
363    ":minizip_warnings",
364  ]
365
366  public_configs = [ ":zlib_config" ]
367}
368
369executable("zlib_bench") {
370  include_dirs = [ "." ]
371
372  sources = [ "contrib/bench/zlib_bench.cc" ]
373
374  if (!is_debug) {
375    configs -= [ "//build/config/compiler:default_optimization" ]
376    configs += [ "//build/config/compiler:optimize_speed" ]
377  }
378
379  configs -= [ "//build/config/compiler:chromium_code" ]
380  configs += [ "//build/config/compiler:no_chromium_code" ]
381
382  deps = [ ":zlib" ]
383}
384