From 7cac9382ad273080a67feb8540298045ee6f0606 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Mon, 11 Nov 2024 23:17:13 +0100 Subject: [PATCH] we assumed unary operands are at leas 4bytes bit --- lang/src/son/hbvm.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lang/src/son/hbvm.rs b/lang/src/son/hbvm.rs index 470da46..937e74f 100644 --- a/lang/src/son/hbvm.rs +++ b/lang/src/son/hbvm.rs @@ -564,27 +564,27 @@ impl TokenKind { } fn unop(&self, dst: ty::Id, src: ty::Id) -> Option EncodedInstr> { - let src_idx = src.simple_size().unwrap().ilog2() as usize - 2; + let src_idx = src.simple_size().unwrap().ilog2() as usize; Some(match self { Self::Sub => [ - |a, b| sub8(a, 0, b), - |a, b| sub16(a, 0, b), - |a, b| sub32(a, 0, b), - |a, b| sub64(a, 0, b), - ][src.simple_size().unwrap().ilog2() as usize], + |a, b| sub8(a, reg::ZERO, b), + |a, b| sub16(a, reg::ZERO, b), + |a, b| sub32(a, reg::ZERO, b), + |a, b| sub64(a, reg::ZERO, b), + ][src_idx], Self::Not => instrs::not, Self::Float if dst.is_float() && src.is_integer() => { debug_assert_matches!( (dst.simple_size(), src.simple_size()), (Some(4 | 8), Some(8)) ); - [instrs::itf32, instrs::itf64][src_idx] + [instrs::itf32, instrs::itf64][src_idx - 2] } Self::Number if src.is_float() && dst.is_integer() => { - [|a, b| instrs::fti32(a, b, 1), |a, b| instrs::fti64(a, b, 1)][src_idx] + [|a, b| instrs::fti32(a, b, 1), |a, b| instrs::fti64(a, b, 1)][src_idx - 2] } Self::Float if dst.is_float() && src.is_float() => { - [instrs::fc32t64, |a, b| instrs::fc64t32(a, b, 1)][src_idx] + [instrs::fc32t64, |a, b| instrs::fc64t32(a, b, 1)][src_idx - 2] } _ => return None, })