Skip to content

Commit 78e1cb3

Browse files
authored
ctutils: impl CtEq/CtSelect for isize (#1283)
Uses the same strategy as `usize`
1 parent c6fe223 commit 78e1cb3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ctutils/src/traits/ct_eq.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ macro_rules! impl_ct_eq_with_cmov_eq {
3737

3838
impl_ct_eq_with_cmov_eq!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128);
3939

40+
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
41+
impl CtEq for isize {
42+
#[cfg(target_pointer_width = "32")]
43+
fn ct_eq(&self, other: &Self) -> Choice {
44+
(*self as i32).ct_eq(&(*other as i32))
45+
}
46+
47+
#[cfg(target_pointer_width = "64")]
48+
fn ct_eq(&self, other: &Self) -> Choice {
49+
(*self as i64).ct_eq(&(*other as i64))
50+
}
51+
}
52+
4053
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
4154
impl CtEq for usize {
4255
#[cfg(target_pointer_width = "32")]

ctutils/src/traits/ct_select.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ macro_rules! impl_ct_select_with_cmov {
4747

4848
impl_ct_select_with_cmov!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128);
4949

50+
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
51+
impl CtSelect for isize {
52+
#[cfg(target_pointer_width = "32")]
53+
#[inline]
54+
fn ct_select(&self, other: &Self, choice: Choice) -> Self {
55+
(*self as i32).ct_select(&(*other as i32), choice) as isize
56+
}
57+
58+
#[cfg(target_pointer_width = "64")]
59+
#[inline]
60+
fn ct_select(&self, other: &Self, choice: Choice) -> Self {
61+
(*self as i64).ct_select(&(*other as i64), choice) as isize
62+
}
63+
}
64+
5065
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
5166
impl CtSelect for usize {
5267
#[cfg(target_pointer_width = "32")]

0 commit comments

Comments
 (0)