From a3e33cfb6e6eddf0e47bc98fd46075fab30978e1 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 23 Apr 2013 13:56:49 -0400 Subject: [PATCH] inline the primitive numeric operations --- src/libcore/num/f32.rs | 13 +++++++++++++ src/libcore/num/float.rs | 9 +++++++++ src/libcore/num/int-template.rs | 18 ++++++++++++++++++ src/libcore/num/uint-template.rs | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 2e7dc98e3c5..62004710196 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -301,20 +301,28 @@ impl num::One for f32 { #[cfg(notest)] impl Add for f32 { + #[inline(always)] fn add(&self, other: &f32) -> f32 { *self + *other } } + #[cfg(notest)] impl Sub for f32 { + #[inline(always)] fn sub(&self, other: &f32) -> f32 { *self - *other } } + #[cfg(notest)] impl Mul for f32 { + #[inline(always)] fn mul(&self, other: &f32) -> f32 { *self * *other } } + #[cfg(stage0,notest)] impl Div for f32 { + #[inline(always)] fn div(&self, other: &f32) -> f32 { *self / *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -322,10 +330,13 @@ impl Quot for f32 { #[inline(always)] fn quot(&self, other: &f32) -> f32 { *self / *other } } + #[cfg(stage0,notest)] impl Modulo for f32 { + #[inline(always)] fn modulo(&self, other: &f32) -> f32 { *self % *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -333,8 +344,10 @@ impl Rem for f32 { #[inline(always)] fn rem(&self, other: &f32) -> f32 { *self % *other } } + #[cfg(notest)] impl Neg for f32 { + #[inline(always)] fn neg(&self) -> f32 { -*self } } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 9cf14cf0f49..c5c1e52a14c 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -455,18 +455,25 @@ impl num::Round for float { #[cfg(notest)] impl Add for float { + #[inline(always)] fn add(&self, other: &float) -> float { *self + *other } } + #[cfg(notest)] impl Sub for float { + #[inline(always)] fn sub(&self, other: &float) -> float { *self - *other } } + #[cfg(notest)] impl Mul for float { + #[inline(always)] fn mul(&self, other: &float) -> float { *self * *other } } + #[cfg(stage0,notest)] impl Div for float { + #[inline(always)] fn div(&self, other: &float) -> float { *self / *other } } #[cfg(stage1,notest)] @@ -478,6 +485,7 @@ impl Quot for float { } #[cfg(stage0,notest)] impl Modulo for float { + #[inline(always)] fn modulo(&self, other: &float) -> float { *self % *other } } #[cfg(stage1,notest)] @@ -489,6 +497,7 @@ impl Rem for float { } #[cfg(notest)] impl Neg for float { + #[inline(always)] fn neg(&self) -> float { -*self } } diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 8f448994c98..684083f53e9 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -175,20 +175,28 @@ impl num::One for T { #[cfg(notest)] impl Add for T { + #[inline(always)] fn add(&self, other: &T) -> T { *self + *other } } + #[cfg(notest)] impl Sub for T { + #[inline(always)] fn sub(&self, other: &T) -> T { *self - *other } } + #[cfg(notest)] impl Mul for T { + #[inline(always)] fn mul(&self, other: &T) -> T { *self * *other } } + #[cfg(stage0,notest)] impl Div for T { + #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -196,10 +204,13 @@ impl Quot for T { #[inline(always)] fn quot(&self, other: &T) -> T { *self / *other } } + #[cfg(stage0,notest)] impl Modulo for T { + #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -207,8 +218,10 @@ impl Rem for T { #[inline(always)] fn rem(&self, other: &T) -> T { *self % *other } } + #[cfg(notest)] impl Neg for T { + #[inline(always)] fn neg(&self) -> T { -*self } } @@ -217,26 +230,31 @@ impl BitOr for T { #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } + #[cfg(notest)] impl BitAnd for T { #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } + #[cfg(notest)] impl BitXor for T { #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } + #[cfg(notest)] impl Shl for T { #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } + #[cfg(notest)] impl Shr for T { #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } + #[cfg(notest)] impl Not for T { #[inline(always)] diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 6f3f402f92d..4bb93907a3a 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -140,20 +140,28 @@ impl num::One for T { #[cfg(notest)] impl Add for T { + #[inline(always)] fn add(&self, other: &T) -> T { *self + *other } } + #[cfg(notest)] impl Sub for T { + #[inline(always)] fn sub(&self, other: &T) -> T { *self - *other } } + #[cfg(notest)] impl Mul for T { + #[inline(always)] fn mul(&self, other: &T) -> T { *self * *other } } + #[cfg(stage0,notest)] impl Div for T { + #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -161,10 +169,13 @@ impl Quot for T { #[inline(always)] fn quot(&self, other: &T) -> T { *self / *other } } + #[cfg(stage0,notest)] impl Modulo for T { + #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } + #[cfg(stage1,notest)] #[cfg(stage2,notest)] #[cfg(stage3,notest)] @@ -172,8 +183,10 @@ impl Rem for T { #[inline(always)] fn rem(&self, other: &T) -> T { *self % *other } } + #[cfg(notest)] impl Neg for T { + #[inline(always)] fn neg(&self) -> T { -*self } } @@ -182,26 +195,31 @@ impl BitOr for T { #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } + #[cfg(notest)] impl BitAnd for T { #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } + #[cfg(notest)] impl BitXor for T { #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } + #[cfg(notest)] impl Shl for T { #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } + #[cfg(notest)] impl Shr for T { #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } + #[cfg(notest)] impl Not for T { #[inline(always)]