1// Copyright (C) 2018 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14// 15 16package { 17 default_applicable_licenses: ["Android-Apache-2.0"], 18} 19 20python_binary_host { 21 name: "gen_intrinsics", 22 main: "gen_intrinsics.py", 23 srcs: ["gen_intrinsics.py"], 24 libs: ["asm_defs_lib"], 25} 26 27python_library_host { 28 name: "gen_intrinsics_lib", 29 srcs: ["gen_intrinsics.py"], 30} 31 32python_test_host { 33 name: "gen_intrinsics_tests", 34 main: "gen_intrinsics_test.py", 35 srcs: [ 36 "gen_intrinsics_test.py", 37 "gen_intrinsics.py", 38 ], 39 libs: ["asm_defs_lib"], 40 test_suites: ["device-tests"], 41 test_options: { 42 unit_test: true, 43 }, 44} 45 46genrule { 47 name: "libberberis_text_assembler_gen_headers_x86_32", 48 out: [ 49 "gen_text_assembler_common_x86-inl.h", 50 "gen_text_assembler_x86_32-inl.h", 51 ], 52 srcs: [":libberberis_assembler_gen_inputs_x86_32"], 53 tools: ["gen_asm_x86"], 54 cmd: "$(location gen_asm_x86) --text-assembler $(out) $(in)", 55} 56 57genrule { 58 name: "libberberis_text_assembler_gen_headers_x86_64", 59 out: [ 60 "gen_text_assembler_common_x86-inl.h", 61 "gen_text_assembler_x86_64-inl.h", 62 ], 63 srcs: [":libberberis_assembler_gen_inputs_x86_64"], 64 tools: ["gen_asm_x86"], 65 cmd: "$(location gen_asm_x86) --text-assembler $(out) $(in)", 66} 67 68filegroup { 69 name: "libberberis_intrinsics_gen_inputs_riscv64_to_x86_64", 70 srcs: ["riscv64_to_x86_64/intrinsic_def.json"], 71} 72 73filegroup { 74 name: "libberberis_machine_ir_intrinsic_binding_riscv64_to_x86_64", 75 srcs: ["riscv64_to_x86_64/machine_ir_intrinsic_binding.json"], 76} 77 78filegroup { 79 name: "libberberis_macro_assembler_gen_inputs_riscv64_to_x86_64", 80 srcs: ["riscv64_to_x86_64/macro_def.json"], 81} 82 83filegroup { 84 name: "dummy_gen_text_asm_intrinsics_srcs", 85 srcs: ["dummy_gen_text_asm_intrinsics.cc"], 86} 87 88filegroup { 89 name: "gen_text_asm_intrinsics_srcs", 90 srcs: ["common_to_x86/gen_text_asm_intrinsics.cc"], 91} 92 93genrule { 94 name: "libberberis_intrinsics_gen_inline_headers_riscv64_to_x86_64", 95 out: ["berberis/intrinsics/intrinsics.h"], 96 srcs: [], 97 tools: ["gen_riscv64_to_x86_64_intrinsics"], 98 cmd: "$(location gen_riscv64_to_x86_64_intrinsics) $(out)", 99} 100 101genrule { 102 name: "libberberis_macro_assembler_gen_intrinsics_headers_riscv64_to_x86_64", 103 out: ["text_asm_intrinsics_process_bindings-inl.h"], 104 srcs: [ 105 ":libberberis_intrinsics_gen_inputs_riscv64_to_x86_64", 106 ":libberberis_machine_ir_intrinsic_binding_riscv64_to_x86_64", 107 ":libberberis_macro_assembler_gen_inputs_riscv64_to_x86_64", 108 ":libberberis_assembler_gen_inputs_x86_64", 109 ], 110 tools: ["gen_intrinsics"], 111 cmd: "$(location gen_intrinsics) --text_asm_intrinsics_bindings $(out) $(in)", 112} 113 114genrule { 115 name: "libberberis_intrinsics_gen_public_headers_riscv64_to_x86_64", 116 out: [ 117 "berberis/intrinsics/intrinsics-inl.h", 118 "berberis/intrinsics/intrinsics_process_bindings-inl.h", 119 "berberis/intrinsics/interpreter_intrinsics_hooks-inl.h", 120 "berberis/intrinsics/translator_intrinsics_hooks-inl.h", 121 "berberis/intrinsics/mock_semantics_listener_intrinsics_hooks-inl.h", 122 ], 123 srcs: [ 124 ":libberberis_intrinsics_gen_inputs_riscv64_to_x86_64", 125 ":libberberis_machine_ir_intrinsic_binding_riscv64_to_x86_64", 126 ":libberberis_macro_assembler_gen_inputs_riscv64_to_x86_64", 127 ":libberberis_assembler_gen_inputs_x86_64", 128 ], 129 tools: ["gen_intrinsics"], 130 cmd: "$(location gen_intrinsics) --public_headers $(out) $(in)", 131} 132 133genrule { 134 name: "libberberis_macro_assembler_gen_headers_riscv64_to_x86_64", 135 out: ["berberis/intrinsics/macro_assembler_interface-inl.h"], 136 srcs: [":libberberis_macro_assembler_gen_inputs_riscv64_to_x86_64"], 137 tools: ["gen_asm_x86"], 138 cmd: "$(location gen_asm_x86) --binary-assembler $(out) $(in)", 139} 140 141// Note: the following two genrules and this host binary are working together. 142// 143// gen_riscv64_to_x86_64_intrinsics is C++ program, generated by python script, 144// which does not accept any inputs and produces berberis/intrinsics/intrinsics.h 145// 146// Other modules are not supposed to use gen_riscv64_to_x86_64_intrinsics, they should only 147// depend on libberberis_intrinsics_gen_asm_impl_headers_riscv64_to_x86_64 148// 149// So with 64-bit RISC V headers we have two-step operation: 150// 151// gen_intrinsics 152// -> text_asm_intrinsics_process_bindings-inl.h 153// -> gen_riscv64_to_x86_64_intrinsics 154// -> libberberis_intrinsics_gen_asm_impl_headers_riscv64_to_x86_64 155// 156// Compare to single-step generation of common headers: 157// 158// gen_intrinsics 159// -> libberberis_intrinsics_gen_public_headers_riscv64_to_x86_64 160 161cc_binary_host { 162 name: "gen_riscv64_to_x86_64_intrinsics", 163 defaults: ["gen_text_asm_intrinsics_defaults"], 164 local_include_dirs: ["riscv64_to_x86_64"], 165 target: { 166 linux: { 167 generated_headers: [ 168 "libberberis_intrinsics_gen_public_headers_riscv64_to_x86_64", 169 "libberberis_macro_assembler_gen_intrinsics_headers_riscv64_to_x86_64", 170 "libberberis_text_assembler_gen_headers_x86_64", 171 ], 172 header_libs: ["libberberis_macro_assembler_headers_riscv64_to_x86_64"], 173 static_libs: ["libberberis_macro_assembler_riscv64_to_x86_64"], 174 }, 175 }, 176} 177 178cc_defaults { 179 name: "gen_text_asm_intrinsics_defaults", 180 // Note: build system would pick the build OS variant. 181 // Usually that's 64-bit version thus we can only support 64bit version here. 182 // Currently none of Android builds that we care about used 32bit version of host tools. 183 defaults: ["berberis_defaults_64"], 184 host_supported: true, 185 header_libs: ["libberberis_intrinsics_headers"], 186 // Note: since this tool is used in genrule, it has to be buildable and 187 // available on all platforms unconditionally. 188 // 189 // Since we don't support MacOS build for the rest of berberis we are providing 190 // a "dummy" version on non-linux platform: it would always generate empty header. 191 // 192 // That version does not need any internal headers, libraries or sources, 193 // thus we use conditional dependencies only on linux platform here. 194 target: { 195 darwin: { 196 enabled: true, 197 srcs: [":dummy_gen_text_asm_intrinsics_srcs"], 198 }, 199 linux: { 200 // We are only ever executing that binary once, it's faster to build it without 201 // optimizations and spend half-second more running it, than spend tens of seconds 202 // optimizing the code to save that half-second. 203 cflags: ["-O0"], 204 srcs: [":gen_text_asm_intrinsics_srcs"], 205 header_libs: [ 206 "libberberis_base_headers", 207 "libberberis_runtime_primitives_headers", 208 ], 209 shared_libs: ["liblog"], 210 }, 211 }, 212 // Targets using these defaults must provide the following guest-specific fields on linux: 213 // generated_header: [ 214 // "libberberis_intrinsics_gen_public_headers_<guest>_to_<host>", 215 // "libberberis_text_assembler_gen_headers_<guest>_to_<host>", 216 // ], 217 // header_libs: [ "libberberis_macro_assembler_headers_<guest>_to_<host>" ], 218 // static_libs: [ "libberberis_macro_assembler_<guest>_to_<host>" ], 219} 220 221cc_library_headers { 222 name: "libberberis_intrinsics_riscv64_headers", 223 defaults: ["berberis_defaults"], 224 host_supported: true, 225 header_libs: [ 226 "libberberis_base_headers", 227 "libberberis_intrinsics_headers", 228 "libberberis_runtime_primitives_headers", // for platform.h 229 ], 230 export_header_lib_headers: [ 231 "libberberis_base_headers", 232 "libberberis_intrinsics_headers", 233 "libberberis_runtime_primitives_headers", // for platform.h 234 ], 235 arch: { 236 x86_64: { 237 generated_headers: [ 238 "libberberis_intrinsics_gen_inline_headers_riscv64_to_x86_64", 239 "libberberis_intrinsics_gen_public_headers_riscv64_to_x86_64", 240 ], 241 export_generated_headers: [ 242 "libberberis_intrinsics_gen_inline_headers_riscv64_to_x86_64", 243 "libberberis_intrinsics_gen_public_headers_riscv64_to_x86_64", 244 ], 245 export_include_dirs: [ 246 "riscv64_to_x86_64/include", 247 "riscv64/include", 248 ], 249 }, 250 }, 251} 252 253cc_library_headers { 254 name: "libberberis_intrinsics_headers", 255 defaults: ["berberis_defaults"], 256 host_supported: true, 257 export_include_dirs: ["include"], 258 header_libs: ["libberberis_base_headers"], 259 export_header_lib_headers: ["libberberis_base_headers"], 260 arch: { 261 x86: { 262 export_include_dirs: [ 263 "common_to_x86/include", 264 ], 265 }, 266 x86_64: { 267 export_include_dirs: [ 268 "common_to_x86/include", 269 ], 270 }, 271 }, 272} 273 274cc_library_static { 275 name: "libberberis_intrinsics", 276 defaults: ["berberis_defaults"], 277 host_supported: true, 278 header_libs: ["libberberis_intrinsics_riscv64_headers"], 279 static_libs: ["libberberis_base"], 280 export_header_lib_headers: ["libberberis_intrinsics_riscv64_headers"], 281} 282 283cc_library_headers { 284 name: "libberberis_macro_assembler_headers_riscv64_to_x86_64", 285 defaults: ["berberis_defaults_64"], 286 host_supported: true, 287 export_include_dirs: [ 288 "riscv64_to_x86_64/include", 289 "riscv64/include", 290 "common_to_x86/include", 291 "include", 292 ], 293 header_libs: [ 294 "libberberis_base_headers", 295 "libberberis_intrinsics_headers", 296 ], 297 export_header_lib_headers: [ 298 "libberberis_base_headers", 299 "libberberis_intrinsics_headers", 300 ], 301 generated_headers: ["libberberis_macro_assembler_gen_headers_riscv64_to_x86_64"], 302 export_generated_headers: ["libberberis_macro_assembler_gen_headers_riscv64_to_x86_64"], 303} 304 305cc_library_static { 306 name: "libberberis_macro_assembler_riscv64_to_x86_64", 307 defaults: ["berberis_defaults_64"], 308 host_supported: true, 309 srcs: ["riscv64_to_x86_64/macro_assembler.cc"], 310 header_libs: ["libberberis_macro_assembler_headers_riscv64_to_x86_64"], 311} 312 313cc_library_static { 314 name: "libberberis_intrinsics_riscv64", 315 defaults: ["berberis_defaults_64"], 316 host_supported: true, 317 srcs: [ 318 "riscv64/intrinsics.cc", 319 "riscv64/vector_intrinsics.cc", 320 ], 321 header_libs: [ 322 "libberberis_base_headers", 323 "libberberis_intrinsics_riscv64_headers", 324 ], 325 export_header_lib_headers: [ 326 "libberberis_base_headers", 327 "libberberis_intrinsics_riscv64_headers", 328 ], 329} 330 331cc_test_library { 332 name: "libberberis_intrinsics_unit_tests", 333 defaults: ["berberis_defaults"], 334 host_supported: true, 335 arch: { 336 x86: { 337 srcs: [ 338 "common_to_x86/intrinsics_float_test.cc", 339 "common_to_x86/simd_register_test.cc", 340 ], 341 }, 342 x86_64: { 343 cflags: ["-mssse3"], 344 srcs: [ 345 "common_to_x86/intrinsics_float_test.cc", 346 "common_to_x86_64/tuple_test.cc", 347 // Note that these two tests technically should work on any platform that supports 348 // risv64 to something translation, but currently that's only x86-64. 349 "riscv64/intrinsics_test.cc", 350 "riscv64/vector_intrinsics_test.cc", 351 ], 352 }, 353 }, 354 static_libs: [ 355 "libberberis_base", 356 "libberberis_intrinsics", 357 ], 358 shared: { 359 enabled: false, 360 }, 361} 362