fix some bugs

This commit is contained in:
Solomon Ucko 2022-08-09 21:51:42 -04:00
parent 45a3975d31
commit 570559ae27
3 changed files with 42 additions and 22 deletions

View File

@ -43,8 +43,8 @@ macro_rules! basic_op {
macro_rules! logic_op {
(
$imp:ident, $imp_assign:ident, $typ:ident, $typ_inner:ident, $fun:ident, $fun_assign:ident;
$i:ident, $j:ident, $r:ident, $s:ident, $slice:ident, $slice1:ident, $slice2:ident, $res:ident;
$inline_heap:tt, $heap_heap:tt
$i:ident, $j:ident, $r:ident, $s:ident, $slice:ident, $slice1:ident, $slice2:ident, $min:ident, $res:ident;
$inline_heap:tt, $heap_heap_create_res:tt, $heap_heap_return:tt
) => {
fn $fun(a: &$typ, b: &$typ) -> $typ {
match (&a.0, &b.0) {
@ -63,15 +63,12 @@ macro_rules! logic_op {
let $slice1 = unsafe { core::slice::from_raw_parts($r, $s) };
let $slice2 = unsafe { core::slice::from_raw_parts($i, $j) };
let min = std::cmp::min($slice1.len(), $slice2.len());
let $min = std::cmp::min($slice1.len(), $slice2.len());
let mut $res = Vec::with_capacity(min);
#[allow(unused_mut)]
let mut $res = $heap_heap_create_res;
for l in 0..min {
$res.push($slice1[l] & $slice2[l]);
}
$heap_heap
$heap_heap_return
}
}
}
@ -93,7 +90,7 @@ macro_rules! logic_op {
}
macro_rules! inline_heap_to_heap {
($op_assign:tt, $i:ident, $slice:ident) => {
($op_assign:tt; $i:ident, $slice:ident) => {
let mut retvec = $slice.to_vec();
let mut v = $i;
@ -110,7 +107,21 @@ macro_rules! inline_heap_to_heap {
}
}
macro_rules! heap_heap_to_any {
macro_rules! heap_heap_create_res_longest {
($fun:ident; $slice1:ident, $slice2:ident, $min:ident) => {
let mut res = if $slice1.len() > $slice2.len() {
$slice1.to_vec()
} else {
$slice2.to_vec()
};
for l in 0..$min {
res[l] = $slice1[l].$fun($slice2[l]);
}
res
}
}
macro_rules! heap_heap_return_any {
($res:ident) => {
while $res.len() != 1 && $res[$res.len() - 1] == 0 {
$res.pop();
@ -132,7 +143,7 @@ macro_rules! heap_heap_to_any {
logic_op! {
BitAnd, BitAndAssign, SmallUint, SmallUintType, bitand, bitand_assign;
i, j, r, s, slice, slice1, slice2, res;
i, j, r, s, slice, slice1, slice2, min, res;
{
let mut j = 0u128;
for i in 0..4 {
@ -141,13 +152,21 @@ logic_op! {
}
SmallUint(SmallUintType::Inline(i & j))
},
{ heap_heap_to_any! { res } }
{
let mut res = Vec::with_capacity(min);
for l in 0..min {
res.push(slice1[l] & slice2[l]);
}
res
},
{ heap_heap_return_any! { res } }
}
logic_op! {
BitOr, BitOrAssign, SmallUint, SmallUintType, bitor, bitor_assign;
i, j, r, s, slice, slice1, slice2, res;
{ inline_heap_to_heap! { |=, i, slice } },
i, j, r, s, slice, slice1, slice2, min, res;
{ inline_heap_to_heap! { |=; i, slice } },
{ heap_heap_create_res_longest! { bitor; slice1, slice2, min }},
{
let mut slice = ManuallyDrop::new(res.into_boxed_slice());
SmallUint(SmallUintType::Heap((slice.as_mut_ptr(), slice.len())))
@ -156,7 +175,8 @@ logic_op! {
logic_op! {
BitXor, BitXorAssign, SmallUint, SmallUintType, bitxor, bitxor_assign;
i, j, r, s, slice, slice1, slice2, res;
{ inline_heap_to_heap! { |=, i, slice } },
{ heap_heap_to_any! { res } }
i, j, r, s, slice, slice1, slice2, min, res;
{ inline_heap_to_heap! { ^=; i, slice } },
{ heap_heap_create_res_longest! { bitxor; slice1, slice2, min }},
{ heap_heap_return_any! { res } }
}

View File

@ -582,7 +582,7 @@ impl MulAssign<SmallInt> for SmallInt {
}
}
fn div(a: &SmallUint, b: &SmallUint) -> SmallUint {
fn div(_a: &SmallUint, _b: &SmallUint) -> SmallUint {
todo!()
}
@ -600,7 +600,7 @@ impl DivAssign<SmallUint> for SmallUint {
}
}
fn div_signed(a: &SmallInt, b: &SmallInt) -> SmallInt {
fn div_signed(_a: &SmallInt, _b: &SmallInt) -> SmallInt {
todo!()
}

View File

@ -12,7 +12,7 @@ impl core::fmt::Debug for SmallInt {
SmallIntType::Inline(i) => {
write!(f, "{}", i)?;
}
SmallIntType::Heap((r, s)) => {
SmallIntType::Heap((_r, _s)) => {
#[cfg(feature = "num-bigint")]
write!(f, "{}", BigInt::from(self))?;
@ -30,7 +30,7 @@ impl core::fmt::Debug for SmallUint {
SmallUintType::Inline(i) => {
write!(f, "{}", i)?;
}
SmallUintType::Heap((r, s)) => {
SmallUintType::Heap((_r, _s)) => {
#[cfg(feature = "num-bigint")]
write!(f, "{}", BigUint::from(self))?;