Skip to content

Commit 6e0e851

Browse files
committed
[libc][math][c23] Add llogbf16 C23 math function
1 parent dcc2be4 commit 6e0e851

File tree

11 files changed

+86
-2
lines changed

11 files changed

+86
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
521521
libc.src.math.fromfpxf16
522522
libc.src.math.ilogbf16
523523
libc.src.math.ldexpf16
524+
libc.src.math.llogbf16
524525
libc.src.math.llrintf16
525526
libc.src.math.llroundf16
526527
libc.src.math.lrintf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
554554
libc.src.math.fromfpxf16
555555
libc.src.math.ilogbf16
556556
libc.src.math.ldexpf16
557+
libc.src.math.llogbf16
557558
libc.src.math.llrintf16
558559
libc.src.math.llroundf16
559560
libc.src.math.lrintf16

libc/docs/c23.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Additions:
5050
* issignaling
5151
* issubnormal
5252
* iszero
53-
* llogb*
53+
* llogb* |check|
5454
* pown*
5555
* powr*
5656
* rootn*

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Basic Operations
172172
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
173173
| ldexp | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
174174
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
175-
| llogb | |check| | |check| | |check| | | |check| | 7.12.6.10 | F.10.3.10 |
175+
| llogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
176176
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
177177
| llrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
178178
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def StdC : StandardSpec<"stdc"> {
526526
FunctionSpec<"llogb", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
527527
FunctionSpec<"llogbf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
528528
FunctionSpec<"llogbl", RetValSpec<LongType>, [ArgSpec<LongDoubleType>]>,
529+
GuardedFunctionSpec<"llogbf16", RetValSpec<LongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
529530
GuardedFunctionSpec<"llogbf128", RetValSpec<LongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
530531

531532
FunctionSpec<"ldexp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ add_math_entrypoint_object(ilogbf128)
218218
add_math_entrypoint_object(llogb)
219219
add_math_entrypoint_object(llogbf)
220220
add_math_entrypoint_object(llogbl)
221+
add_math_entrypoint_object(llogbf16)
221222
add_math_entrypoint_object(llogbf128)
222223

223224
add_math_entrypoint_object(ldexp)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,19 @@ add_entrypoint_object(
14251425
libc.src.__support.FPUtil.manipulation_functions
14261426
)
14271427

1428+
add_entrypoint_object(
1429+
llogbf16
1430+
SRCS
1431+
llogbf16.cpp
1432+
HDRS
1433+
../llogbf16.h
1434+
COMPILE_OPTIONS
1435+
-O3
1436+
DEPENDS
1437+
libc.src.__support.macros.properties.types
1438+
libc.src.__support.FPUtil.manipulation_functions
1439+
)
1440+
14281441
add_entrypoint_object(
14291442
llogbf128
14301443
SRCS

libc/src/math/generic/llogbf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of llogbf16 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/llogbf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(long, llogbf16, (float16 x)) {
16+
return fputil::intlogb<long>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/llogbf16.h

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,21 @@ add_fp_unittest(
14751475
libc.src.__support.FPUtil.manipulation_functions
14761476
)
14771477

1478+
add_fp_unittest(
1479+
llogbf16_test
1480+
SUITE
1481+
libc-math-smoke-tests
1482+
SRCS
1483+
llogbf16_test.cpp
1484+
HDRS
1485+
ILogbTest.h
1486+
DEPENDS
1487+
libc.src.math.llogbf16
1488+
libc.src.__support.CPP.limits
1489+
libc.src.__support.FPUtil.fp_bits
1490+
libc.src.__support.FPUtil.manipulation_functions
1491+
)
1492+
14781493
add_fp_unittest(
14791494
llogbf128_test
14801495
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for llogbf16 --------------------------------------------===//
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 "ILogbTest.h"
10+
11+
#include "src/math/llogbf16.h"
12+
13+
LIST_INTLOGB_TESTS(long, float16, LIBC_NAMESPACE::llogbf16);

0 commit comments

Comments
 (0)