xref: /llvm-project/libc/src/math/generic/rintf16.cpp (revision 127349fcba81646389e4b8202b35405a5fdbef47)
12635d041SOverMighty //===-- Implementation of rintf16 function --------------------------------===//
22635d041SOverMighty //
32635d041SOverMighty // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42635d041SOverMighty // See https://llvm.org/LICENSE.txt for license information.
52635d041SOverMighty // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62635d041SOverMighty //
72635d041SOverMighty //===----------------------------------------------------------------------===//
82635d041SOverMighty 
92635d041SOverMighty #include "src/math/rintf16.h"
102635d041SOverMighty #include "src/__support/FPUtil/NearestIntegerOperations.h"
11*127349fcSOverMighty #include "src/__support/FPUtil/cast.h"
122635d041SOverMighty #include "src/__support/common.h"
135ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1481ce7960SOverMighty #include "src/__support/macros/properties/cpu_features.h"
152635d041SOverMighty 
165ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
172635d041SOverMighty 
182635d041SOverMighty LLVM_LIBC_FUNCTION(float16, rintf16, (float16 x)) {
194531f82cSOverMighty #if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) &&                       \
2081ce7960SOverMighty     defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
21*127349fcSOverMighty   return fputil::cast<float16>(__builtin_rintf(x));
224531f82cSOverMighty #else
232635d041SOverMighty   return fputil::round_using_current_rounding_mode(x);
244531f82cSOverMighty #endif
252635d041SOverMighty }
262635d041SOverMighty 
275ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
28