Skip to content

Commit faa9f52

Browse files
committed
[libc][math][c23] Add scalbnf16 C23 math function
1 parent 2bd9b14 commit faa9f52

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
@@ -540,6 +540,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
540540
libc.src.math.rintf16
541541
libc.src.math.roundf16
542542
libc.src.math.roundevenf16
543+
libc.src.math.scalbnf16
543544
libc.src.math.truncf16
544545
libc.src.math.ufromfpf16
545546
libc.src.math.ufromfpxf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
570570
libc.src.math.rintf16
571571
libc.src.math.roundf16
572572
libc.src.math.roundevenf16
573+
libc.src.math.scalbnf16
573574
libc.src.math.truncf16
574575
libc.src.math.ufromfpf16
575576
libc.src.math.ufromfpxf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Basic Operations
208208
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
209209
| roundeven | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
210210
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
211-
| scalbn | |check| | |check| | |check| | | |check| | 7.12.6.19 | F.10.3.19 |
211+
| scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
212212
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
213213
| trunc | |check| | |check| | |check| | |check| | |check| | 7.12.9.9 | F.10.6.9 |
214214
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ def StdC : StandardSpec<"stdc"> {
696696
FunctionSpec<"scalbn", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
697697
FunctionSpec<"scalbnf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
698698
FunctionSpec<"scalbnl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>]>,
699+
GuardedFunctionSpec<"scalbnf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>], "LIBC_TYPES_HAS_FLOAT16">,
699700
GuardedFunctionSpec<"scalbnf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>], "LIBC_TYPES_HAS_FLOAT128">,
700701

701702
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
@@ -343,6 +343,7 @@ add_math_entrypoint_object(roundevenf128)
343343
add_math_entrypoint_object(scalbn)
344344
add_math_entrypoint_object(scalbnf)
345345
add_math_entrypoint_object(scalbnl)
346+
add_math_entrypoint_object(scalbnf16)
346347
add_math_entrypoint_object(scalbnf128)
347348

348349
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
@@ -3527,6 +3527,20 @@ add_entrypoint_object(
35273527
-O3
35283528
)
35293529

3530+
add_entrypoint_object(
3531+
scalbnf16
3532+
SRCS
3533+
scalbnf16.cpp
3534+
HDRS
3535+
../scalbnf16.h
3536+
DEPENDS
3537+
libc.hdr.float_macros
3538+
libc.src.__support.macros.properties.types
3539+
libc.src.__support.FPUtil.manipulation_functions
3540+
COMPILE_OPTIONS
3541+
-O3
3542+
)
3543+
35303544
add_entrypoint_object(
35313545
scalbnf128
35323546
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
@@ -3490,6 +3490,19 @@ add_fp_unittest(
34903490
libc.src.__support.FPUtil.fp_bits
34913491
)
34923492

3493+
add_fp_unittest(
3494+
scalbnf16_test
3495+
SUITE
3496+
libc-math-smoke-tests
3497+
SRCS
3498+
scalbnf16_test.cpp
3499+
HDRS
3500+
ScalbnTest.h
3501+
DEPENDS
3502+
libc.src.math.scalbnf16
3503+
libc.src.__support.FPUtil.fp_bits
3504+
)
3505+
34933506
add_fp_unittest(
34943507
scalbnf128_test
34953508
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)