1 //===-- AMDGPU specific platform definitions for math support -------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_SRC_MATH_AMDGPU_PLATFORM_H 10 #define LLVM_LIBC_SRC_MATH_AMDGPU_PLATFORM_H 11 12 #include "src/__support/macros/attributes.h" 13 #include "src/__support/macros/config.h" 14 15 #include <stdint.h> 16 17 namespace LIBC_NAMESPACE_DECL { 18 19 // The ROCm device library uses control globals to alter codegen for the 20 // different targets. To avoid needing to link them in manually we simply 21 // define them here. 22 extern "C" { 23 24 // Disable unsafe math optimizations in the implementation. 25 extern const LIBC_INLINE_VAR uint8_t __oclc_unsafe_math_opt = 0; 26 27 // Disable denormalization at zero optimizations in the implementation. 28 extern const LIBC_INLINE_VAR uint8_t __oclc_daz_opt = 0; 29 30 // Disable rounding optimizations for 32-bit square roots. 31 extern const LIBC_INLINE_VAR uint8_t __oclc_correctly_rounded_sqrt32 = 1; 32 33 // Disable finite math optimizations. 34 extern const LIBC_INLINE_VAR uint8_t __oclc_finite_only_opt = 0; 35 36 // Set the ISA value to a high enough value that the ROCm device library math 37 // functions will assume we have fast FMA operations among other features. This 38 // is determined to be safe on all targets by looking at the source code. 39 // https://github.com/ROCm/ROCm-Device-Libs/blob/amd-stg-open/ocml/src/opts.h 40 extern const LIBC_INLINE_VAR uint32_t __oclc_ISA_version = 9000; 41 } 42 43 // These aliases cause clang to emit the control constants with ODR linkage. 44 // This allows us to link against the symbols without preventing them from being 45 // optimized out or causing symbol collisions. 46 [[gnu::alias("__oclc_unsafe_math_opt")]] const uint8_t __oclc_unsafe_math_opt__; 47 [[gnu::alias("__oclc_daz_opt")]] const uint8_t __oclc_daz_opt__; 48 [[gnu::alias("__oclc_correctly_rounded_sqrt32")]] const uint8_t 49 __oclc_correctly_rounded_sqrt32__; 50 [[gnu::alias("__oclc_finite_only_opt")]] const uint8_t __oclc_finite_only_opt__; 51 [[gnu::alias("__oclc_ISA_version")]] const uint32_t __oclc_ISA_version__; 52 53 } // namespace LIBC_NAMESPACE_DECL 54 55 #endif // LLVM_LIBC_SRC_MATH_AMDGPU_PLATFORM_H 56