From 72863daa7e1c8abf80d40e796145081b721860c5 Mon Sep 17 00:00:00 2001 From: Norbert Hajagos Date: Mon, 7 Oct 2024 23:02:11 +0200 Subject: [PATCH] gen_dev-x86_64 extend Num.neg to all Signed and Unsigned int sizes --- crates/compiler/gen_dev/src/generic64/mod.rs | 2 +- crates/compiler/test_gen/src/gen_num.rs | 23 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/compiler/gen_dev/src/generic64/mod.rs b/crates/compiler/gen_dev/src/generic64/mod.rs index 62869ab1df9..8d6482a5d31 100644 --- a/crates/compiler/gen_dev/src/generic64/mod.rs +++ b/crates/compiler/gen_dev/src/generic64/mod.rs @@ -1786,7 +1786,7 @@ impl< fn build_num_neg(&mut self, dst: &Symbol, src: &Symbol, layout: &InLayout<'a>) { match self.layout_interner.get_repr(*layout) { - LayoutRepr::Builtin(Builtin::Int(IntWidth::I64 | IntWidth::U64)) => { + LayoutRepr::Builtin(Builtin::Int(quadword_and_smaller!())) => { let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst); let src_reg = self.storage_manager.load_to_general_reg(&mut self.buf, src); ASM::neg_reg64_reg64(&mut self.buf, dst_reg, src_reg); diff --git a/crates/compiler/test_gen/src/gen_num.rs b/crates/compiler/test_gen/src/gen_num.rs index a7b155d10f5..388e4024130 100644 --- a/crates/compiler/test_gen/src/gen_num.rs +++ b/crates/compiler/test_gen/src/gen_num.rs @@ -1605,20 +1605,21 @@ fn tail_call_elimination() { ); } -#[test] -#[cfg(feature = "gen-dev")] -fn int_negate_dev() { - // TODO - // dev backend yet to have `Num.maxI64` or `Num.minI64`. - // add the "gen-dev" feature to the test below after implementing them both. - assert_evals_to!("Num.neg 123", -123, i64); - assert_evals_to!("Num.neg -123", 123, i64); - assert_evals_to!("Num.neg 0", 0, i64); -} - #[test] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))] fn int_negate() { + assert_evals_to!("Num.neg 123i8", -123, i8); + assert_evals_to!("Num.neg Num.maxI8", -i8::MAX, i8); + assert_evals_to!("Num.neg (Num.minI8 + 1)", i8::MAX, i8); + + assert_evals_to!("Num.neg 123i16", -123, i16); + assert_evals_to!("Num.neg Num.maxI16", -i16::MAX, i16); + assert_evals_to!("Num.neg (Num.minI16 + 1)", i16::MAX, i16); + + assert_evals_to!("Num.neg 123i32", -123, i32); + assert_evals_to!("Num.neg Num.maxI32", -i32::MAX, i32); + assert_evals_to!("Num.neg (Num.minI32 + 1)", i32::MAX, i32); + assert_evals_to!("Num.neg 123", -123, i64); assert_evals_to!("Num.neg Num.maxI64", -i64::MAX, i64); assert_evals_to!("Num.neg (Num.minI64 + 1)", i64::MAX, i64);