Skip to content

cmov: use #[inline] instead of #[inline(always)] #924

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

Merged
merged 2 commits into from
Jul 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions cmov/src/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,72 +40,72 @@ macro_rules! csel_eq {
}

impl Cmov for u16 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:w}, {2:w}, {3:w}, NE", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:w}, {2:w}, {3:w}, EQ", self, value, condition);
}
}

impl CmovEq for u16 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, EQ", self, rhs, input, output);
}
}

impl Cmov for u32 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:w}, {2:w}, {3:w}, NE", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:w}, {2:w}, {3:w}, EQ", self, value, condition);
}
}

impl CmovEq for u32 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, EQ", self, rhs, input, output);
}
}

impl Cmov for u64 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:x}, {2:x}, {3:x}, NE", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
csel!("csel {1:x}, {2:x}, {3:x}, EQ", self, value, condition);
}
}

impl CmovEq for u64 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, NE", self, rhs, input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
csel_eq!("csel {3:w}, {4:w}, {5:w}, EQ", self, rhs, input, output);
}
Expand Down
16 changes: 8 additions & 8 deletions cmov/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ pub trait CmovEq {
}

impl Cmov for u8 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u16;
tmp.cmovnz(&(*value as u16), condition);
*self = tmp as u8;
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u16;
tmp.cmovz(&(*value as u16), condition);
Expand All @@ -76,19 +76,19 @@ impl Cmov for u8 {
}

impl CmovEq for u8 {
#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u16).cmoveq(&(*rhs as u16), input, output);
}

#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u16).cmovne(&(*rhs as u16), input, output);
}
}

impl Cmov for u128 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mut lo = (*self & u64::MAX as u128) as u64;
let mut hi = (*self >> 64) as u64;
Expand All @@ -99,7 +99,7 @@ impl Cmov for u128 {
*self = (lo as u128) | (hi as u128) << 64;
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mut lo = (*self & u64::MAX as u128) as u64;
let mut hi = (*self >> 64) as u64;
Expand All @@ -112,7 +112,7 @@ impl Cmov for u128 {
}

impl CmovEq for u128 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
let lo = (*self & u64::MAX as u128) as u64;
let hi = (*self >> 64) as u64;
Expand All @@ -123,7 +123,7 @@ impl CmovEq for u128 {
tmp.cmoveq(&0, input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
let lo = (*self & u64::MAX as u128) as u64;
let hi = (*self >> 64) as u64;
Expand Down
26 changes: 13 additions & 13 deletions cmov/src/portable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use crate::{Cmov, CmovEq, Condition};

impl Cmov for u16 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u64;
tmp.cmovnz(&(*value as u64), condition);
*self = tmp as u16;
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u64;
tmp.cmovz(&(*value as u64), condition);
Expand All @@ -25,26 +25,26 @@ impl Cmov for u16 {
}

impl CmovEq for u16 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u64).cmovne(&(*rhs as u64), input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u64).cmoveq(&(*rhs as u64), input, output);
}
}

impl Cmov for u32 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u64;
tmp.cmovnz(&(*value as u64), condition);
*self = tmp as u32;
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mut tmp = *self as u64;
tmp.cmovz(&(*value as u64), condition);
Expand All @@ -53,38 +53,38 @@ impl Cmov for u32 {
}

impl CmovEq for u32 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u64).cmovne(&(*rhs as u64), input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
(*self as u64).cmoveq(&(*rhs as u64), input, output);
}
}

impl Cmov for u64 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mask = is_non_zero(condition).wrapping_sub(1);
*self = (*self & mask) | (*value & !mask);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mask = (1 ^ is_non_zero(condition)).wrapping_sub(1);
*self = (*self & mask) | (*value & !mask);
}
}

impl CmovEq for u64 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovnz(&input, (self ^ rhs) as u8);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovz(&input, (self ^ rhs) as u8);
}
Expand All @@ -95,7 +95,7 @@ impl CmovEq for u64 {
/// # Returns
/// - `condition` is zero: `0`
/// - `condition` is non-zero: `1`
#[inline(always)]
#[inline]
fn is_non_zero(condition: Condition) -> u64 {
const SHIFT_BITS: usize = core::mem::size_of::<u64>() - 1;
let condition = condition as u64;
Expand Down
32 changes: 16 additions & 16 deletions cmov/src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,56 @@ macro_rules! cmov {
}

impl Cmov for u16 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovnz {1:e}, {2:e}", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovz {1:e}, {2:e}", self, value, condition);
}
}

impl CmovEq for u16 {
#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovz(&input, (self ^ rhs) as u8);
}

#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovnz(&input, (self ^ rhs) as u8);
}
}

impl Cmov for u32 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovnz {1:e}, {2:e}", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovz {1:e}, {2:e}", self, value, condition);
}
}

impl CmovEq for u32 {
#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovz(&input, (self ^ rhs) as u8);
}

#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovnz(&input, (self ^ rhs) as u8);
}
}

#[cfg(target_arch = "x86")]
impl Cmov for u64 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
let mut lo = (*self & u32::MAX as u64) as u32;
let mut hi = (*self >> 32) as u32;
Expand All @@ -86,7 +86,7 @@ impl Cmov for u64 {
*self = (lo as u64) | (hi as u64) << 32;
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
let mut lo = (*self & u32::MAX as u64) as u32;
let mut hi = (*self >> 32) as u32;
Expand All @@ -100,7 +100,7 @@ impl Cmov for u64 {

#[cfg(target_arch = "x86")]
impl CmovEq for u64 {
#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
let lo = (*self & u32::MAX as u64) as u32;
let hi = (*self >> 32) as u32;
Expand All @@ -111,7 +111,7 @@ impl CmovEq for u64 {
tmp.cmoveq(&0, input, output);
}

#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
let lo = (*self & u32::MAX as u64) as u32;
let hi = (*self >> 32) as u32;
Expand All @@ -125,25 +125,25 @@ impl CmovEq for u64 {

#[cfg(target_arch = "x86_64")]
impl Cmov for u64 {
#[inline(always)]
#[inline]
fn cmovnz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovnz {1:r}, {2:r}", self, value, condition);
}

#[inline(always)]
#[inline]
fn cmovz(&mut self, value: &Self, condition: Condition) {
cmov!("cmovz {1:r}, {2:r}", self, value, condition);
}
}

#[cfg(target_arch = "x86_64")]
impl CmovEq for u64 {
#[inline(always)]
#[inline]
fn cmoveq(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovz(&input, (self ^ rhs) as u8);
}

#[inline(always)]
#[inline]
fn cmovne(&self, rhs: &Self, input: Condition, output: &mut Condition) {
output.cmovnz(&input, (self ^ rhs) as u8);
}
Expand Down