| 1 | //===-- Implementation header for fabsf16 -----------------------*- 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FABSF16_H |
| 10 | #define LLVM_LIBC_SRC___SUPPORT_MATH_FABSF16_H |
| 11 | |
| 12 | #include "include/llvm-libc-macros/float16-macros.h" |
| 13 | |
| 14 | #ifdef LIBC_TYPES_HAS_FLOAT16 |
| 15 | |
| 16 | #include "src/__support/FPUtil/BasicOperations.h" |
| 17 | #include "src/__support/macros/config.h" |
| 18 | #include "src/__support/macros/properties/architectures.h" |
| 19 | #include "src/__support/macros/properties/compiler.h" |
| 20 | |
| 21 | namespace LIBC_NAMESPACE_DECL { |
| 22 | namespace math { |
| 23 | |
| 24 | LIBC_INLINE constexpr float16 fabsf16(float16 x) { |
| 25 | if (cpp::is_constant_evaluated()) |
| 26 | return fputil::abs(x); |
| 27 | // For x86, GCC generates better code from the generic implementation. |
| 28 | // https://godbolt.org/z/K9orM4hTa |
| 29 | #if defined(__LIBC_MISC_MATH_BASIC_OPS_OPT) && \ |
| 30 | !(defined(LIBC_TARGET_ARCH_IS_X86) && defined(LIBC_COMPILER_IS_GCC)) |
| 31 | return __builtin_fabsf16(x); |
| 32 | #else |
| 33 | return fputil::abs(x); |
| 34 | #endif |
| 35 | } |
| 36 | |
| 37 | } // namespace math |
| 38 | } // namespace LIBC_NAMESPACE_DECL |
| 39 | |
| 40 | #endif // LIBC_TYPES_HAS_FLOAT16 |
| 41 | |
| 42 | #endif // LLVM_LIBC_SRC___SUPPORT_MATH_FABSF16_H |
| 43 |