make integer multiplication work for quadwords and lower

This commit is contained in:
Folkert 2022-08-17 13:05:48 +02:00
parent 07eed2c4a6
commit 038ba47409
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 26 additions and 21 deletions

View file

@ -339,6 +339,19 @@ pub fn new_backend_64bit<
}
}
macro_rules! quadword_and_smaller {
() => {
IntWidth::I64
| IntWidth::U64
| IntWidth::I32
| IntWidth::U32
| IntWidth::I16
| IntWidth::U16
| IntWidth::I8
| IntWidth::U8
};
}
impl<
'a,
GeneralReg: RegTrait,
@ -699,16 +712,7 @@ impl<
fn build_num_add(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, layout: &Layout<'a>) {
match layout {
Layout::Builtin(Builtin::Int(
IntWidth::I64
| IntWidth::U64
| IntWidth::I32
| IntWidth::U32
| IntWidth::I16
| IntWidth::U16
| IntWidth::I8
| IntWidth::U8,
)) => {
Layout::Builtin(Builtin::Int(quadword_and_smaller!())) => {
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
let src1_reg = self
.storage_manager
@ -736,7 +740,7 @@ impl<
fn build_num_mul(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, layout: &Layout<'a>) {
match layout {
Layout::Builtin(Builtin::Int(IntWidth::I64 | IntWidth::U64)) => {
Layout::Builtin(Builtin::Int(quadword_and_smaller!())) => {
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
let src1_reg = self
.storage_manager

View file

@ -1114,18 +1114,19 @@ fn gen_mul_dec() {
i128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn gen_mul_i64() {
assert_evals_to!(
indoc!(
r#"
2 * 4 * 6
"#
),
48,
i64
);
fn gen_mul_quadword_and_lower() {
assert_evals_to!("2i64 * 4 * 6", 48, i64);
assert_evals_to!("2i32 * 4 * 6", 48, i32);
assert_evals_to!("2i16 * 4 * 6", 48, i16);
assert_evals_to!("2i8 * 4 * 6", 48, i8);
assert_evals_to!("2u64 * 4 * 6", 48, u64);
assert_evals_to!("2u32 * 4 * 6", 48, u32);
assert_evals_to!("2u16 * 4 * 6", 48, u16);
assert_evals_to!("2u8 * 4 * 6", 48, u8);
}
#[test]