Skip to content

Commit 0dea266

Browse files
committed
[libc][math][c23] Add ufromfpxf16 C23 math function
1 parent 7e655fb commit 0dea266

File tree

12 files changed

+125
-44
lines changed

12 files changed

+125
-44
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
514514
libc.src.math.roundevenf16
515515
libc.src.math.truncf16
516516
libc.src.math.ufromfpf16
517+
libc.src.math.ufromfpxf16
517518
)
518519
endif()
519520

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
547547
libc.src.math.roundevenf16
548548
libc.src.math.truncf16
549549
libc.src.math.ufromfpf16
550+
libc.src.math.ufromfpxf16
550551
)
551552
endif()
552553

libc/docs/c23.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Additions:
5858
* fromfp* |check|
5959
* ufromfp* |check|
6060
* fromfpx* |check|
61+
* ufromfpx* |check|
6162
* nextup*
6263
* nextdown*
6364
* canonicalize*

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Basic Operations
214214
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
215215
| ufromfp | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
216216
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
217-
| ufromfpx | |check| | |check| | |check| | | |check| | 7.12.9.11 | F.10.6.11 |
217+
| ufromfpx | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
218218
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
219219

220220

libc/spec/stdc.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ def StdC : StandardSpec<"stdc"> {
494494
FunctionSpec<"ufromfpx", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
495495
FunctionSpec<"ufromfpxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
496496
FunctionSpec<"ufromfpxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
497-
GuardedFunctionSpec<"ufromfpxf128", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,
497+
GuardedFunctionSpec<"ufromfpxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT16">,
498+
GuardedFunctionSpec<"ufromfpxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,
498499

499500
FunctionSpec<"hypot", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
500501
FunctionSpec<"hypotf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,5 @@ add_math_entrypoint_object(ufromfpf128)
355355
add_math_entrypoint_object(ufromfpx)
356356
add_math_entrypoint_object(ufromfpxf)
357357
add_math_entrypoint_object(ufromfpxl)
358+
add_math_entrypoint_object(ufromfpxf16)
358359
add_math_entrypoint_object(ufromfpxf128)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,6 +2901,19 @@ add_entrypoint_object(
29012901
-O3
29022902
)
29032903

2904+
add_entrypoint_object(
2905+
ufromfpxf16
2906+
SRCS
2907+
ufromfpxf16.cpp
2908+
HDRS
2909+
../ufromfpxf16.h
2910+
DEPENDS
2911+
libc.src.__support.macros.properties.types
2912+
libc.src.__support.FPUtil.nearest_integer_operations
2913+
COMPILE_OPTIONS
2914+
-O3
2915+
)
2916+
29042917
add_entrypoint_object(
29052918
ufromfpxf128
29062919
SRCS

libc/src/math/generic/ufromfpxf16.cpp

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

libc/src/math/ufromfpxf16.h

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,18 @@ add_fp_unittest(
12861286
libc.src.math.ufromfpxl
12871287
)
12881288

1289+
add_fp_unittest(
1290+
ufromfpxf16_test
1291+
SUITE
1292+
libc-math-smoke-tests
1293+
SRCS
1294+
ufromfpxf16_test.cpp
1295+
HDRS
1296+
UfromfpxTest.h
1297+
DEPENDS
1298+
libc.src.math.ufromfpxf16
1299+
)
1300+
12891301
add_fp_unittest(
12901302
ufromfpxf128_test
12911303
SUITE

0 commit comments

Comments
 (0)