Skip to content

Commit 930cf1c

Browse files
author
Siva Chandra Reddy
committed
[libc] Add implementations of ilogb[f|l].
Depends on D90805. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D90806
1 parent e9e2e31 commit 930cf1c

File tree

18 files changed

+460
-0
lines changed

18 files changed

+460
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ set(TARGET_LIBM_ENTRYPOINTS
6565
libc.src.math.frexpf
6666
libc.src.math.frexpl
6767
libc.src.math.hypotf
68+
libc.src.math.ilogb
69+
libc.src.math.ilogbf
70+
libc.src.math.ilogbl
6871
libc.src.math.logb
6972
libc.src.math.logbf
7073
libc.src.math.logbl

libc/config/linux/api.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def MathAPI : PublicAPI<"math.h"> {
144144
SimpleMacroDef<"INFINITY", "__builtin_inff()">,
145145
SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,
146146

147+
SimpleMacroDef<"FP_ILOGB0", "(-__INT_MAX__ - 1)">, // INT_MIN
148+
SimpleMacroDef<"FP_ILOGBNAN", "__INT_MAX__">,
149+
147150
IsFiniteMacro,
148151
IsInfMacro,
149152
IsNanMacro,

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ set(TARGET_LIBM_ENTRYPOINTS
9898
libc.src.math.frexpf
9999
libc.src.math.frexpl
100100
libc.src.math.hypotf
101+
libc.src.math.ilogb
102+
libc.src.math.ilogbf
103+
libc.src.math.ilogbl
101104
libc.src.math.logb
102105
libc.src.math.logbf
103106
libc.src.math.logbl

libc/spec/stdc.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def StdC : StandardSpec<"stdc"> {
233233
Macro<"INFINITY">,
234234
Macro<"NAN">,
235235

236+
Macro<"FP_ILOGB0">,
237+
Macro<"FP_ILOGBNAN">,
238+
236239
Macro<"isfinite">,
237240
Macro<"isinf">,
238241
Macro<"isnan">,
@@ -273,6 +276,10 @@ def StdC : StandardSpec<"stdc"> {
273276

274277
FunctionSpec<"hypotf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
275278

279+
FunctionSpec<"ilogb", RetValSpec<IntType>, [ArgSpec<DoubleType>]>,
280+
FunctionSpec<"ilogbf", RetValSpec<IntType>, [ArgSpec<FloatType>]>,
281+
FunctionSpec<"ilogbl", RetValSpec<IntType>, [ArgSpec<LongDoubleType>]>,
282+
276283
FunctionSpec<"logb", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
277284
FunctionSpec<"logbf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
278285
FunctionSpec<"logbl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,42 @@ add_entrypoint_object(
342342
-O2
343343
)
344344

345+
add_entrypoint_object(
346+
ilogb
347+
SRCS
348+
ilogb.cpp
349+
HDRS
350+
ilogb.h
351+
DEPENDS
352+
libc.utils.FPUtil.fputil
353+
COMPILE_OPTIONS
354+
-O2
355+
)
356+
357+
add_entrypoint_object(
358+
ilogbf
359+
SRCS
360+
ilogbf.cpp
361+
HDRS
362+
ilogbf.h
363+
DEPENDS
364+
libc.utils.FPUtil.fputil
365+
COMPILE_OPTIONS
366+
-O2
367+
)
368+
369+
add_entrypoint_object(
370+
ilogbl
371+
SRCS
372+
ilogbl.cpp
373+
HDRS
374+
ilogbl.h
375+
DEPENDS
376+
libc.utils.FPUtil.fputil
377+
COMPILE_OPTIONS
378+
-O2
379+
)
380+
345381
add_entrypoint_object(
346382
logb
347383
SRCS

libc/src/math/ilogb.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Implementation of ilogb 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/__support/common.h"
10+
#include "utils/FPUtil/ManipulationFunctions.h"
11+
12+
namespace __llvm_libc {
13+
14+
int LLVM_LIBC_ENTRYPOINT(ilogb)(double x) { return fputil::ilogb(x); }
15+
16+
} // namespace __llvm_libc

libc/src/math/ilogb.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header for ilogb -------------------------*- 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_ILOGB_H
10+
#define LLVM_LIBC_SRC_MATH_ILOGB_H
11+
12+
namespace __llvm_libc {
13+
14+
int ilogb(double x);
15+
16+
} // namespace __llvm_libc
17+
18+
#endif // LLVM_LIBC_SRC_MATH_ILOGB_H

libc/src/math/ilogbf.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Implementation of ilogbf 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/__support/common.h"
10+
#include "utils/FPUtil/ManipulationFunctions.h"
11+
12+
namespace __llvm_libc {
13+
14+
int LLVM_LIBC_ENTRYPOINT(ilogbf)(float x) { return fputil::ilogb(x); }
15+
16+
} // namespace __llvm_libc

libc/src/math/ilogbf.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header for ilogbf ------------------------*- 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_ILOGBF_H
10+
#define LLVM_LIBC_SRC_MATH_ILOGBF_H
11+
12+
namespace __llvm_libc {
13+
14+
int ilogbf(float x);
15+
16+
} // namespace __llvm_libc
17+
18+
#endif // LLVM_LIBC_SRC_MATH_ILOGBF_H

libc/src/math/ilogbl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Implementation of ilogbl 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/__support/common.h"
10+
#include "utils/FPUtil/ManipulationFunctions.h"
11+
12+
namespace __llvm_libc {
13+
14+
int LLVM_LIBC_ENTRYPOINT(ilogbl)(long double x) { return fputil::ilogb(x); }
15+
16+
} // namespace __llvm_libc

0 commit comments

Comments
 (0)