[libc-commits] [libc] 2635d04 - [libc][math][c23] Add {nearbyint, rint, lrint, llrint, lround, llround}f16 C23 math functions (#94218)
via libc-commits
libc-commits at lists.llvm.org
Tue Jun 4 07:03:36 PDT 2024
Author: OverMighty
Date: 2024-06-04T10:03:31-04:00
New Revision: 2635d0419e4800c34c7cfea120a12fec8d4878fe
URL: https://github.com/llvm/llvm-project/commit/2635d0419e4800c34c7cfea120a12fec8d4878fe
DIFF: https://github.com/llvm/llvm-project/commit/2635d0419e4800c34c7cfea120a12fec8d4878fe.diff
LOG: [libc][math][c23] Add {nearbyint,rint,lrint,llrint,lround,llround}f16 C23 math functions (#94218)
https://github.com/llvm/llvm-project/issues/93566
Added:
libc/src/math/generic/llrintf16.cpp
libc/src/math/generic/llroundf16.cpp
libc/src/math/generic/lrintf16.cpp
libc/src/math/generic/lroundf16.cpp
libc/src/math/generic/nearbyintf16.cpp
libc/src/math/generic/rintf16.cpp
libc/src/math/llrintf16.h
libc/src/math/llroundf16.h
libc/src/math/lrintf16.h
libc/src/math/lroundf16.h
libc/src/math/nearbyintf16.h
libc/src/math/rintf16.h
libc/test/src/math/smoke/llrintf16_test.cpp
libc/test/src/math/smoke/llroundf16_test.cpp
libc/test/src/math/smoke/lrintf16_test.cpp
libc/test/src/math/smoke/lroundf16_test.cpp
libc/test/src/math/smoke/nearbyintf16_test.cpp
libc/test/src/math/smoke/rintf16_test.cpp
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/docs/math/index.rst
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/test/src/math/smoke/CMakeLists.txt
libc/test/src/math/smoke/RoundToIntegerTest.h
Removed:
################################################################################
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 3bbd1629e3d8d..23842c951c8cc 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -502,6 +502,12 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ceilf16
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
+ libc.src.math.rintf16
libc.src.math.roundf16
libc.src.math.roundevenf16
libc.src.math.truncf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 62434298890f0..6506ea3108169 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -535,6 +535,12 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.ceilf16
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
+ libc.src.math.rintf16
libc.src.math.roundf16
libc.src.math.roundevenf16
libc.src.math.truncf16
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 9df7dcfc256db..b1a8aa2dd9470 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -174,21 +174,21 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| llogb | |check| | |check| | |check| | | |check| | 7.12.6.10 | F.10.3.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| llrint | |check| | |check| | |check| | | |check| | 7.12.9.5 | F.10.6.5 |
+| 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| lrint | |check| | |check| | |check| | | |check| | 7.12.9.5 | F.10.6.5 |
+| lrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| lround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 |
+| lround | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| modf | |check| | |check| | |check| | | |check| | 7.12.6.18 | F.10.3.18 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| nan | |check| | |check| | |check| | | |check| | 7.12.11.2 | F.10.8.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| nearbyint | |check| | |check| | |check| | | |check| | 7.12.9.3 | F.10.6.3 |
+| nearbyint | |check| | |check| | |check| | |check| | |check| | 7.12.9.3 | F.10.6.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| nextafter | |check| | |check| | |check| | | |check| | 7.12.11.3 | F.10.8.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -202,7 +202,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | | | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| rint | |check| | |check| | |check| | | |check| | 7.12.9.4 | F.10.6.4 |
+| rint | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| round | |check| | |check| | |check| | |check| | |check| | 7.12.9.6 | F.10.6.6 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index cacc91ce8789a..2e64336ed4835 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -579,26 +579,31 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"lround", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"lroundf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
FunctionSpec<"lroundl", RetValSpec<LongType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"lroundf16", RetValSpec<LongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"lroundf128", RetValSpec<LongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
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>]>,
FunctionSpec<"rintf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"rintl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"rintf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"rintf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"lrint", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"lrintf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
FunctionSpec<"lrintl", RetValSpec<LongType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"lrintf16", RetValSpec<LongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"lrintf128", RetValSpec<LongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"llrint", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"llrintf", RetValSpec<LongLongType>, [ArgSpec<FloatType>]>,
FunctionSpec<"llrintl", RetValSpec<LongLongType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"llrintf16", RetValSpec<LongLongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"llrintf128", RetValSpec<LongLongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"sqrt", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
@@ -615,6 +620,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"nearbyint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"nearbyintf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"nearbyintl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"nearbyintf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"nearbyintf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"nextafterf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3b07b0b8679c4..84c9beebfbea2 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -225,21 +225,25 @@ add_math_entrypoint_object(logbf128)
add_math_entrypoint_object(llrint)
add_math_entrypoint_object(llrintf)
add_math_entrypoint_object(llrintl)
+add_math_entrypoint_object(llrintf16)
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)
add_math_entrypoint_object(lrintf)
add_math_entrypoint_object(lrintl)
+add_math_entrypoint_object(lrintf16)
add_math_entrypoint_object(lrintf128)
add_math_entrypoint_object(lround)
add_math_entrypoint_object(lroundf)
add_math_entrypoint_object(lroundl)
+add_math_entrypoint_object(lroundf16)
add_math_entrypoint_object(lroundf128)
add_math_entrypoint_object(modf)
@@ -255,6 +259,7 @@ add_math_entrypoint_object(nanf128)
add_math_entrypoint_object(nearbyint)
add_math_entrypoint_object(nearbyintf)
add_math_entrypoint_object(nearbyintl)
+add_math_entrypoint_object(nearbyintf16)
add_math_entrypoint_object(nearbyintf128)
add_math_entrypoint_object(nextafter)
@@ -290,6 +295,7 @@ add_math_entrypoint_object(remquol)
add_math_entrypoint_object(rint)
add_math_entrypoint_object(rintf)
add_math_entrypoint_object(rintl)
+add_math_entrypoint_object(rintf16)
add_math_entrypoint_object(rintf128)
add_math_entrypoint_object(round)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 369616caa2565..4fb744254cfdc 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -564,6 +564,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ lroundf16
+ SRCS
+ lroundf16.cpp
+ HDRS
+ ../lroundf16.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+)
+
add_entrypoint_object(
lroundf128
SRCS
@@ -613,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
@@ -662,6 +688,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ rintf16
+ SRCS
+ rintf16.cpp
+ HDRS
+ ../rintf16.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+)
+
add_entrypoint_object(
rintf128
SRCS
@@ -711,6 +750,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ lrintf16
+ SRCS
+ lrintf16.cpp
+ HDRS
+ ../lrintf16.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+)
+
add_entrypoint_object(
lrintf128
SRCS
@@ -760,6 +812,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
+add_entrypoint_object(
+ llrintf16
+ SRCS
+ llrintf16.cpp
+ HDRS
+ ../llrintf16.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+)
+
add_entrypoint_object(
llrintf128
SRCS
@@ -809,6 +874,19 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ nearbyintf16
+ SRCS
+ nearbyintf16.cpp
+ HDRS
+ ../nearbyintf16.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.nearest_integer_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
nearbyintf128
SRCS
diff --git a/libc/src/math/generic/llrintf16.cpp b/libc/src/math/generic/llrintf16.cpp
new file mode 100644
index 0000000000000..0bed21ad17bb8
--- /dev/null
+++ b/libc/src/math/generic/llrintf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of llrintf16 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/llrintf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(long long, llrintf16, (float16 x)) {
+ return fputil::round_to_signed_integer_using_current_rounding_mode<float16,
+ long long>(
+ x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/llroundf16.cpp b/libc/src/math/generic/llroundf16.cpp
new file mode 100644
index 0000000000000..9485674d54bcb
--- /dev/null
+++ b/libc/src/math/generic/llroundf16.cpp
@@ -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<float16, long long>(x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/lrintf16.cpp b/libc/src/math/generic/lrintf16.cpp
new file mode 100644
index 0000000000000..d49be281a686b
--- /dev/null
+++ b/libc/src/math/generic/lrintf16.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of lrintf16 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/lrintf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(long, lrintf16, (float16 x)) {
+ return fputil::round_to_signed_integer_using_current_rounding_mode<float16,
+ long>(x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/lroundf16.cpp b/libc/src/math/generic/lroundf16.cpp
new file mode 100644
index 0000000000000..db8113d7bfb5e
--- /dev/null
+++ b/libc/src/math/generic/lroundf16.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of lroundf16 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/lroundf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(long, lroundf16, (float16 x)) {
+ return fputil::round_to_signed_integer<float16, long>(x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/nearbyintf16.cpp b/libc/src/math/generic/nearbyintf16.cpp
new file mode 100644
index 0000000000000..efd31e9143f57
--- /dev/null
+++ b/libc/src/math/generic/nearbyintf16.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of nearbyintf16 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/nearbyintf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float16, nearbyintf16, (float16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/rintf16.cpp b/libc/src/math/generic/rintf16.cpp
new file mode 100644
index 0000000000000..e0caa7ad2550e
--- /dev/null
+++ b/libc/src/math/generic/rintf16.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of rintf16 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/rintf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float16, rintf16, (float16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/llrintf16.h b/libc/src/math/llrintf16.h
new file mode 100644
index 0000000000000..90ad0e9e2ea2a
--- /dev/null
+++ b/libc/src/math/llrintf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for llrintf16 ---------------------*- 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_LLRINTF16_H
+#define LLVM_LIBC_SRC_MATH_LLRINTF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+long long llrintf16(float16 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_LLRINTF16_H
diff --git a/libc/src/math/llroundf16.h b/libc/src/math/llroundf16.h
new file mode 100644
index 0000000000000..379c45446ab27
--- /dev/null
+++ b/libc/src/math/llroundf16.h
@@ -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
diff --git a/libc/src/math/lrintf16.h b/libc/src/math/lrintf16.h
new file mode 100644
index 0000000000000..f31fba4cc6a46
--- /dev/null
+++ b/libc/src/math/lrintf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for lrintf16 ----------------------*- 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_LRINTF16_H
+#define LLVM_LIBC_SRC_MATH_LRINTF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+long lrintf16(float16 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_LRINTF16_H
diff --git a/libc/src/math/lroundf16.h b/libc/src/math/lroundf16.h
new file mode 100644
index 0000000000000..57201e7063a9e
--- /dev/null
+++ b/libc/src/math/lroundf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for lroundf16 ---------------------*- 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_LROUNDF16_H
+#define LLVM_LIBC_SRC_MATH_LROUNDF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+long lroundf16(float16 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_LROUNDF16_H
diff --git a/libc/src/math/nearbyintf16.h b/libc/src/math/nearbyintf16.h
new file mode 100644
index 0000000000000..3e6f3fb3d493c
--- /dev/null
+++ b/libc/src/math/nearbyintf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for nearbyintf16 ------------------*- 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_NEARBYINTF16_H
+#define LLVM_LIBC_SRC_MATH_NEARBYINTF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+float16 nearbyintf16(float16 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_NEARBYINTF16_H
diff --git a/libc/src/math/rintf16.h b/libc/src/math/rintf16.h
new file mode 100644
index 0000000000000..5ea9587ef3cf6
--- /dev/null
+++ b/libc/src/math/rintf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for rintf16 -----------------------*- 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_RINTF16_H
+#define LLVM_LIBC_SRC_MATH_RINTF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+float16 rintf16(float16 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_RINTF16_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 685a53d8e7c6a..8f4eb37e665cb 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -507,10 +507,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lround
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -524,10 +523,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lroundf
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -541,10 +539,25 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lroundl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ lroundf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lroundf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lroundf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -558,10 +571,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lroundf128
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -575,10 +587,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llround
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -592,10 +603,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llroundf
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -609,10 +619,25 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llroundl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ 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
)
@@ -626,10 +651,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llroundf128
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -675,6 +699,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ rintf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ rintf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.src.math.rintf16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
rintf128_test
SUITE
@@ -698,7 +736,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.lrint
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -712,7 +752,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.lrintf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -726,7 +768,25 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.lrintl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ lrintf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lrintf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lrintf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -740,7 +800,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.lrintf128
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -754,7 +816,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.llrint
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -768,7 +832,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.llrintf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -782,7 +848,25 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.llrintl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ llrintf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ llrintf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.llrintf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -796,7 +880,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.src.errno.errno
libc.src.math.llrintf128
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -2299,6 +2385,19 @@ add_fp_unittest(
libc.src.math.nearbyintl
)
+add_fp_unittest(
+ nearbyintf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ nearbyintf16_test.cpp
+ HDRS
+ NearbyIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.nearbyintf16
+)
+
add_fp_unittest(
nearbyintf128_test
SUITE
diff --git a/libc/test/src/math/smoke/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h
index 3ff311f46b056..02ae601716afc 100644
--- a/libc/test/src/math/smoke/RoundToIntegerTest.h
+++ b/libc/test/src/math/smoke/RoundToIntegerTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
@@ -113,8 +114,10 @@ class RoundToIntegerTestTemplate
}
void testSubnormalRange(RoundToIntegerFunc func) {
- constexpr StorageType COUNT = 1'000'001;
- constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+ constexpr int COUNT = 1'000'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = FPBits(i).get_val();
if (x == F(0.0))
diff --git a/libc/test/src/math/smoke/llrintf16_test.cpp b/libc/test/src/math/smoke/llrintf16_test.cpp
new file mode 100644
index 0000000000000..d16bd8f38b052
--- /dev/null
+++ b/libc/test/src/math/smoke/llrintf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llrintf16 -------------------------------------------===//
+//
+// 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/llrintf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long long,
+ LIBC_NAMESPACE::llrintf16)
diff --git a/libc/test/src/math/smoke/llroundf16_test.cpp b/libc/test/src/math/smoke/llroundf16_test.cpp
new file mode 100644
index 0000000000000..9342b24fd5d04
--- /dev/null
+++ b/libc/test/src/math/smoke/llroundf16_test.cpp
@@ -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)
diff --git a/libc/test/src/math/smoke/lrintf16_test.cpp b/libc/test/src/math/smoke/lrintf16_test.cpp
new file mode 100644
index 0000000000000..28b1a1cb888d7
--- /dev/null
+++ b/libc/test/src/math/smoke/lrintf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for lrintf16 --------------------------------------------===//
+//
+// 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/lrintf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long, LIBC_NAMESPACE::lrintf16)
diff --git a/libc/test/src/math/smoke/lroundf16_test.cpp b/libc/test/src/math/smoke/lroundf16_test.cpp
new file mode 100644
index 0000000000000..3077134d58f91
--- /dev/null
+++ b/libc/test/src/math/smoke/lroundf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for lroundf16 -------------------------------------------===//
+//
+// 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/lroundf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(float16, long, LIBC_NAMESPACE::lroundf16)
diff --git a/libc/test/src/math/smoke/nearbyintf16_test.cpp b/libc/test/src/math/smoke/nearbyintf16_test.cpp
new file mode 100644
index 0000000000000..e6ec250cec91f
--- /dev/null
+++ b/libc/test/src/math/smoke/nearbyintf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for nearbyintf16 ----------------------------------------===//
+//
+// 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 "NearbyIntTest.h"
+
+#include "src/math/nearbyintf16.h"
+
+LIST_NEARBYINT_TESTS(float16, LIBC_NAMESPACE::nearbyintf16)
diff --git a/libc/test/src/math/smoke/rintf16_test.cpp b/libc/test/src/math/smoke/rintf16_test.cpp
new file mode 100644
index 0000000000000..2adf2560bae1f
--- /dev/null
+++ b/libc/test/src/math/smoke/rintf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for rintf16 ---------------------------------------------===//
+//
+// 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 "RIntTest.h"
+
+#include "src/math/rintf16.h"
+
+LIST_RINT_TESTS(float16, LIBC_NAMESPACE::rintf16)
More information about the libc-commits
mailing list