some methods to check pointers for correct alignment

上级 7161c723
......@@ -51,6 +51,25 @@ fn zst_ptr() -> Self {
offset: 0,
}
}
pub fn is_aligned_to(&self, align: usize) -> bool {
self.offset % align == 0
}
pub fn check_align(&self, align: usize) -> EvalResult<'static, ()> {
if self.is_aligned_to(align) {
Ok(())
} else {
let mut best = self.offset;
let mut i = 1;
while best > 0 && (best & 1 == 0) {
best >>= 1;
i <<= 1;
}
Err(EvalError::AlignmentCheckFailed {
required: align,
has: i,
})
}
}
}
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册