Skip to content

Commit 94c70a7

Browse files
authored
Merge pull request #7 from rust-lang/inline-more
Add missing `#[inline]` to non-generic functions.
2 parents 6959ffd + 28d82c9 commit 94c70a7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/ieee.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct IeeeFloat<S> {
3939
/// large to store the largest significands by itself.
4040
type Limb = u128;
4141
const LIMB_BITS: usize = 128;
42+
#[inline(always)]
4243
fn limbs_for_bits(bits: usize) -> usize {
4344
(bits + LIMB_BITS - 1) / LIMB_BITS
4445
}
@@ -337,6 +338,7 @@ impl Semantics for X87DoubleExtendedS {
337338
/// exponent!=0 nor all 1's, integer bit 0 ("unnormal")
338339
/// exponent = 0, integer bit 1 ("pseudodenormal")
339340
/// At the moment, the first three are treated as NaNs, the last one as Normal.
341+
#[inline]
340342
fn from_bits(bits: u128) -> IeeeFloat<Self> {
341343
let sign = bits & (1 << (Self::BITS - 1));
342344
let exponent = ((bits & !sign) >> (Self::BITS - 1 - Self::EXP_BITS)) & ((1 << Self::EXP_BITS) - 1);
@@ -373,6 +375,7 @@ impl Semantics for X87DoubleExtendedS {
373375
r
374376
}
375377

378+
#[inline]
376379
fn to_bits(x: IeeeFloat<Self>) -> u128 {
377380
// Get integer bit from significand.
378381
let integer_bit = sig::get_bit(&x.sig, Self::PRECISION - 1);
@@ -2656,6 +2659,7 @@ impl<S: Semantics> IeeeFloat<S> {
26562659

26572660
impl Loss {
26582661
/// Combine the effect of two lost fractions.
2662+
#[inline]
26592663
fn combine(self, less_significant: Loss) -> Loss {
26602664
let mut more_significant = self;
26612665
if less_significant != Loss::ExactlyZero {
@@ -2671,6 +2675,7 @@ impl Loss {
26712675

26722676
/// Return the fraction lost were a bignum truncated losing the least
26732677
/// significant `bits` bits.
2678+
#[inline]
26742679
fn through_truncation(limbs: &[Limb], bits: usize) -> Loss {
26752680
if bits == 0 {
26762681
return Loss::ExactlyZero;
@@ -2703,11 +2708,13 @@ mod sig {
27032708
use core::cmp::Ordering;
27042709
use core::mem;
27052710

2711+
#[inline]
27062712
pub(super) fn is_all_zeros(limbs: &[Limb]) -> bool {
27072713
limbs.iter().all(|&l| l == 0)
27082714
}
27092715

27102716
/// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
2717+
#[inline]
27112718
pub(super) fn olsb(limbs: &[Limb]) -> usize {
27122719
for i in 0..limbs.len() {
27132720
if limbs[i] != 0 {
@@ -2719,6 +2726,7 @@ mod sig {
27192726
}
27202727

27212728
/// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
2729+
#[inline]
27222730
pub(super) fn omsb(limbs: &[Limb]) -> usize {
27232731
for i in (0..limbs.len()).rev() {
27242732
if limbs[i] != 0 {
@@ -2730,6 +2738,7 @@ mod sig {
27302738
}
27312739

27322740
/// Comparison (unsigned) of two significands.
2741+
#[inline]
27332742
pub(super) fn cmp(a: &[Limb], b: &[Limb]) -> Ordering {
27342743
assert_eq!(a.len(), b.len());
27352744
for (a, b) in a.iter().zip(b).rev() {
@@ -2743,16 +2752,19 @@ mod sig {
27432752
}
27442753

27452754
/// Extract the given bit.
2755+
#[inline]
27462756
pub(super) fn get_bit(limbs: &[Limb], bit: usize) -> bool {
27472757
limbs[bit / LIMB_BITS] & (1 << (bit % LIMB_BITS)) != 0
27482758
}
27492759

27502760
/// Set the given bit.
2761+
#[inline]
27512762
pub(super) fn set_bit(limbs: &mut [Limb], bit: usize) {
27522763
limbs[bit / LIMB_BITS] |= 1 << (bit % LIMB_BITS);
27532764
}
27542765

27552766
/// Shift `dst` left `bits` bits, subtract `bits` from its exponent.
2767+
#[inline]
27562768
pub(super) fn shift_left(dst: &mut [Limb], exp: &mut ExpInt, bits: usize) {
27572769
if bits > 0 {
27582770
// Our exponent should not underflow.
@@ -2785,6 +2797,7 @@ mod sig {
27852797
}
27862798

27872799
/// Shift `dst` right `bits` bits noting lost fraction.
2800+
#[inline]
27882801
pub(super) fn shift_right(dst: &mut [Limb], exp: &mut ExpInt, bits: usize) -> Loss {
27892802
let loss = Loss::through_truncation(dst, bits);
27902803

@@ -2823,6 +2836,7 @@ mod sig {
28232836
/// Copy the bit vector of width `src_bits` from `src`, starting at bit SRC_LSB,
28242837
/// to `dst`, such that the bit SRC_LSB becomes the least significant bit of `dst`.
28252838
/// All high bits above `src_bits` in `dst` are zero-filled.
2839+
#[inline]
28262840
pub(super) fn extract(dst: &mut [Limb], src: &[Limb], src_bits: usize, src_lsb: usize) {
28272841
if src_bits == 0 {
28282842
return;
@@ -2856,6 +2870,7 @@ mod sig {
28562870

28572871
/// We want the most significant PRECISION bits of `src`. There may not
28582872
/// be that many; extract what we can.
2873+
#[inline]
28592874
pub(super) fn from_limbs(dst: &mut [Limb], src: &[Limb], precision: usize) -> (Loss, ExpInt) {
28602875
let omsb = omsb(src);
28612876

@@ -2871,6 +2886,7 @@ mod sig {
28712886
/// For every consecutive chunk of `bits` bits from `limbs`,
28722887
/// going from most significant to the least significant bits,
28732888
/// call `f` to transform those bits and store the result back.
2889+
#[inline]
28742890
pub(super) fn each_chunk<F: FnMut(Limb) -> Limb>(limbs: &mut [Limb], bits: usize, mut f: F) {
28752891
assert_eq!(LIMB_BITS % bits, 0);
28762892
for limb in limbs.iter_mut().rev() {
@@ -2883,6 +2899,7 @@ mod sig {
28832899
}
28842900

28852901
/// Increment in-place, return the carry flag.
2902+
#[inline]
28862903
pub(super) fn increment(dst: &mut [Limb]) -> Limb {
28872904
for x in dst {
28882905
*x = x.wrapping_add(1);
@@ -2895,6 +2912,7 @@ mod sig {
28952912
}
28962913

28972914
/// Decrement in-place, return the borrow flag.
2915+
#[inline]
28982916
pub(super) fn decrement(dst: &mut [Limb]) -> Limb {
28992917
for x in dst {
29002918
*x = x.wrapping_sub(1);
@@ -2907,6 +2925,7 @@ mod sig {
29072925
}
29082926

29092927
/// `a += b + c` where `c` is zero or one. Returns the carry flag.
2928+
#[inline]
29102929
pub(super) fn add(a: &mut [Limb], b: &[Limb], mut c: Limb) -> Limb {
29112930
assert!(c <= 1);
29122931

@@ -2921,6 +2940,7 @@ mod sig {
29212940
}
29222941

29232942
/// `a -= b + c` where `c` is zero or one. Returns the borrow flag.
2943+
#[inline]
29242944
pub(super) fn sub(a: &mut [Limb], b: &[Limb], mut c: Limb) -> Limb {
29252945
assert!(c <= 1);
29262946

@@ -2935,6 +2955,7 @@ mod sig {
29352955
}
29362956

29372957
/// `a += b` or `a -= b`. Does not preserve `b`.
2958+
#[inline]
29382959
pub(super) fn add_or_sub(
29392960
a_sig: &mut [Limb],
29402961
a_exp: &mut ExpInt,
@@ -3000,6 +3021,7 @@ mod sig {
30003021
/// `(n - 1) * (n - 1) + 2 * (n - 1) == (n - 1) * (n + 1)`
30013022
///
30023023
/// which is less than n^2.
3024+
#[inline]
30033025
pub(super) fn widening_mul(a: Limb, b: Limb) -> [Limb; 2] {
30043026
let mut wide = [0, 0];
30053027

@@ -3022,6 +3044,7 @@ mod sig {
30223044
}
30233045

30243046
/// `dst = a * b` (for normal `a` and `b`). Returns the lost fraction.
3047+
#[inline]
30253048
pub(super) fn mul<'a>(
30263049
dst: &mut [Limb],
30273050
exp: &mut ExpInt,
@@ -3092,6 +3115,7 @@ mod sig {
30923115

30933116
/// `quotient = dividend / divisor`. Returns the lost fraction.
30943117
/// Does not preserve `dividend` or `divisor`.
3118+
#[inline]
30953119
pub(super) fn div(
30963120
quotient: &mut [Limb],
30973121
exp: &mut ExpInt,

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub enum Round {
127127

128128
impl Neg for Round {
129129
type Output = Round;
130+
#[inline]
130131
fn neg(self) -> Round {
131132
match self {
132133
Round::TowardPositive => Round::TowardNegative,
@@ -608,6 +609,7 @@ macro_rules! float_common_impls {
608609
where
609610
Self: Float,
610611
{
612+
#[inline]
611613
fn default() -> Self {
612614
Self::ZERO
613615
}
@@ -618,6 +620,7 @@ macro_rules! float_common_impls {
618620
Self: Float,
619621
{
620622
type Err = ParseError;
623+
#[inline]
621624
fn from_str(s: &str) -> Result<Self, ParseError> {
622625
Self::from_str_r(s, Round::NearestTiesToEven).map(|x| x.value)
623626
}
@@ -630,6 +633,7 @@ macro_rules! float_common_impls {
630633
Self: Float,
631634
{
632635
type Output = StatusAnd<Self>;
636+
#[inline]
633637
fn add(self, rhs: Self) -> StatusAnd<Self> {
634638
self.add_r(rhs, Round::NearestTiesToEven)
635639
}
@@ -640,6 +644,7 @@ macro_rules! float_common_impls {
640644
Self: Float,
641645
{
642646
type Output = StatusAnd<Self>;
647+
#[inline]
643648
fn sub(self, rhs: Self) -> StatusAnd<Self> {
644649
self.sub_r(rhs, Round::NearestTiesToEven)
645650
}
@@ -650,6 +655,7 @@ macro_rules! float_common_impls {
650655
Self: Float,
651656
{
652657
type Output = StatusAnd<Self>;
658+
#[inline]
653659
fn mul(self, rhs: Self) -> StatusAnd<Self> {
654660
self.mul_r(rhs, Round::NearestTiesToEven)
655661
}
@@ -660,6 +666,7 @@ macro_rules! float_common_impls {
660666
Self: Float,
661667
{
662668
type Output = StatusAnd<Self>;
669+
#[inline]
663670
fn div(self, rhs: Self) -> StatusAnd<Self> {
664671
self.div_r(rhs, Round::NearestTiesToEven)
665672
}
@@ -670,6 +677,7 @@ macro_rules! float_common_impls {
670677
Self: Float,
671678
{
672679
type Output = StatusAnd<Self>;
680+
#[inline]
673681
fn rem(self, rhs: Self) -> StatusAnd<Self> {
674682
self.c_fmod(rhs)
675683
}
@@ -679,6 +687,7 @@ macro_rules! float_common_impls {
679687
where
680688
Self: Float,
681689
{
690+
#[inline]
682691
fn add_assign(&mut self, rhs: Self) {
683692
*self = (*self + rhs).value;
684693
}
@@ -688,6 +697,7 @@ macro_rules! float_common_impls {
688697
where
689698
Self: Float,
690699
{
700+
#[inline]
691701
fn sub_assign(&mut self, rhs: Self) {
692702
*self = (*self - rhs).value;
693703
}
@@ -697,6 +707,7 @@ macro_rules! float_common_impls {
697707
where
698708
Self: Float,
699709
{
710+
#[inline]
700711
fn mul_assign(&mut self, rhs: Self) {
701712
*self = (*self * rhs).value;
702713
}
@@ -706,6 +717,7 @@ macro_rules! float_common_impls {
706717
where
707718
Self: Float,
708719
{
720+
#[inline]
709721
fn div_assign(&mut self, rhs: Self) {
710722
*self = (*self / rhs).value;
711723
}
@@ -715,6 +727,7 @@ macro_rules! float_common_impls {
715727
where
716728
Self: Float,
717729
{
730+
#[inline]
718731
fn rem_assign(&mut self, rhs: Self) {
719732
*self = (*self % rhs).value;
720733
}

0 commit comments

Comments
 (0)