Skip to content

Commit

Permalink
[libc][math][c23] Add llroundf16 C23 math function
Browse files Browse the repository at this point in the history
  • Loading branch information
overmighty committed Jun 3, 2024
1 parent 30cd537 commit c9c1068
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fabsf16
libc.src.math.floorf16
libc.src.math.llrintf16
libc.src.math.llroundf16
libc.src.math.lrintf16
libc.src.math.lroundf16
libc.src.math.nearbyintf16
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fabsf16
libc.src.math.floorf16
libc.src.math.llrintf16
libc.src.math.llroundf16
libc.src.math.lrintf16
libc.src.math.lroundf16
libc.src.math.nearbyintf16
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| llrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 |
| llround | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| logb | |check| | |check| | |check| | | |check| | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
1 change: 1 addition & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"llround", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"llroundf", RetValSpec<LongLongType>, [ArgSpec<FloatType>]>,
FunctionSpec<"llroundl", RetValSpec<LongLongType>, [ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"llroundf16", RetValSpec<LongLongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"llroundf128", RetValSpec<LongLongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"rint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ add_math_entrypoint_object(llrintf128)
add_math_entrypoint_object(llround)
add_math_entrypoint_object(llroundf)
add_math_entrypoint_object(llroundl)
add_math_entrypoint_object(llroundf16)
add_math_entrypoint_object(llroundf128)

add_math_entrypoint_object(lrint)
Expand Down
13 changes: 13 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
llroundf16
SRCS
llroundf16.cpp
HDRS
../llroundf16.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
llroundf128
SRCS
Expand Down
19 changes: 19 additions & 0 deletions libc/src/math/generic/llroundf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of llroundf16 function -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/llroundf16.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(long long, llroundf16, (float16 x)) {
return fputil::round_to_signed_integer<float128, long long>(x);
}

} // namespace LIBC_NAMESPACE
20 changes: 20 additions & 0 deletions libc/src/math/llroundf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for llroundf16 --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_LLROUNDF16_H
#define LLVM_LIBC_SRC_MATH_LLROUNDF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

long long llroundf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_LLROUNDF16_H
16 changes: 16 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
llroundf16_test
SUITE
libc-math-smoke-tests
SRCS
llroundf16_test.cpp
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llroundf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
llroundf128_test
SUITE
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/llroundf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for llroundf16 ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "RoundToIntegerTest.h"

#include "src/math/llroundf16.h"

LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)

0 comments on commit c9c1068

Please sign in to comment.