some cleanup and bug fix
This commit is contained in:
parent
ca1d471646
commit
4502a64514
|
@ -1248,13 +1248,13 @@ impl<'a> Codegen<'a> {
|
||||||
let signed = bt::is_signed(ty);
|
let signed = bt::is_signed(ty);
|
||||||
|
|
||||||
if let Loc::Imm(mut imm) = right.loc
|
if let Loc::Imm(mut imm) = right.loc
|
||||||
&& let Some(oper) = Self::imm_math_op(op, signed, size, false)
|
&& let Some(oper) = Self::imm_math_op(op, signed, size)
|
||||||
{
|
{
|
||||||
if matches!(op, T::Add | T::Sub) {
|
if matches!(op, T::Add | T::Sub)
|
||||||
if bt::is_pointer(left.ty) {
|
&& let TypeKind::Pointer(ty) = TypeKind::from_ty(ty)
|
||||||
let size = self.size_of(self.pointers[ty as usize]);
|
{
|
||||||
imm *= size;
|
let size = self.size_of(self.pointers[ty as usize]);
|
||||||
}
|
imm *= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.code.encode(oper(lhs.0, lhs.0, imm));
|
self.code.encode(oper(lhs.0, lhs.0, imm));
|
||||||
|
@ -1381,7 +1381,6 @@ impl<'a> Codegen<'a> {
|
||||||
op: T,
|
op: T,
|
||||||
signed: bool,
|
signed: bool,
|
||||||
size: u64,
|
size: u64,
|
||||||
first_imm: bool,
|
|
||||||
) -> Option<fn(u8, u8, u64) -> (usize, [u8; instrs::MAX_SIZE])> {
|
) -> Option<fn(u8, u8, u64) -> (usize, [u8; instrs::MAX_SIZE])> {
|
||||||
use instrs as i;
|
use instrs as i;
|
||||||
|
|
||||||
|
@ -1402,14 +1401,14 @@ impl<'a> Codegen<'a> {
|
||||||
|
|
||||||
let ops = match op {
|
let ops = match op {
|
||||||
T::Add => basic_op!(addi8, addi16, addi32, addi64),
|
T::Add => basic_op!(addi8, addi16, addi32, addi64),
|
||||||
T::Sub if !first_imm => sub_op!(addi8, addi16, addi32, addi64),
|
T::Sub => sub_op!(addi8, addi16, addi32, addi64),
|
||||||
T::Mul => basic_op!(muli8, muli16, muli32, muli64),
|
T::Mul => basic_op!(muli8, muli16, muli32, muli64),
|
||||||
T::Band => return Some(i::andi),
|
T::Band => return Some(i::andi),
|
||||||
T::Bor => return Some(i::ori),
|
T::Bor => return Some(i::ori),
|
||||||
T::Xor => return Some(i::xori),
|
T::Xor => return Some(i::xori),
|
||||||
T::Shr if signed && !first_imm => basic_op!(srui8, srui16, srui32, srui64),
|
T::Shr if signed => basic_op!(srui8, srui16, srui32, srui64),
|
||||||
T::Shr if !first_imm => basic_op!(srui8, srui16, srui32, srui64),
|
T::Shr => basic_op!(srui8, srui16, srui32, srui64),
|
||||||
T::Shl if !first_imm => basic_op!(slui8, slui16, slui32, slui64),
|
T::Shl => basic_op!(slui8, slui16, slui32, slui64),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1442,7 +1441,7 @@ impl<'a> Codegen<'a> {
|
||||||
let (lhs, owned) = self.loc_to_reg_ref(&left, size);
|
let (lhs, owned) = self.loc_to_reg_ref(&left, size);
|
||||||
|
|
||||||
if let Loc::Imm(imm) = right
|
if let Loc::Imm(imm) = right
|
||||||
&& let Some(op) = Self::imm_math_op(op, signed, size, false)
|
&& let Some(op) = Self::imm_math_op(op, signed, size)
|
||||||
{
|
{
|
||||||
self.code.encode(op(lhs, lhs, imm));
|
self.code.encode(op(lhs, lhs, imm));
|
||||||
return if let Ctx::Dest(dest) = ctx {
|
return if let Ctx::Dest(dest) = ctx {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 209
|
code size: 200
|
||||||
ret: 1
|
ret: 1
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 527
|
code size: 499
|
||||||
ret: 512
|
ret: 512
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 666
|
code size: 657
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 314
|
code size: 308
|
||||||
ret: 44
|
ret: 44
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 287
|
code size: 281
|
||||||
ret: 16
|
ret: 16
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 290
|
code size: 287
|
||||||
ret: 55
|
ret: 55
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 382
|
code size: 379
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 124
|
code size: 121
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
Loading…
Reference in a new issue