Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #[inline] on fallback functions #61

Merged
merged 1 commit into from Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bfloat/convert.rs
@@ -1,6 +1,7 @@
use crate::leading_zeros::leading_zeros_u16;
use core::mem;

#[inline]
pub(crate) const fn f32_to_bf16(value: f32) -> u16 {
// TODO: Replace mem::transmute with to_bits() once to_bits is const-stabilized
// Convert to raw bytes
Expand All @@ -21,6 +22,7 @@ pub(crate) const fn f32_to_bf16(value: f32) -> u16 {
}
}

#[inline]
pub(crate) const fn f64_to_bf16(value: f64) -> u16 {
// TODO: Replace mem::transmute with to_bits() once to_bits is const-stabilized
// Convert to raw bytes, truncating the last 32-bits of mantissa; that precision will always
Expand Down Expand Up @@ -88,6 +90,7 @@ pub(crate) const fn f64_to_bf16(value: f64) -> u16 {
}
}

#[inline]
pub(crate) const fn bf16_to_f32(i: u16) -> f32 {
// TODO: Replace mem::transmute with from_bits() once from_bits is const-stabilized
// If NaN, keep current mantissa but also set most significiant mantissa bit
Expand All @@ -98,6 +101,7 @@ pub(crate) const fn bf16_to_f32(i: u16) -> f32 {
}
}

#[inline]
pub(crate) const fn bf16_to_f64(i: u16) -> f64 {
// TODO: Replace mem::transmute with from_bits() once from_bits is const-stabilized
// Check for signed zero
Expand Down
4 changes: 4 additions & 0 deletions src/binary16/convert.rs
Expand Up @@ -143,6 +143,7 @@ convert_fn! {
// which can be simplified into
// (mantissa & round_bit) != 0 && (mantissa & (3 * round_bit - 1)) != 0

#[inline]
pub(crate) const fn f32_to_f16_fallback(value: f32) -> u16 {
// TODO: Replace mem::transmute with to_bits() once to_bits is const-stabilized
// Convert to raw bytes
Expand Down Expand Up @@ -203,6 +204,7 @@ pub(crate) const fn f32_to_f16_fallback(value: f32) -> u16 {
}
}

#[inline]
pub(crate) const fn f64_to_f16_fallback(value: f64) -> u16 {
// Convert to raw bytes, truncating the last 32-bits of mantissa; that precision will always
// be lost on half-precision.
Expand Down Expand Up @@ -270,6 +272,7 @@ pub(crate) const fn f64_to_f16_fallback(value: f64) -> u16 {
}
}

#[inline]
pub(crate) const fn f16_to_f32_fallback(i: u16) -> f32 {
// Check for signed zero
// TODO: Replace mem::transmute with from_bits() once from_bits is const-stabilized
Expand Down Expand Up @@ -316,6 +319,7 @@ pub(crate) const fn f16_to_f32_fallback(i: u16) -> f32 {
unsafe { mem::transmute(sign | exp | man) }
}

#[inline]
pub(crate) const fn f16_to_f64_fallback(i: u16) -> f64 {
// Check for signed zero
// TODO: Replace mem::transmute with from_bits() once from_bits is const-stabilized
Expand Down