[libc][NFC] Move aligned access implementations to separate header
[llvm-project.git] / libc / src / __support / FPUtil / gpu / FMA.h
blob2828dfe538598490c3d6c3225887afdf742235e2
1 //===-- GPU implementations of the fma function -----------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H
12 #include "src/__support/CPP/type_traits.h"
13 #include "src/__support/macros/config.h"
15 // These intrinsics map to the FMA instrunctions in the target ISA for the GPU.
16 // The default rounding mode generated from these will be to the nearest even.
17 static_assert(LIBC_HAS_BUILTIN(__builtin_fma), "FMA builtins must be defined");
18 static_assert(LIBC_HAS_BUILTIN(__builtin_fmaf), "FMA builtins must be defined");
20 namespace __llvm_libc {
21 namespace fputil {
23 template <typename T>
24 LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
25 return __builtin_fmaf(x, y, z);
28 template <typename T>
29 LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
30 return __builtin_fma(x, y, z);
33 } // namespace fputil
34 } // namespace __llvm_libc
36 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H