Skip to content

Commit f4a9850

Browse files
committed
[libc][math][c23] Add llrintf16 C23 math function
1 parent a886cb8 commit f4a9850

File tree

10 files changed

+88
-1
lines changed

10 files changed

+88
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
502502
libc.src.math.ceilf16
503503
libc.src.math.fabsf16
504504
libc.src.math.floorf16
505+
libc.src.math.llrintf16
505506
libc.src.math.lrintf16
506507
libc.src.math.nearbyintf16
507508
libc.src.math.rintf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
535535
libc.src.math.ceilf16
536536
libc.src.math.fabsf16
537537
libc.src.math.floorf16
538+
libc.src.math.llrintf16
538539
libc.src.math.lrintf16
539540
libc.src.math.nearbyintf16
540541
libc.src.math.rintf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Basic Operations
174174
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
175175
| llogb | |check| | |check| | |check| | | |check| | 7.12.6.10 | F.10.3.10 |
176176
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
177-
| llrint | |check| | |check| | |check| | | |check| | 7.12.9.5 | F.10.6.5 |
177+
| llrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
178178
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
179179
| llround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 |
180180
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ def StdC : StandardSpec<"stdc"> {
601601
FunctionSpec<"llrint", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,
602602
FunctionSpec<"llrintf", RetValSpec<LongLongType>, [ArgSpec<FloatType>]>,
603603
FunctionSpec<"llrintl", RetValSpec<LongLongType>, [ArgSpec<LongDoubleType>]>,
604+
GuardedFunctionSpec<"llrintf16", RetValSpec<LongLongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
604605
GuardedFunctionSpec<"llrintf128", RetValSpec<LongLongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
605606

606607
FunctionSpec<"sqrt", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ add_math_entrypoint_object(logbf128)
225225
add_math_entrypoint_object(llrint)
226226
add_math_entrypoint_object(llrintf)
227227
add_math_entrypoint_object(llrintl)
228+
add_math_entrypoint_object(llrintf16)
228229
add_math_entrypoint_object(llrintf128)
229230

230231
add_math_entrypoint_object(llround)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,19 @@ add_entrypoint_object(
786786
libc.src.__support.FPUtil.nearest_integer_operations
787787
)
788788

789+
add_entrypoint_object(
790+
llrintf16
791+
SRCS
792+
llrintf16.cpp
793+
HDRS
794+
../llrintf16.h
795+
COMPILE_OPTIONS
796+
-O3
797+
DEPENDS
798+
libc.src.__support.macros.properties.types
799+
libc.src.__support.FPUtil.nearest_integer_operations
800+
)
801+
789802
add_entrypoint_object(
790803
llrintf128
791804
SRCS

libc/src/math/generic/llrintf16.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of llrintf16 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/llrintf16.h"
10+
#include "src/__support/FPUtil/NearestIntegerOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(long long, llrintf16, (float16 x)) {
16+
return fputil::round_to_signed_integer_using_current_rounding_mode<float128,
17+
long long>(
18+
x);
19+
}
20+
21+
} // namespace LIBC_NAMESPACE

libc/src/math/llrintf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for llrintf16 ---------------------*- 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_MATH_LLRINTF16_H
10+
#define LLVM_LIBC_SRC_MATH_LLRINTF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
long long llrintf16(float16 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_LLRINTF16_H

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,21 @@ add_fp_unittest(
831831
libc.src.__support.FPUtil.fp_bits
832832
)
833833

834+
add_fp_unittest(
835+
llrintf16_test
836+
SUITE
837+
libc-math-smoke-tests
838+
SRCS
839+
llrintf16_test.cpp
840+
HDRS
841+
RoundToIntegerTest.h
842+
DEPENDS
843+
libc.src.math.llrintf16
844+
libc.src.__support.CPP.algorithm
845+
libc.src.__support.FPUtil.fenv_impl
846+
libc.src.__support.FPUtil.fp_bits
847+
)
848+
834849
add_fp_unittest(
835850
llrintf128_test
836851
SUITE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Unittests for llrintf16 -------------------------------------------===//
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 "RoundToIntegerTest.h"
10+
11+
#include "src/math/llrintf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long long,
14+
LIBC_NAMESPACE::llrintf16)

0 commit comments

Comments
 (0)