| 1 | //===-- Implementation header for truncf16 ----------------------*- 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_TRUNCF16_H |
| 10 | #define LLVM_LIBC_SRC___SUPPORT_MATH_TRUNCF16_H |
| 11 | |
| 12 | #include "include/llvm-libc-macros/float16-macros.h" |
| 13 | |
| 14 | #ifdef LIBC_TYPES_HAS_FLOAT16 |
| 15 | |
| 16 | #include "src/__support/FPUtil/NearestIntegerOperations.h" |
| 17 | #include "src/__support/FPUtil/cast.h" |
| 18 | #include "src/__support/macros/config.h" |
| 19 | #include "src/__support/macros/properties/cpu_features.h" |
| 20 | |
| 21 | namespace LIBC_NAMESPACE_DECL { |
| 22 | namespace math { |
| 23 | |
| 24 | LIBC_INLINE LIBC_CONSTEXPR float16 truncf16(float16 x) { |
| 25 | #if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \ |
| 26 | defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS) && \ |
| 27 | !defined(LIBC_USE_CONSTEXPR) |
| 28 | return fputil::cast<float16>(__builtin_truncf(x)); |
| 29 | #else |
| 30 | return fputil::trunc(x); |
| 31 | #endif |
| 32 | } |
| 33 | |
| 34 | } // namespace math |
| 35 | } // namespace LIBC_NAMESPACE_DECL |
| 36 | |
| 37 | #endif // LIBC_TYPES_HAS_FLOAT16 |
| 38 | |
| 39 | #endif // LLVM_LIBC_SRC___SUPPORT_MATH_TRUNCF16_H |
| 40 |