Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b58785d
feat: implement {,u}fromfp{,x}bf16 math functions
krishna2803 Aug 16, 2025
0a2b527
chore: add tests for {,u}fromfp{,x}bf16 math functions
krishna2803 Aug 16, 2025
baaf0e0
chore: update entrypoints
krishna2803 Aug 16, 2025
733f4f1
chore: update docs
krishna2803 Aug 16, 2025
4a80312
feat: implement next{after,down,toward,up}bf16 math functions
krishna2803 Aug 17, 2025
446e637
chore: add smoke tests for next{after,down,toward,up}bf16 math functions
krishna2803 Aug 17, 2025
a98b928
chore: update entrypoints
krishna2803 Aug 17, 2025
12f1923
docs: add next{after,down,toward,up}bf16 math functions
krishna2803 Aug 17, 2025
6f8d84d
feat: implement {get,set}payloadbf16 and setpayloadsigbf16 math funct…
krishna2803 Aug 17, 2025
c8f4380
chore: implement smoke tests for {get,set}payloadbf16 and setpayloads…
krishna2803 Aug 17, 2025
8ea9354
fix: add correct static_cast for fputil::getpload for bfloat16
krishna2803 Aug 17, 2025
fc2b6eb
chore: update entrypoints
krishna2803 Aug 17, 2025
70e4463
docs: add {get,set}payloadbf16 and setpayloadsigbf16 math functions
krishna2803 Aug 17, 2025
ea9625e
feat: implement nanbf16 math function
krishna2803 Aug 17, 2025
ae0e616
chore: add smoke tests for nanbf16 math function
krishna2803 Aug 17, 2025
27364c5
chore: update entrypoints
krishna2803 Aug 17, 2025
250cfea
docs: add nanbf16
krishna2803 Aug 17, 2025
832bbc6
feat: implement {frexp,ilogb,ldexp,llogb,logb}bf16 math functions
krishna2803 Aug 19, 2025
a08faab
chore: add smoke tests for {frexp,ilogb,ldexp,llogb,logb}bf16 math fu…
krishna2803 Aug 19, 2025
5fb2a5c
chore: update entrypoints
krishna2803 Aug 19, 2025
5f0ab92
fix: infinite recursion and tests
krishna2803 Aug 19, 2025
49dc65d
docs: add {frexp,ilogb,ldexp,llogb,logb}bf16 math functions
krishna2803 Aug 19, 2025
2bf7920
fix: add cpp::min in LdExpTest.h
krishna2803 Aug 20, 2025
92cdc99
merge: branch 'main' into users/krishna2803/frexpbf16
krishna2803 Aug 24, 2025
3c062b9
refactor: remove redundant if-else
krishna2803 Aug 24, 2025
dc0e3d7
merge: branch 'main' into users/krishna2803/frexpbf16
krishna2803 Aug 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc/config/baremetal/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/darwin/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/darwin/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/gpu/amdgpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/gpu/nvptx/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -873,13 +873,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
5 changes: 5 additions & 0 deletions libc/config/windows/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,18 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
libc.src.math.frexpbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
libc.src.math.lrintbf16
libc.src.math.lroundbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.ilogbbf16
libc.src.math.ldexpbf16
libc.src.math.llogbbf16
libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
Expand Down
10 changes: 5 additions & 5 deletions libc/docs/headers/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fmul | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.3 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| frexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.7 | F.10.3.7 |
| frexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.7 | F.10.3.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fromfp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
Expand All @@ -189,21 +189,21 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| getpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| ilogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.8 | F.10.3.8 |
| ilogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| iscanonical | |check| | |check| | |check| | |check| | |check| | | 7.12.3.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| issignaling | |check| | |check| | |check| | |check| | |check| | | 7.12.3.8 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| ldexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.9 | F.10.3.9 |
| ldexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.10 | F.10.3.10 |
| llogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
Expand Down
5 changes: 1 addition & 4 deletions libc/src/__support/FPUtil/BasicOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> getpayload(T x) {

return static_cast<T>(payload_dfloat);
} else {
if constexpr (cpp::is_same_v<T, bfloat16>)
return T(static_cast<int>(payload));
else
return static_cast<T>(payload);
return static_cast<T>(payload);
}
}

Expand Down
2 changes: 2 additions & 0 deletions libc/src/__support/FPUtil/bfloat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct BFloat16 {
xd(sign, 0, value);
bits = xd.template as<bfloat16, /*ShouldSignalExceptions=*/true>().bits;

} else if constexpr (cpp::is_convertible_v<T, BFloat16>) {
bits = value.operator BFloat16().bits;
} else {
bits = fputil::cast<bfloat16>(static_cast<float>(value)).bits;
}
Expand Down
5 changes: 5 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ add_math_entrypoint_object(frexpf)
add_math_entrypoint_object(frexpl)
add_math_entrypoint_object(frexpf16)
add_math_entrypoint_object(frexpf128)
add_math_entrypoint_object(frexpbf16)

add_math_entrypoint_object(fromfp)
add_math_entrypoint_object(fromfpf)
Expand Down Expand Up @@ -343,6 +344,7 @@ add_math_entrypoint_object(ilogbf)
add_math_entrypoint_object(ilogbl)
add_math_entrypoint_object(ilogbf16)
add_math_entrypoint_object(ilogbf128)
add_math_entrypoint_object(ilogbbf16)

add_math_entrypoint_object(isnan)
add_math_entrypoint_object(isnanf)
Expand All @@ -359,12 +361,14 @@ add_math_entrypoint_object(llogbf)
add_math_entrypoint_object(llogbl)
add_math_entrypoint_object(llogbf16)
add_math_entrypoint_object(llogbf128)
add_math_entrypoint_object(llogbbf16)

add_math_entrypoint_object(ldexp)
add_math_entrypoint_object(ldexpf)
add_math_entrypoint_object(ldexpl)
add_math_entrypoint_object(ldexpf16)
add_math_entrypoint_object(ldexpf128)
add_math_entrypoint_object(ldexpbf16)

add_math_entrypoint_object(log10)
add_math_entrypoint_object(log10f)
Expand All @@ -386,6 +390,7 @@ add_math_entrypoint_object(logbf)
add_math_entrypoint_object(logbl)
add_math_entrypoint_object(logbf16)
add_math_entrypoint_object(logbf128)
add_math_entrypoint_object(logbbf16)

add_math_entrypoint_object(llrint)
add_math_entrypoint_object(llrintf)
Expand Down
21 changes: 21 additions & 0 deletions libc/src/math/frexpbf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for frexpbf16 ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FREXPFB16_H
#define LLVM_LIBC_SRC_MATH_FREXPFB16_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

bfloat16 frexpbf16(bfloat16 x, int *exp);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FREXPFB16_H
Loading
Loading