1 | //===-- Implementation of fabsf16 function --------------------------------===// |
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 | #include "src/math/fabsf16.h" |
10 | #include "src/__support/FPUtil/BasicOperations.h" |
11 | #include "src/__support/common.h" |
12 | #include "src/__support/macros/config.h" |
13 | #include "src/__support/macros/properties/architectures.h" |
14 | #include "src/__support/macros/properties/compiler.h" |
15 | |
16 | namespace LIBC_NAMESPACE_DECL { |
17 | |
18 | LLVM_LIBC_FUNCTION(float16, fabsf16, (float16 x)) { |
19 | // For x86, GCC generates better code from the generic implementation. |
20 | // https://godbolt.org/z/K9orM4hTa |
21 | #if defined(__LIBC_MISC_MATH_BASIC_OPS_OPT) && \ |
22 | !(defined(LIBC_TARGET_ARCH_IS_X86) && defined(LIBC_COMPILER_IS_GCC)) |
23 | return __builtin_fabsf16(x); |
24 | #else |
25 | return fputil::abs(x); |
26 | #endif |
27 | } |
28 | |
29 | } // namespace LIBC_NAMESPACE_DECL |
30 | |