Skip to content

Commit d0fe470

Browse files
[libc][math] Add scalbln{,f,l,f128} math functions (#102219)
Co-authored-by: OverMighty <[email protected]>
1 parent 2b592b1 commit d0fe470

27 files changed

+434
-1
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ set(TARGET_LIBM_ENTRYPOINTS
394394
libc.src.math.roundevenl
395395
libc.src.math.roundf
396396
libc.src.math.roundl
397+
libc.src.math.scalbln
398+
libc.src.math.scalblnf
399+
libc.src.math.scalblnl
397400
libc.src.math.scalbn
398401
libc.src.math.scalbnf
399402
libc.src.math.scalbnl

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ set(TARGET_LIBM_ENTRYPOINTS
389389
libc.src.math.roundevenl
390390
libc.src.math.roundf
391391
libc.src.math.roundl
392+
libc.src.math.scalbln
393+
libc.src.math.scalblnf
394+
libc.src.math.scalblnl
392395
libc.src.math.scalbn
393396
libc.src.math.scalbnf
394397
libc.src.math.scalbnl

libc/config/darwin/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ set(TARGET_LIBM_ENTRYPOINTS
248248
libc.src.math.round
249249
libc.src.math.roundf
250250
libc.src.math.roundl
251+
libc.src.math.scalbln
252+
libc.src.math.scalblnf
253+
libc.src.math.scalblnl
251254
libc.src.math.scalbn
252255
libc.src.math.scalbnf
253256
libc.src.math.scalbnl

libc/config/gpu/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ set(TARGET_LIBM_ENTRYPOINTS
336336
libc.src.math.rintf
337337
libc.src.math.round
338338
libc.src.math.roundf
339+
libc.src.math.scalbln
340+
libc.src.math.scalblnf
339341
libc.src.math.scalbn
340342
libc.src.math.scalbnf
341343
libc.src.math.sin

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ set(TARGET_LIBM_ENTRYPOINTS
542542
libc.src.math.roundevenl
543543
libc.src.math.roundf
544544
libc.src.math.roundl
545+
libc.src.math.scalbln
546+
libc.src.math.scalblnf
547+
libc.src.math.scalblnl
545548
libc.src.math.scalbn
546549
libc.src.math.scalbnf
547550
libc.src.math.scalbnl
@@ -729,6 +732,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
729732
libc.src.math.rintf128
730733
libc.src.math.roundevenf128
731734
libc.src.math.roundf128
735+
libc.src.math.scalblnf128
732736
libc.src.math.scalbnf128
733737
libc.src.math.setpayloadf128
734738
libc.src.math.setpayloadsigf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ set(TARGET_LIBM_ENTRYPOINTS
371371
libc.src.math.round
372372
libc.src.math.roundf
373373
libc.src.math.roundl
374+
libc.src.math.scalbln
375+
libc.src.math.scalblnf
376+
libc.src.math.scalblnl
374377
libc.src.math.scalbn
375378
libc.src.math.scalbnf
376379
libc.src.math.scalbnl

libc/config/linux/riscv/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ set(TARGET_LIBM_ENTRYPOINTS
545545
libc.src.math.roundevenl
546546
libc.src.math.roundf
547547
libc.src.math.roundl
548+
libc.src.math.scalbln
549+
libc.src.math.scalblnf
550+
libc.src.math.scalblnl
548551
libc.src.math.scalbn
549552
libc.src.math.scalbnf
550553
libc.src.math.scalbnl
@@ -636,6 +639,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
636639
libc.src.math.rintf128
637640
libc.src.math.roundevenf128
638641
libc.src.math.roundf128
642+
libc.src.math.scalblnf128
639643
libc.src.math.scalbnf128
640644
libc.src.math.setpayloadf128
641645
libc.src.math.setpayloadsigf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ set(TARGET_LIBM_ENTRYPOINTS
545545
libc.src.math.roundevenl
546546
libc.src.math.roundf
547547
libc.src.math.roundl
548+
libc.src.math.scalbln
549+
libc.src.math.scalblnf
550+
libc.src.math.scalblnl
548551
libc.src.math.scalbn
549552
libc.src.math.scalbnf
550553
libc.src.math.scalbnl
@@ -725,6 +728,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
725728
libc.src.math.rintf128
726729
libc.src.math.roundevenf128
727730
libc.src.math.roundf128
731+
libc.src.math.scalblnf128
728732
libc.src.math.scalbnf128
729733
libc.src.math.setpayloadf128
730734
libc.src.math.setpayloadsigf128

libc/config/windows/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ set(TARGET_LIBM_ENTRYPOINTS
264264
libc.src.math.round
265265
libc.src.math.roundf
266266
libc.src.math.roundl
267+
libc.src.math.scalbln
268+
libc.src.math.scalblnf
269+
libc.src.math.scalblnl
267270
libc.src.math.scalbn
268271
libc.src.math.scalbnf
269272
libc.src.math.scalbnl

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Basic Operations
220220
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
221221
| roundeven | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
222222
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
223-
| scalbln | | | | |check| | | 7.12.6.19 | F.10.3.19 |
223+
| scalbln | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
224224
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
225225
| scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
226226
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/newhdrgen/yaml/math.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,43 @@ functions:
23132313
- type: int
23142314
- type: unsigned int
23152315
guard: LIBC_TYPES_HAS_FLOAT128
2316+
- name: scalbln
2317+
standards:
2318+
- stdc
2319+
return_type: double
2320+
arguments:
2321+
- type: double
2322+
- type: long
2323+
- name: scalblnl
2324+
standards:
2325+
- stdc
2326+
return_type: long double
2327+
arguments:
2328+
- type: long double
2329+
- type: long
2330+
- name: scalblnf
2331+
standards:
2332+
- stdc
2333+
return_type: float
2334+
arguments:
2335+
- type: float
2336+
- type: long
2337+
- name: scalblnf16
2338+
standards:
2339+
- stdc
2340+
return_type: float16
2341+
arguments:
2342+
- type: float16
2343+
- type: long
2344+
guard: LIBC_TYPES_HAS_FLOAT16
2345+
- name: scalblnf128
2346+
standards:
2347+
- stdc
2348+
return_type: float128
2349+
arguments:
2350+
- type: float128
2351+
- type: long
2352+
guard: LIBC_TYPES_HAS_FLOAT128
23162353
- name: lgamma
23172354
standards:
23182355
- stdc

libc/spec/stdc.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,11 @@ def StdC : StandardSpec<"stdc"> {
717717
FunctionSpec<"asinhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
718718
FunctionSpec<"atanhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
719719

720+
FunctionSpec<"scalbln", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<LongType>]>,
721+
FunctionSpec<"scalblnf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<LongType>]>,
722+
FunctionSpec<"scalblnl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongType>]>,
720723
GuardedFunctionSpec<"scalblnf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<LongType>], "LIBC_TYPES_HAS_FLOAT16">,
724+
GuardedFunctionSpec<"scalblnf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<LongType>], "LIBC_TYPES_HAS_FLOAT128">,
721725

722726
FunctionSpec<"scalbn", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
723727
FunctionSpec<"scalbnf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ add_math_entrypoint_object(roundevenl)
427427
add_math_entrypoint_object(roundevenf16)
428428
add_math_entrypoint_object(roundevenf128)
429429

430+
add_math_entrypoint_object(scalbln)
431+
add_math_entrypoint_object(scalblnf)
432+
add_math_entrypoint_object(scalblnl)
430433
add_math_entrypoint_object(scalblnf16)
434+
add_math_entrypoint_object(scalblnf128)
431435

432436
add_math_entrypoint_object(scalbn)
433437
add_math_entrypoint_object(scalbnf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,6 +4185,46 @@ add_entrypoint_object(
41854185
libc.src.__support.macros.optimization
41864186
)
41874187

4188+
4189+
add_entrypoint_object(
4190+
scalbln
4191+
SRCS
4192+
scalbln.cpp
4193+
HDRS
4194+
../scalbln.h
4195+
DEPENDS
4196+
libc.hdr.float_macros
4197+
libc.src.__support.FPUtil.manipulation_functions
4198+
COMPILE_OPTIONS
4199+
-O3
4200+
)
4201+
4202+
add_entrypoint_object(
4203+
scalblnf
4204+
SRCS
4205+
scalblnf.cpp
4206+
HDRS
4207+
../scalblnf.h
4208+
DEPENDS
4209+
libc.hdr.float_macros
4210+
libc.src.__support.FPUtil.manipulation_functions
4211+
COMPILE_OPTIONS
4212+
-O3
4213+
)
4214+
4215+
add_entrypoint_object(
4216+
scalblnl
4217+
SRCS
4218+
scalblnl.cpp
4219+
HDRS
4220+
../scalblnl.h
4221+
DEPENDS
4222+
libc.hdr.float_macros
4223+
libc.src.__support.FPUtil.manipulation_functions
4224+
COMPILE_OPTIONS
4225+
-O3
4226+
)
4227+
41884228
add_entrypoint_object(
41894229
scalblnf16
41904230
SRCS
@@ -4199,6 +4239,20 @@ add_entrypoint_object(
41994239
-O3
42004240
)
42014241

4242+
add_entrypoint_object(
4243+
scalblnf128
4244+
SRCS
4245+
scalblnf128.cpp
4246+
HDRS
4247+
../scalblnf128.h
4248+
DEPENDS
4249+
libc.hdr.float_macros
4250+
libc.src.__support.macros.properties.types
4251+
libc.src.__support.FPUtil.manipulation_functions
4252+
COMPILE_OPTIONS
4253+
-O3
4254+
)
4255+
42024256
add_entrypoint_object(
42034257
scalbn
42044258
SRCS

libc/src/math/generic/scalbln.cpp

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

libc/src/math/generic/scalblnf.cpp

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

libc/src/math/generic/scalblnf128.cpp

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

libc/src/math/generic/scalblnl.cpp

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

libc/src/math/scalbln.h

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

0 commit comments

Comments
 (0)