Add spl case tests

next
Sayan Nandan 1 year ago
parent e2112c8bc1
commit 9297095f45
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -51,7 +51,7 @@ impl Datacell {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(
CUTag::BOOL,
DataRaw::word(SpecialPaddedWord::store(b).dword_promote()),
DataRaw::word(SpecialPaddedWord::store(b).dwordqn_promote()),
)
}
}
@ -73,7 +73,7 @@ impl Datacell {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(
CUTag::UINT,
DataRaw::word(SpecialPaddedWord::store(u).dword_promote()),
DataRaw::word(SpecialPaddedWord::store(u).dwordqn_promote()),
)
}
}
@ -95,7 +95,7 @@ impl Datacell {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(
CUTag::SINT,
DataRaw::word(SpecialPaddedWord::store(i).dword_promote()),
DataRaw::word(SpecialPaddedWord::store(i).dwordqn_promote()),
)
}
}
@ -117,7 +117,7 @@ impl Datacell {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(
CUTag::FLOAT,
DataRaw::word(SpecialPaddedWord::store(f).dword_promote()),
DataRaw::word(SpecialPaddedWord::store(f).dwordqn_promote()),
)
}
}
@ -228,7 +228,7 @@ impl<'a> From<LitIR<'a>> for Datacell {
Datacell::new(
CUTag::from(l.kind()),
// DO NOT RELY ON the payload's bit pattern; it's padded
DataRaw::word(l.data().dword_promote()),
DataRaw::word(l.data().dwordqn_promote()),
)
},
TagClass::Bin | TagClass::Str => unsafe {

@ -133,7 +133,7 @@ fn qwordnnn_all() {
#[test]
fn dwordqn_promotions() {
let x = SpecialPaddedWord::store(u64::MAX);
let y: NativeTword = x.dword_promote();
let y: NativeTword = x.dwordqn_promote();
let (uint, usize) = y.dwordqn_load_qw_nw();
assert_eq!(uint, u64::MAX);
assert_eq!(usize, ZERO_BLOCK.as_ptr() as usize);
@ -143,3 +143,28 @@ fn dwordqn_promotions() {
assert_eq!(usize_1, ZERO_BLOCK.as_ptr() as usize);
assert_eq!(usize_2, 0);
}
fn eval_special_case(x: SpecialPaddedWord, qw: u64, nw: usize) {
let y: NativeQword = x.dwordqn_promote();
assert_eq!(y.dwordqn_load_qw_nw(), (qw, nw));
let z: SpecialPaddedWord = unsafe {
let (a, b) = y.dwordqn_load_qw_nw();
SpecialPaddedWord::new(a, b)
};
assert_eq!(z.dwordqn_load_qw_nw(), (qw, nw));
}
#[test]
fn dwordqn_special_case_ldpk() {
let hello = "hello, world";
eval_special_case(
SpecialPaddedWord::store((hello.len(), hello.as_ptr())),
hello.len() as u64,
hello.as_ptr() as usize,
);
eval_special_case(
SpecialPaddedWord::store(u64::MAX),
u64::MAX,
ZERO_BLOCK.as_ptr() as usize,
);
}

@ -96,7 +96,7 @@ pub trait DwordQN: Sized {
Self::dwordqn_store_qw_nw(a, 0)
}
// promotions
fn dword_promote<W: DwordQN>(&self) -> W {
fn dwordqn_promote<W: DwordQN>(&self) -> W {
let (a, b) = self.dwordqn_load_qw_nw();
<W as DwordQN>::dwordqn_store_qw_nw(a, b)
}

Loading…
Cancel
Save