xref: /llvm-project/libc/src/math/generic/fabsf16.cpp (revision 70843bf658004cc6997e4978e625140abce77427)
10eb9e021SOverMighty //===-- Implementation of fabsf16 function --------------------------------===//
20eb9e021SOverMighty //
30eb9e021SOverMighty // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40eb9e021SOverMighty // See https://llvm.org/LICENSE.txt for license information.
50eb9e021SOverMighty // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60eb9e021SOverMighty //
70eb9e021SOverMighty //===----------------------------------------------------------------------===//
80eb9e021SOverMighty 
90eb9e021SOverMighty #include "src/math/fabsf16.h"
100eb9e021SOverMighty #include "src/__support/FPUtil/BasicOperations.h"
110eb9e021SOverMighty #include "src/__support/common.h"
125ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
13*70843bf6SOverMighty #include "src/__support/macros/properties/architectures.h"
14*70843bf6SOverMighty #include "src/__support/macros/properties/compiler.h"
150eb9e021SOverMighty 
165ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
170eb9e021SOverMighty 
18*70843bf6SOverMighty LLVM_LIBC_FUNCTION(float16, fabsf16, (float16 x)) {
19*70843bf6SOverMighty   // For x86, GCC generates better code from the generic implementation.
20*70843bf6SOverMighty   // https://godbolt.org/z/K9orM4hTa
21*70843bf6SOverMighty #if defined(__LIBC_MISC_MATH_BASIC_OPS_OPT) &&                                 \
22*70843bf6SOverMighty     !(defined(LIBC_TARGET_ARCH_IS_X86) && defined(LIBC_COMPILER_IS_GCC))
23*70843bf6SOverMighty   return __builtin_fabsf16(x);
24*70843bf6SOverMighty #else
25*70843bf6SOverMighty   return fputil::abs(x);
26*70843bf6SOverMighty #endif
27*70843bf6SOverMighty }
280eb9e021SOverMighty 
295ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
30