Skip to content

Commit c9c1068

Browse files
committed
[libc][math][c23] Add llroundf16 C23 math function
1 parent 30cd537 commit c9c1068

File tree

10 files changed

+86
-1
lines changed

10 files changed

+86
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
503503
libc.src.math.fabsf16
504504
libc.src.math.floorf16
505505
libc.src.math.llrintf16
506+
libc.src.math.llroundf16
506507
libc.src.math.lrintf16
507508
libc.src.math.lroundf16
508509
libc.src.math.nearbyintf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
536536
libc.src.math.fabsf16
537537
libc.src.math.floorf16
538538
libc.src.math.llrintf16
539+
libc.src.math.llroundf16
539540
libc.src.math.lrintf16
540541
libc.src.math.lroundf16
541542
libc.src.math.nearbyintf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Basic Operations
176176
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
177177
| llrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
178178
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
179-
| llround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 |
179+
| llround | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
180180
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
181181
| logb | |check| | |check| | |check| | | |check| | 7.12.6.17 | F.10.3.17 |
182182
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def StdC : StandardSpec<"stdc"> {
585585
FunctionSpec<"llround", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,
586586
FunctionSpec<"llroundf", RetValSpec<LongLongType>, [ArgSpec<FloatType>]>,
587587
FunctionSpec<"llroundl", RetValSpec<LongLongType>, [ArgSpec<LongDoubleType>]>,
588+
GuardedFunctionSpec<"llroundf16", RetValSpec<LongLongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
588589
GuardedFunctionSpec<"llroundf128", RetValSpec<LongLongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
589590

590591
FunctionSpec<"rint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ add_math_entrypoint_object(llrintf128)
231231
add_math_entrypoint_object(llround)
232232
add_math_entrypoint_object(llroundf)
233233
add_math_entrypoint_object(llroundl)
234+
add_math_entrypoint_object(llroundf16)
234235
add_math_entrypoint_object(llroundf128)
235236

236237
add_math_entrypoint_object(lrint)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,19 @@ add_entrypoint_object(
626626
libc.src.__support.FPUtil.nearest_integer_operations
627627
)
628628

629+
add_entrypoint_object(
630+
llroundf16
631+
SRCS
632+
llroundf16.cpp
633+
HDRS
634+
../llroundf16.h
635+
COMPILE_OPTIONS
636+
-O3
637+
DEPENDS
638+
libc.src.__support.macros.properties.types
639+
libc.src.__support.FPUtil.nearest_integer_operations
640+
)
641+
629642
add_entrypoint_object(
630643
llroundf128
631644
SRCS

libc/src/math/generic/llroundf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of llroundf16 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/llroundf16.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, llroundf16, (float16 x)) {
16+
return fputil::round_to_signed_integer<float128, long long>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/llroundf16.h

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,22 @@ add_fp_unittest(
625625
libc.src.__support.FPUtil.fp_bits
626626
)
627627

628+
add_fp_unittest(
629+
llroundf16_test
630+
SUITE
631+
libc-math-smoke-tests
632+
SRCS
633+
llroundf16_test.cpp
634+
HDRS
635+
RoundToIntegerTest.h
636+
DEPENDS
637+
libc.src.errno.errno
638+
libc.src.math.llroundf16
639+
libc.src.__support.CPP.algorithm
640+
libc.src.__support.FPUtil.fenv_impl
641+
libc.src.__support.FPUtil.fp_bits
642+
)
643+
628644
add_fp_unittest(
629645
llroundf128_test
630646
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for llroundf16 ------------------------------------------===//
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/llroundf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)

0 commit comments

Comments
 (0)