Skip to content

Instantly share code, notes, and snippets.

@shadeglare
Created April 1, 2023 11:52
Show Gist options
  • Save shadeglare/1f8f0d147db937187a80483e49be9c94 to your computer and use it in GitHub Desktop.
Save shadeglare/1f8f0d147db937187a80483e49be9c94 to your computer and use it in GitHub Desktop.
pub trait DwordOps<TOutput> {
fn low_dword(self) -> TOutput;
fn high_dword(self) -> TOutput;
}
impl DwordOps<u64> for u64 {
#[inline(always)]
fn low_dword(self) -> u64 {
self & 0x0000_0000_ffff_ffff_u64
}
#[inline(always)]
fn high_dword(self) -> u64 {
self >> 0x0000_0000_0000_0020_u64 & 0x0000_0000_ffff_ffff_u64
}
}
impl DwordOps<u32> for u64 {
#[inline(always)]
fn low_dword(self) -> u32 {
DwordOps::<u64>::low_dword(self) as u32
}
#[inline(always)]
fn high_dword(self) -> u32 {
DwordOps::<u64>::high_dword(self) as u32
}
}
impl DwordOps<u64> for i64 {
#[inline(always)]
fn low_dword(self) -> u64 {
DwordOps::<u64>::low_dword(self as u64)
}
#[inline(always)]
fn high_dword(self) -> u64 {
DwordOps::<u64>::high_dword(self as u64)
}
}
impl DwordOps<u32> for i64 {
#[inline(always)]
fn low_dword(self) -> u32 {
DwordOps::<u32>::low_dword(self as u64)
}
#[inline(always)]
fn high_dword(self) -> u32 {
DwordOps::<u32>::high_dword(self as u64)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment