[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / FPUtil / aarch64 / FMA.h
blob5f80ed737ef278dfef5cab21399267531c4aba9f
1 //===-- Aarch64 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_AARCH64_FMA_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H
12 #include "src/__support/macros/properties/architectures.h"
13 #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
15 #if !defined(LIBC_TARGET_ARCH_IS_AARCH64)
16 #error "Invalid include"
17 #endif
19 #if !defined(LIBC_TARGET_CPU_HAS_FMA)
20 #error "FMA instructions are not supported"
21 #endif
23 #include "src/__support/CPP/type_traits.h"
25 namespace __llvm_libc {
26 namespace fputil {
28 template <typename T>
29 cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
30 float result;
31 __asm__ __volatile__("fmadd %s0, %s1, %s2, %s3\n\t"
32 : "=w"(result)
33 : "w"(x), "w"(y), "w"(z));
34 return result;
37 template <typename T>
38 cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
39 double result;
40 __asm__ __volatile__("fmadd %d0, %d1, %d2, %d3\n\t"
41 : "=w"(result)
42 : "w"(x), "w"(y), "w"(z));
43 return result;
46 } // namespace fputil
47 } // namespace __llvm_libc
49 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H