Skip to content

Commit

Permalink
Merge pull request #7146 from HajagosNorbert/hajagosnorbert/neg_int
Browse files Browse the repository at this point in the history
gen_dev-x86_64 extend Num.neg to all Signed and Unsigned int sizes
  • Loading branch information
bhansconnect authored Oct 11, 2024
2 parents b5e3c3e + 72863da commit 5646f82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/compiler/gen_dev/src/generic64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 12 additions & 11 deletions crates/compiler/test_gen/src/gen_num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5646f82

Please sign in to comment.