[libc][NFC] Move aligned access implementations to separate header
[llvm-project.git] / libc / src / __support / FPUtil / multiply_add.h
blob2829ebb6d0047f5e29582a57021f42cdc1674d09
1 //===-- Common header for multiply-add implementations ----------*- 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_MULTIPLY_ADD_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/properties/architectures.h"
14 #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
16 namespace __llvm_libc {
17 namespace fputil {
19 // Implement a simple wrapper for multiply-add operation:
20 // multiply_add(x, y, z) = x*y + z
21 // which uses FMA instructions to speed up if available.
23 template <typename T> LIBC_INLINE T multiply_add(T x, T y, T z) {
24 return x * y + z;
27 } // namespace fputil
28 } // namespace __llvm_libc
30 #if defined(LIBC_TARGET_CPU_HAS_FMA)
32 // FMA instructions are available.
33 #include "FMA.h"
35 namespace __llvm_libc {
36 namespace fputil {
38 template <> LIBC_INLINE float multiply_add<float>(float x, float y, float z) {
39 return fma(x, y, z);
42 template <>
43 LIBC_INLINE double multiply_add<double>(double x, double y, double z) {
44 return fma(x, y, z);
47 } // namespace fputil
48 } // namespace __llvm_libc
50 #endif // LIBC_TARGET_CPU_HAS_FMA
52 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H