Skip to content

Commit 781c9b0

Browse files
committed
[libc][math][c23] Add scalbnf16 C23 math function
1 parent 2125fc1 commit 781c9b0

File tree

10 files changed

+90
-1
lines changed

10 files changed

+90
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
545545
libc.src.math.rintf16
546546
libc.src.math.roundf16
547547
libc.src.math.roundevenf16
548+
libc.src.math.scalbnf16
548549
libc.src.math.totalorderf16
549550
libc.src.math.totalordermagf16
550551
libc.src.math.truncf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
575575
libc.src.math.rintf16
576576
libc.src.math.roundf16
577577
libc.src.math.roundevenf16
578+
libc.src.math.scalbnf16
578579
libc.src.math.totalorderf16
579580
libc.src.math.totalordermagf16
580581
libc.src.math.truncf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Basic Operations
210210
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
211211
| roundeven | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
212212
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
213-
| scalbn | |check| | |check| | |check| | | |check| | 7.12.6.19 | F.10.3.19 |
213+
| scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
214214
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
215215
| totalorder | | | | |check| | | F.10.12.1 | N/A |
216216
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ def StdC : StandardSpec<"stdc"> {
699699
FunctionSpec<"scalbn", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
700700
FunctionSpec<"scalbnf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
701701
FunctionSpec<"scalbnl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>]>,
702+
GuardedFunctionSpec<"scalbnf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>], "LIBC_TYPES_HAS_FLOAT16">,
702703
GuardedFunctionSpec<"scalbnf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>], "LIBC_TYPES_HAS_FLOAT128">,
703704

704705
FunctionSpec<"nanf", RetValSpec<FloatType>, [ArgSpec<ConstCharPtr>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ add_math_entrypoint_object(roundevenf128)
349349
add_math_entrypoint_object(scalbn)
350350
add_math_entrypoint_object(scalbnf)
351351
add_math_entrypoint_object(scalbnl)
352+
add_math_entrypoint_object(scalbnf16)
352353
add_math_entrypoint_object(scalbnf128)
353354

354355
add_math_entrypoint_object(sincos)

libc/src/math/generic/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,20 @@ add_entrypoint_object(
35533553
-O3
35543554
)
35553555

3556+
add_entrypoint_object(
3557+
scalbnf16
3558+
SRCS
3559+
scalbnf16.cpp
3560+
HDRS
3561+
../scalbnf16.h
3562+
DEPENDS
3563+
libc.hdr.float_macros
3564+
libc.src.__support.macros.properties.types
3565+
libc.src.__support.FPUtil.manipulation_functions
3566+
COMPILE_OPTIONS
3567+
-O3
3568+
)
3569+
35563570
add_entrypoint_object(
35573571
scalbnf128
35583572
SRCS

libc/src/math/generic/scalbnf16.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation of scalbnf16 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/scalbnf16.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
#include "hdr/float_macros.h"
14+
15+
#if FLT_RADIX != 2
16+
#error "FLT_RADIX != 2 is not supported."
17+
#endif
18+
19+
namespace LIBC_NAMESPACE {
20+
21+
LLVM_LIBC_FUNCTION(float16, scalbnf16, (float16 x, int n)) {
22+
return fputil::ldexp(x, n);
23+
}
24+
25+
} // namespace LIBC_NAMESPACE

libc/src/math/scalbnf16.h

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

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,19 @@ add_fp_unittest(
35093509
libc.src.__support.FPUtil.fp_bits
35103510
)
35113511

3512+
add_fp_unittest(
3513+
scalbnf16_test
3514+
SUITE
3515+
libc-math-smoke-tests
3516+
SRCS
3517+
scalbnf16_test.cpp
3518+
HDRS
3519+
ScalbnTest.h
3520+
DEPENDS
3521+
libc.src.math.scalbnf16
3522+
libc.src.__support.FPUtil.fp_bits
3523+
)
3524+
35123525
add_fp_unittest(
35133526
scalbnf128_test
35143527
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for scalbnf16 -------------------------------------------===//
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 "ScalbnTest.h"
10+
11+
#include "src/math/scalbnf16.h"
12+
13+
LIST_SCALBN_TESTS(float16, LIBC_NAMESPACE::scalbnf16)

0 commit comments

Comments
 (0)