Skip to content

Commit 138efd7

Browse files
committed
Added shr & srl implementations for addresses
1 parent 8dc6d0b commit 138efd7

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use core::fmt;
66
use core::fmt::Debug;
77
use core::ops::{
8-
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Sub,
9-
SubAssign,
8+
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Shl,
9+
ShlAssign, Shr, ShrAssign, Sub, SubAssign,
1010
};
1111

1212
pub mod arch;
@@ -48,6 +48,10 @@ pub trait MemoryAddress:
4848
+ Sub<Self, Output = Self::RAW>
4949
+ Sub<<Self>::RAW, Output = Self>
5050
+ SubAssign<<Self>::RAW>
51+
+ Shr<usize, Output = Self>
52+
+ ShrAssign<usize>
53+
+ Shl<usize, Output = Self>
54+
+ ShlAssign<usize>
5155
+ fmt::Binary
5256
+ fmt::LowerHex
5357
+ fmt::UpperHex

src/macros.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@ macro_rules! impl_address {
131131
}
132132
}
133133

134+
impl core::ops::Shl<usize> for $T {
135+
type Output = $T;
136+
#[inline]
137+
fn shl(self, rhs: usize) -> Self::Output {
138+
Self::new_truncate(self.0 << rhs)
139+
}
140+
}
141+
142+
impl core::ops::Shr<usize> for $T {
143+
type Output = $T;
144+
#[inline]
145+
fn shr(self, rhs: usize) -> Self::Output {
146+
Self::new_truncate(self.0 >> rhs)
147+
}
148+
}
149+
150+
impl core::ops::ShlAssign<usize> for $T {
151+
#[inline]
152+
fn shl_assign(&mut self, rhs: usize) {
153+
*self = Self::new_truncate(self.0 << rhs);
154+
}
155+
}
156+
157+
impl core::ops::ShrAssign<usize> for $T {
158+
#[inline]
159+
fn shr_assign(&mut self, rhs: usize) {
160+
*self = Self::new_truncate(self.0 >> rhs);
161+
}
162+
}
163+
134164
impl From<$V> for $T {
135165
#[inline]
136166
fn from(addr: $V) -> $T {

0 commit comments

Comments
 (0)