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
14#include <stdint.h>
15
16namespace LIBC_NAMESPACE {
17
18// The ROCm device library uses control globals to alter codegen for the
19// different targets. To avoid needing to link them in manually we simply
20// define them here.
21extern "C" {
22
23// Disable unsafe math optimizations in the implementation.
24extern const LIBC_INLINE_VAR uint8_t __oclc_unsafe_math_opt = 0;
25
26// Disable denormalization at zero optimizations in the implementation.
27extern const LIBC_INLINE_VAR uint8_t __oclc_daz_opt = 0;
28
29// Disable rounding optimizations for 32-bit square roots.
30extern const LIBC_INLINE_VAR uint8_t __oclc_correctly_rounded_sqrt32 = 1;
31
32// Disable finite math optimizations.
33extern const LIBC_INLINE_VAR uint8_t __oclc_finite_only_opt = 0;
34
35// Set the ISA value to a high enough value that the ROCm device library math
36// functions will assume we have fast FMA operations among other features. This
37// is determined to be safe on all targets by looking at the source code.
38// https://github.com/ROCm/ROCm-Device-Libs/blob/amd-stg-open/ocml/src/opts.h
39extern const LIBC_INLINE_VAR uint32_t __oclc_ISA_version = 9000;
40}
41
42// These aliases cause clang to emit the control constants with ODR linkage.
43// This allows us to link against the symbols without preventing them from being
44// optimized out or causing symbol collisions.
45[[gnu::alias("__oclc_unsafe_math_opt")]] const uint8_t __oclc_unsafe_math_opt__;
46[[gnu::alias("__oclc_daz_opt")]] const uint8_t __oclc_daz_opt__;
47[[gnu::alias("__oclc_correctly_rounded_sqrt32")]] const uint8_t
48 __oclc_correctly_rounded_sqrt32__;
49[[gnu::alias("__oclc_finite_only_opt")]] const uint8_t __oclc_finite_only_opt__;
50[[gnu::alias("__oclc_ISA_version")]] const uint32_t __oclc_ISA_version__;
51
52} // namespace LIBC_NAMESPACE
53
54#endif // LLVM_LIBC_SRC_MATH_AMDGPU_PLATFORM_H
55

source code of libc/src/math/amdgpu/platform.h