Skip to content

Commit

Permalink
Merge pull request #61 from Shnatsel/inline-fallbacks
Browse files Browse the repository at this point in the history
Add `#[inline]` on fallback functions
  • Loading branch information
starkat99 authored Dec 30, 2022
2 parents ae9b799 + f24a4e1 commit a28a562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bfloat/convert.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit a28a562

Please sign in to comment.