1# Copyright 2017 The Chromium Authors 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/features.gni") 6import("//testing/test.gni") 7import("//third_party/google_benchmark/buildconfig.gni") 8 9# Only applied to CRC32C source and tests. (not exported) 10config("crc32c_config") { 11 visibility = [ ":*" ] 12 13 include_dirs = [ 14 "config", 15 "src/include", 16 ] 17 18 defines = [ 19 "BYTE_ORDER_BIG_ENDIAN=0", 20 "CRC32C_TESTS_BUILT_WITH_GLOG=0", 21 ] 22 23 # If we ever support big-endian builds, add logic to conditionally enable 24 # BYTE_ORDER_BIG_ENDIAN. 25 26 if (current_cpu == "x86" || current_cpu == "x64") { 27 defines += [ 28 "HAVE_MM_PREFETCH=1", 29 "HAVE_SSE42=1", 30 ] 31 } else { 32 defines += [ 33 "HAVE_MM_PREFETCH=0", 34 "HAVE_SSE42=0", 35 ] 36 } 37 if (is_clang || !is_win) { 38 defines += [ "HAVE_BUILTIN_PREFETCH=1" ] 39 } else { 40 defines += [ "HAVE_BUILTIN_PREFETCH=0" ] 41 } 42 43 if (current_cpu == "arm64") { 44 defines += [ "HAVE_ARM64_CRC32C=1" ] 45 } else { 46 defines += [ "HAVE_ARM64_CRC32C=0" ] 47 } 48 49 # Android added <sys/auxv.h> in API level 18. 50 if (is_linux || is_chromeos || is_android) { 51 defines += [ 52 "HAVE_STRONG_GETAUXVAL=1", 53 "HAVE_WEAK_GETAUXVAL=1", 54 ] 55 } else { 56 defines += [ 57 "HAVE_STRONG_GETAUXVAL=0", 58 "HAVE_WEAK_GETAUXVAL=0", 59 ] 60 } 61} 62 63source_set("crc32c") { 64 sources = [ 65 "src/include/crc32c/crc32c.h", 66 "src/src/crc32c.cc", 67 "src/src/crc32c_portable.cc", 68 ] 69 70 configs += [ ":crc32c_config" ] 71 deps = [ 72 ":crc32c_arm64", 73 ":crc32c_internal_headers", 74 ":crc32c_sse42", 75 ] 76} 77 78source_set("crc32c_sse42") { 79 visibility = [ ":*" ] 80 81 sources = [ 82 "src/src/crc32c_sse42.cc", 83 "src/src/crc32c_sse42.h", 84 "src/src/crc32c_sse42_check.h", 85 ] 86 87 configs += [ ":crc32c_config" ] 88 if (current_cpu == "x86" || current_cpu == "x64") { 89 if (is_win && !is_clang) { 90 cflags = [ "/arch:AVX" ] 91 } else { 92 cflags = [ "-msse4.2" ] 93 } 94 } 95 96 deps = [ ":crc32c_internal_headers" ] 97} 98 99source_set("crc32c_arm64") { 100 visibility = [ ":*" ] 101 102 sources = [ 103 "src/src/crc32c_arm64.cc", 104 "src/src/crc32c_arm64.h", 105 "src/src/crc32c_arm64_check.h", 106 ] 107 108 configs += [ ":crc32c_config" ] 109 if (current_cpu == "arm64") { 110 if (is_clang) { 111 cflags = [ 112 "-march=armv8-a", 113 114 # Some builds set -march to a different value from the above. 115 # The specific feature flags below enable the instructions we need 116 # in these cases. See https://crbug.com/934016 for example. 117 "-Xclang", 118 "-target-feature", 119 "-Xclang", 120 "+crc", 121 "-Xclang", 122 "-target-feature", 123 "-Xclang", 124 "+crypto", 125 ] 126 } else { 127 cflags = [ "-march=armv8-a+crc+crypto" ] 128 } 129 } 130 131 deps = [ ":crc32c_internal_headers" ] 132} 133 134source_set("crc32c_internal_headers") { 135 sources = [ 136 "config/crc32c/crc32c_config.h", 137 "src/src/crc32c_internal.h", 138 "src/src/crc32c_prefetch.h", 139 "src/src/crc32c_read_le.h", 140 "src/src/crc32c_round_up.h", 141 ] 142} 143 144test("crc32c_tests") { 145 sources = [ 146 "src/src/crc32c_arm64_unittest.cc", 147 "src/src/crc32c_extend_unittests.h", 148 "src/src/crc32c_portable_unittest.cc", 149 "src/src/crc32c_prefetch_unittest.cc", 150 "src/src/crc32c_read_le_unittest.cc", 151 "src/src/crc32c_round_up_unittest.cc", 152 "src/src/crc32c_sse42_unittest.cc", 153 "src/src/crc32c_unittest.cc", 154 ] 155 156 configs += [ ":crc32c_config" ] 157 deps = [ 158 ":crc32c", 159 ":crc32c_arm64", 160 ":crc32c_internal_headers", 161 ":crc32c_sse42", 162 "//testing/gtest:gtest_main", 163 "//third_party/googletest:gtest", 164 ] 165} 166 167if (enable_google_benchmarks) { 168 test("crc32c_benchmark") { 169 sources = [ "src/src/crc32c_benchmark.cc" ] 170 configs += [ ":crc32c_config" ] 171 deps = [ 172 ":crc32c", 173 ":crc32c_arm64", 174 ":crc32c_internal_headers", 175 ":crc32c_sse42", 176 "//third_party/google_benchmark", 177 ] 178 } 179} 180