Skip to content

Commit fdd290c

Browse files
committed
[libc][math][c23] Add llroundf16 C23 math function
1 parent 91623a2 commit fdd290c

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
@@ -501,6 +501,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
501501
# math.h C23 _Float16 entrypoints
502502
libc.src.math.fabsf16
503503
libc.src.math.llrintf16
504+
libc.src.math.llroundf16
504505
libc.src.math.lrintf16
505506
libc.src.math.lroundf16
506507
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
@@ -534,6 +534,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
534534
# math.h C23 _Float16 entrypoints
535535
libc.src.math.fabsf16
536536
libc.src.math.llrintf16
537+
libc.src.math.llroundf16
537538
libc.src.math.lrintf16
538539
libc.src.math.lroundf16
539540
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
@@ -576,6 +576,7 @@ def StdC : StandardSpec<"stdc"> {
576576
FunctionSpec<"llround", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,
577577
FunctionSpec<"llroundf", RetValSpec<LongLongType>, [ArgSpec<FloatType>]>,
578578
FunctionSpec<"llroundl", RetValSpec<LongLongType>, [ArgSpec<LongDoubleType>]>,
579+
GuardedFunctionSpec<"llroundf16", RetValSpec<LongLongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
579580
GuardedFunctionSpec<"llroundf128", RetValSpec<LongLongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
580581

581582
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
@@ -229,6 +229,7 @@ add_math_entrypoint_object(llrintf128)
229229
add_math_entrypoint_object(llround)
230230
add_math_entrypoint_object(llroundf)
231231
add_math_entrypoint_object(llroundl)
232+
add_math_entrypoint_object(llroundf16)
232233
add_math_entrypoint_object(llroundf128)
233234

234235
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
@@ -561,6 +561,19 @@ add_entrypoint_object(
561561
libc.src.__support.FPUtil.nearest_integer_operations
562562
)
563563

564+
add_entrypoint_object(
565+
llroundf16
566+
SRCS
567+
llroundf16.cpp
568+
HDRS
569+
../llroundf16.h
570+
COMPILE_OPTIONS
571+
-O3
572+
DEPENDS
573+
libc.src.__support.macros.properties.types
574+
libc.src.__support.FPUtil.nearest_integer_operations
575+
)
576+
564577
add_entrypoint_object(
565578
llroundf128
566579
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
@@ -565,6 +565,22 @@ add_fp_unittest(
565565
libc.src.__support.FPUtil.fp_bits
566566
)
567567

568+
add_fp_unittest(
569+
llroundf16_test
570+
SUITE
571+
libc-math-smoke-tests
572+
SRCS
573+
llroundf16_test.cpp
574+
HDRS
575+
RoundToIntegerTest.h
576+
DEPENDS
577+
libc.src.errno.errno
578+
libc.src.math.llroundf16
579+
libc.src.__support.CPP.algorithm
580+
libc.src.__support.FPUtil.fenv_impl
581+
libc.src.__support.FPUtil.fp_bits
582+
)
583+
568584
add_fp_unittest(
569585
llroundf128_test
570586
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)