From 0c2db878f0b0095d8a1c65ab0ad5c9326344694c Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Thu, 24 Oct 2024 10:21:10 +0200 Subject: [PATCH] adding the stack optimizations --- lang/src/codegen.rs | 2 +- lang/src/son.rs | 37 +-- lang/tests/son_tests_arrays.txt | 48 ++-- lang/tests/son_tests_conditional_stores.txt | 15 +- lang/tests/son_tests_different_types.txt | 77 +++--- lang/tests/son_tests_idk.txt | 30 +-- lang/tests/son_tests_inline_test.txt | 50 ++-- lang/tests/son_tests_loop_stores.txt | 11 +- lang/tests/son_tests_struct_operators.txt | 247 ++++++++---------- lang/tests/son_tests_struct_patterns.txt | 32 ++- lang/tests/son_tests_structs.txt | 32 ++- .../tests/son_tests_tests_ptr_to_ptr_copy.txt | 48 ++-- lang/tests/son_tests_wide_ret.txt | 48 ++-- 13 files changed, 307 insertions(+), 370 deletions(-) diff --git a/lang/src/codegen.rs b/lang/src/codegen.rs index 450eb08..d679c23 100644 --- a/lang/src/codegen.rs +++ b/lang/src/codegen.rs @@ -277,7 +277,7 @@ impl Value { } fn imm(value: u64) -> Self { - Self { ty: ty::Id::INT, loc: Loc::ct(value) } + Self { ty: ty::Id::UINT, loc: Loc::ct(value) } } fn ty(ty: ty::Id) -> Self { diff --git a/lang/src/son.rs b/lang/src/son.rs index 06dba95..748f490 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -881,10 +881,6 @@ impl Nodes { #[allow(dead_code)] fn eliminate_stack_temporaries(&mut self) { - if !cfg!(debug_assertions) { - return; - } - 'o: for stack in self[MEM].outputs.clone() { if self[stack].kind != Kind::Stck { continue; @@ -895,6 +891,7 @@ impl Nodes { match self[o].kind { Kind::Load if self[o].ty == self[stack].ty + && self[o].outputs.iter().all(|&n| self[n].kind == Kind::Stre) && let mut full_stores = self[o].outputs.iter().filter(|&&n| { self[n].kind == Kind::Stre && self[n].inputs[1] == o }) @@ -928,7 +925,6 @@ impl Nodes { continue; } let Some(index) = unidentifed.iter().position(|&n| n == contact_point) else { - std::println!("{stack} {region} {unidentifed:?} duped {:?}", self[region]); continue 'o; }; unidentifed.remove(index); @@ -941,15 +937,9 @@ impl Nodes { } if !unidentifed.is_empty() { - for &n in unidentifed.iter() { - std::println!("{:?}", self[n]); - } - std::println!("failed {stack}"); continue; } - std::println!("{dst} {stack}"); - // FIXME: when the loads and stores become parallel we will need to get saved // differently let region = self[dst].inputs[2]; @@ -1288,7 +1278,7 @@ impl ItemCtx { self.scope.clear(&mut self.nodes); self.nodes.unlock(NEVER); self.nodes.unlock(MEM); - //self.nodes.eliminate_stack_temporaries(); + self.nodes.eliminate_stack_temporaries(); } fn emit(&mut self, instr: (usize, [u8; instrs::MAX_SIZE])) { @@ -3958,16 +3948,17 @@ impl<'a> Function<'a> { let ops = vec![self.drg(nid)]; self.add_instr(nid, ops); } - //Kind::Stck - // if node.outputs.iter().all(|&n| { - // matches!(self.nodes[n].kind, Kind::Stre | Kind::Load) - // || matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add } - // if self.nodes.is_const(self.nodes[n].inputs[2]) - // && self.nodes[n] - // .outputs - // .iter() - // .all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load))) - // }) => {} + Kind::Stck + if node.ty.loc(self.tys) == Loc::Reg && node.outputs.iter().all(|&n| { + + matches!(self.nodes[n].kind, Kind::Stre | Kind::Load) + || matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add } + if self.nodes.is_const(self.nodes[n].inputs[2]) + && self.nodes[n] + .outputs + .iter() + .all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load))) + }) => {} Kind::Stck if self.tys.size_of(node.ty) == 0 => self.nodes.lock(nid), Kind::Stck => { let ops = vec![self.drg(nid)]; @@ -4372,7 +4363,7 @@ mod tests { fn generate(ident: &'static str, input: &'static str, output: &mut String) { _ = log::set_logger(&crate::fs::Logger); - //log::set_max_level(log::LevelFilter::Info); + log::set_max_level(log::LevelFilter::Info); // log::set_max_level(log::LevelFilter::Trace); let (ref files, embeds) = crate::test_parse_files(ident, input); diff --git a/lang/tests/son_tests_arrays.txt b/lang/tests/son_tests_arrays.txt index e02ff85..916b2ce 100644 --- a/lang/tests/son_tests_arrays.txt +++ b/lang/tests/son_tests_arrays.txt @@ -1,31 +1,27 @@ main: - ADDI64 r254, r254, -64d - ST r31, r254, 56a, 8h - LI64 r9, 4d - LI64 r7, 1d - LI64 r6, 2d - LI64 r10, 3d + ADDI64 r254, r254, -36d + ST r31, r254, 28a, 8h + LI64 r7, 4d + LI64 r6, 1d + LI64 r5, 2d + LI64 r9, 3d LI64 r8, 1d - LI64 r11, 0d - ADDI64 r2, r254, 0d - ADDI64 r3, r254, 24d - ADDI64 r4, r254, 48d - ADDI64 r12, r254, 52d - ST r11, r254, 52a, 1h - ST r11, r254, 53a, 1h - ST r10, r254, 54a, 1h - ST r7, r254, 55a, 1h - BMC r12, r4, 4h - ST r8, r254, 24a, 8h - ST r6, r254, 32a, 8h - ST r9, r254, 40a, 8h - BMC r3, r2, 24h + LI64 r10, 0d + ADDI64 r12, r254, 0d + ST r10, r254, 0a, 1h + ST r10, r254, 1a, 1h + ST r9, r254, 2a, 1h + ST r6, r254, 3a, 1h + ADDI64 r2, r254, 4d + ST r8, r254, 4a, 8h + ST r5, r254, 12a, 8h + ST r7, r254, 20a, 8h JAL r31, r0, :pass - LD r8, r254, 51a, 1h - ANDI r10, r8, 255d - ADD64 r1, r1, r10 - LD r31, r254, 56a, 8h - ADDI64 r254, r254, 64d + LD r2, r254, 3a, 1h + ANDI r4, r2, 255d + ADD64 r1, r1, r4 + LD r31, r254, 28a, 8h + ADDI64 r254, r254, 36d JALA r0, r31, 0a pass: LD r3, r2, 8a, 8h @@ -36,6 +32,6 @@ pass: ADD64 r11, r3, r9 ADD64 r1, r8, r11 JALA r0, r31, 0a -code size: 380 +code size: 348 ret: 8 status: Ok(()) diff --git a/lang/tests/son_tests_conditional_stores.txt b/lang/tests/son_tests_conditional_stores.txt index ab3d8d2..6f44a63 100644 --- a/lang/tests/son_tests_conditional_stores.txt +++ b/lang/tests/son_tests_conditional_stores.txt @@ -5,18 +5,17 @@ main: ADDI64 r254, r254, -16d ST r31, r254, 8a, 8h JAL r31, r0, :cond - LI64 r6, 0d - CP r8, r6 - JNE r1, r8, :0 - CP r6, r8 - CP r1, r6 + LI64 r5, 0d + CP r7, r5 + JNE r1, r7, :0 + CP r5, r7 + CP r1, r5 JMP :1 0: LI64 r1, 2d - 1: ADDI64 r8, r254, 0d - ST r1, r254, 0a, 8h + 1: ST r1, r254, 0a, 8h LD r31, r254, 8a, 8h ADDI64 r254, r254, 16d JALA r0, r31, 0a -code size: 158 +code size: 147 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_different_types.txt b/lang/tests/son_tests_different_types.txt index 2bc4221..4be6576 100644 --- a/lang/tests/son_tests_different_types.txt +++ b/lang/tests/son_tests_different_types.txt @@ -1,53 +1,46 @@ main: - ADDI64 r254, r254, -36d - LI64 r8, 2d - LI64 r7, 0d + ADDI64 r254, r254, -12d + LI64 r5, 2d + LI64 r4, 0d LI64 r6, 0d - LI64 r9, 255d - ADDI64 r1, r254, 0d - ADDI64 r10, r254, 12d - ADDI64 r11, r254, 20d - ST r9, r254, 20a, 1h - ST r6, r254, 21a, 1h - ST r6, r254, 22a, 1h - ST r9, r254, 23a, 1h - ADDI64 r12, r254, 24d - ADDI64 r9, r12, 4d - BMC r11, r12, 4h - ST r7, r254, 12a, 4h - ST r8, r254, 16a, 4h - BMC r10, r9, 8h - BMC r12, r1, 12h - LD r4, r254, 8a, 4h - ANDI r4, r4, 4294967295d - ANDI r8, r8, 4294967295d - JEQ r4, r8, :0 + LI64 r7, 255d + ADDI64 r9, r254, 0d + ST r7, r254, 0a, 1h + ST r6, r254, 1a, 1h + ST r6, r254, 2a, 1h + ST r7, r254, 3a, 1h + ST r4, r254, 4a, 4h + ST r5, r254, 8a, 4h + LD r6, r254, 8a, 4h + ANDI r6, r6, 4294967295d + ANDI r5, r5, 4294967295d + JEQ r6, r5, :0 LI64 r1, 0d JMP :1 - 0: LD r10, r254, 4a, 4h - ANDI r10, r10, 4294967295d - ANDI r7, r7, 4294967295d - JEQ r10, r7, :2 + 0: LD r11, r254, 4a, 4h + ANDI r11, r11, 4294967295d + ANDI r4, r4, 4294967295d + JEQ r11, r4, :2 LI64 r1, 64d JMP :1 - 2: LD r4, r254, 3a, 1h + 2: LD r5, r254, 3a, 1h + ANDI r7, r5, 255d + LD r4, r254, 2a, 1h ANDI r6, r4, 255d - LD r3, r254, 2a, 1h + LD r3, r254, 1a, 1h ANDI r5, r3, 255d - LD r2, r254, 1a, 1h - ANDI r4, r2, 255d - LD r12, r254, 0a, 1h - ANDI r3, r12, 255d - LD r1, r254, 8a, 4h - LD r2, r254, 4a, 4h - ADD32 r7, r1, r2 - ADD32 r8, r7, r3 - ADD32 r12, r8, r4 - ADD32 r4, r12, r5 - ADD32 r8, r4, r6 - ANDI r1, r8, 4294967295d - 1: ADDI64 r254, r254, 36d + LD r1, r254, 0a, 1h + ANDI r4, r1, 255d + LD r2, r254, 8a, 4h + LD r3, r254, 4a, 4h + ADD32 r8, r2, r3 + ADD32 r9, r8, r4 + ADD32 r1, r9, r5 + ADD32 r5, r1, r6 + ADD32 r9, r5, r7 + ANDI r1, r9, 4294967295d + 1: ADDI64 r254, r254, 12d JALA r0, r31, 0a -code size: 492 +code size: 433 ret: 512 status: Ok(()) diff --git a/lang/tests/son_tests_idk.txt b/lang/tests/son_tests_idk.txt index 93b3577..61dc94f 100644 --- a/lang/tests/son_tests_idk.txt +++ b/lang/tests/son_tests_idk.txt @@ -1,22 +1,20 @@ main: - ADDI64 r254, r254, -256d - LI64 r7, 69d - LI64 r6, 128d - LI64 r8, 0d - ADDI64 r5, r254, 0d - ADDI64 r9, r254, 128d - BMC r9, r5, 128h - 2: JLTS r8, r6, :0 - LD r5, r254, 42a, 1h - ANDI r1, r5, 255d + ADDI64 r254, r254, -128d + LI64 r6, 69d + LI64 r5, 128d + LI64 r7, 0d + ADDI64 r4, r254, 0d + 2: JLTS r7, r5, :0 + LD r2, r254, 42a, 1h + ANDI r1, r2, 255d JMP :1 - 0: ADDI64 r9, r8, 1d - ADD64 r8, r8, r5 - ST r7, r8, 0a, 1h - CP r8, r9 + 0: ADDI64 r8, r7, 1d + ADD64 r3, r7, r4 + ST r6, r3, 0a, 1h + CP r7, r8 JMP :2 - 1: ADDI64 r254, r254, 256d + 1: ADDI64 r254, r254, 128d JALA r0, r31, 0a -code size: 168 +code size: 152 ret: 69 status: Ok(()) diff --git a/lang/tests/son_tests_inline_test.txt b/lang/tests/son_tests_inline_test.txt index b82b377..aacd370 100644 --- a/lang/tests/son_tests_inline_test.txt +++ b/lang/tests/son_tests_inline_test.txt @@ -22,34 +22,30 @@ scalar_values: LI64 r1, 0d JALA r0, r31, 0a structs: - ADDI64 r254, r254, -64d - LI64 r9, 5d - LI64 r7, 20d + ADDI64 r254, r254, -48d + LI64 r7, 5d + LI64 r6, 20d LI64 r4, 0d - ADDI64 r12, r254, 0d - ADDI64 r1, r254, 8d - ADDI64 r10, r254, 24d - ADDI64 r10, r254, 32d - ADDI64 r11, r254, 40d - ADDI64 r2, r254, 56d - ST r4, r254, 56a, 8h - ST r7, r254, 24a, 8h - ST r9, r254, 0a, 8h - BMC r12, r1, 8h - ST r9, r254, 16a, 8h - LD r1, r254, 8a, 8h - LD r2, r254, 24a, 8h - ADD64 r5, r1, r2 - SUB64 r5, r5, r9 - ST r5, r254, 32a, 8h - BMC r10, r11, 8h - ST r7, r254, 48a, 8h - LD r12, r254, 40a, 8h - LD r1, r254, 56a, 8h - ADD64 r4, r12, r1 - SUB64 r1, r4, r7 - ADDI64 r254, r254, 64d + ADDI64 r8, r254, 0d + ADDI64 r10, r254, 8d + ADDI64 r8, r254, 24d + ADDI64 r8, r254, 40d + ST r4, r254, 40a, 8h + ST r6, r254, 0a, 8h + ST r7, r254, 8a, 8h + ST r7, r254, 16a, 8h + LD r8, r254, 8a, 8h + LD r9, r254, 0a, 8h + ADD64 r12, r8, r9 + SUB64 r12, r12, r7 + ST r12, r254, 24a, 8h + ST r6, r254, 32a, 8h + LD r7, r254, 24a, 8h + LD r8, r254, 40a, 8h + ADD64 r10, r7, r8 + SUB64 r1, r10, r6 + ADDI64 r254, r254, 48d JALA r0, r31, 0a -code size: 449 +code size: 417 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_loop_stores.txt b/lang/tests/son_tests_loop_stores.txt index 18e8ece..19e9d45 100644 --- a/lang/tests/son_tests_loop_stores.txt +++ b/lang/tests/son_tests_loop_stores.txt @@ -1,17 +1,16 @@ main: ADDI64 r254, r254, -8d - LI64 r4, 0d + LI64 r3, 0d LI64 r2, 10d - ADDI64 r5, r254, 0d ST r2, r254, 0a, 8h 2: LD r1, r254, 0a, 8h - JNE r1, r4, :0 + JNE r1, r3, :0 JMP :1 - 0: ADDI64 r1, r1, -1d - ST r1, r254, 0a, 8h + 0: ADDI64 r11, r1, -1d + ST r11, r254, 0a, 8h JMP :2 1: ADDI64 r254, r254, 8d JALA r0, r31, 0a -code size: 137 +code size: 126 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_struct_operators.txt b/lang/tests/son_tests_struct_operators.txt index 99e33de..b311e0b 100644 --- a/lang/tests/son_tests_struct_operators.txt +++ b/lang/tests/son_tests_struct_operators.txt @@ -1,145 +1,118 @@ main: - ADDI64 r254, r254, -440d - ST r32, r254, 352a, 88h - LI64 r4, 4d + ADDI64 r254, r254, -136d + LI64 r2, 4d LI64 r9, 1d - LI64 r7, 3d - LI64 r11, 2d - LI64 r12, 1d - LI64 r8, 0d - ADDI64 r3, r254, 336d - ADDI64 r2, r254, 340d - ADDI64 r2, r254, 344d - ADDI64 r10, r254, 348d - ST r8, r254, 348a, 1h - ST r8, r254, 349a, 1h - ST r8, r254, 350a, 1h - ST r8, r254, 351a, 1h - BMC r10, r2, 4h - ST r9, r254, 340a, 1h - ST r9, r254, 341a, 1h - ST r9, r254, 342a, 1h - ST r9, r254, 343a, 1h - LD r6, r254, 340a, 1h - LD r8, r254, 344a, 1h - ADD8 r9, r6, r8 - ST r9, r254, 336a, 1h - LD r1, r254, 341a, 1h - LD r5, r254, 345a, 1h - ADD8 r5, r5, r1 - ST r5, r254, 337a, 1h - LD r8, r254, 342a, 1h - LD r9, r254, 346a, 1h - ADD8 r1, r9, r8 - ST r1, r254, 338a, 1h - LD r5, r254, 343a, 1h - LD r6, r254, 347a, 1h - ADD8 r6, r6, r5 - ST r6, r254, 339a, 1h - BMC r3, r2, 4h - LD r2, r254, 347a, 1h - LD r3, r254, 344a, 1h - LD r1, r254, 345a, 1h - LD r5, r254, 346a, 1h - ADD8 r5, r5, r1 - ADD8 r8, r3, r5 - ADD8 r1, r2, r8 - ANDI r1, r1, 255d - ANDI r4, r4, 255d - JEQ r1, r4, :0 + LI64 r6, 3d + LI64 r7, 2d + LI64 r8, 1d + LI64 r10, 0d + ADDI64 r12, r254, 112d + ADDI64 r12, r254, 116d + ST r10, r254, 116a, 1h + ST r10, r254, 117a, 1h + ST r10, r254, 118a, 1h + ST r10, r254, 119a, 1h + ST r9, r254, 112a, 1h + ST r9, r254, 113a, 1h + ST r9, r254, 114a, 1h + ST r9, r254, 115a, 1h + LD r1, r254, 112a, 1h + LD r3, r254, 116a, 1h + ADD8 r4, r1, r3 + ST r4, r254, 116a, 1h + LD r9, r254, 113a, 1h + LD r10, r254, 117a, 1h + ADD8 r11, r10, r9 + ST r11, r254, 117a, 1h + LD r3, r254, 114a, 1h + LD r4, r254, 118a, 1h + ADD8 r9, r4, r3 + ST r9, r254, 118a, 1h + LD r10, r254, 115a, 1h + LD r11, r254, 119a, 1h + ADD8 r1, r11, r10 + ST r1, r254, 119a, 1h + LD r9, r254, 119a, 1h + LD r5, r254, 118a, 1h + LD r10, r254, 116a, 1h + LD r11, r254, 117a, 1h + ADD8 r11, r5, r11 + ADD8 r3, r10, r11 + ADD8 r5, r9, r3 + ANDI r5, r5, 255d + ANDI r2, r2, 255d + JEQ r5, r2, :0 LI64 r1, 1008d JMP :1 - 0: LI64 r5, 0d - LI64 r32, 4d - ADDI64 r2, r254, 0d - ADDI64 r8, r254, 16d - ADDI64 r9, r254, 32d - ADDI64 r10, r254, 64d - ADDI64 r3, r254, 96d - ADDI64 r1, r254, 112d - ADDI64 r4, r1, 16d - ADDI64 r33, r254, 144d - ADDI64 r34, r254, 160d - ADDI64 r35, r254, 176d - ADDI64 r36, r254, 208d - ADDI64 r37, r254, 224d - ADDI64 r38, r254, 240d - ADDI64 r39, r38, 16d - ADDI64 r40, r254, 272d - ADDI64 r41, r254, 288d - ADDI64 r6, r254, 304d - ADDI64 r42, r254, 320d - ST r12, r254, 320a, 8h - ST r11, r254, 328a, 8h - BMC r42, r6, 16h - ST r7, r254, 288a, 8h - ST r32, r254, 296a, 8h - BMC r41, r40, 16h - LD r7, r254, 272a, 8h - LD r11, r254, 304a, 8h - ADD64 r7, r7, r11 - ST r7, r254, 224a, 8h - LD r11, r254, 280a, 8h - LD r12, r254, 312a, 8h - ADD64 r7, r11, r12 - ST r7, r254, 232a, 8h - BMC r37, r38, 16h - LD r7, r254, 304a, 8h - LD r11, r254, 272a, 8h - SUB64 r11, r11, r7 - ST r11, r254, 208a, 8h - LD r7, r254, 312a, 8h - LD r11, r254, 280a, 8h - SUB64 r7, r11, r7 - ST r7, r254, 216a, 8h - BMC r36, r39, 16h - BMC r38, r35, 32h - ST r5, r254, 160a, 8h - ST r5, r254, 168a, 8h - BMC r34, r33, 16h - LD r11, r254, 272a, 8h - LD r12, r254, 144a, 8h - SUB64 r12, r12, r11 - ST r12, r254, 96a, 8h - LD r5, r254, 280a, 8h - LD r7, r254, 152a, 8h - SUB64 r7, r7, r5 - ST r7, r254, 104a, 8h - BMC r3, r1, 16h - BMC r6, r4, 16h - BMC r1, r10, 32h - LD r5, r254, 176a, 8h - LD r6, r254, 64a, 8h - ADD64 r11, r6, r5 - ST r11, r254, 32a, 8h - LD r12, r254, 184a, 8h - LD r1, r254, 72a, 8h - ADD64 r3, r12, r1 - ST r3, r254, 40a, 8h - LD r7, r254, 192a, 8h - LD r11, r254, 80a, 8h - ADD64 r11, r7, r11 - ST r11, r254, 48a, 8h - LD r3, r254, 200a, 8h - LD r4, r254, 88a, 8h - ADD64 r5, r3, r4 - ST r5, r254, 56a, 8h - BMC r9, r10, 32h - LD r11, r254, 80a, 8h - LD r12, r254, 64a, 8h - ADD64 r3, r11, r12 + 0: LI64 r3, 0d + LI64 r1, 4d + ADDI64 r4, r254, 0d + ADDI64 r2, r254, 16d + ADDI64 r10, r2, 16d + ADDI64 r4, r254, 48d + ADDI64 r9, r254, 64d + ADDI64 r11, r254, 96d + ST r8, r254, 48a, 8h + ST r7, r254, 56a, 8h + ST r6, r254, 0a, 8h + ST r1, r254, 8a, 8h + LD r2, r254, 48a, 8h + LD r5, r254, 0a, 8h + ADD64 r6, r5, r2 + ST r6, r254, 64a, 8h + LD r11, r254, 8a, 8h + LD r12, r254, 56a, 8h + ADD64 r1, r11, r12 + ST r1, r254, 72a, 8h + LD r5, r254, 0a, 8h + LD r6, r254, 48a, 8h + SUB64 r8, r5, r6 + ST r8, r254, 80a, 8h + LD r12, r254, 56a, 8h + LD r1, r254, 8a, 8h + SUB64 r5, r1, r12 + ST r5, r254, 88a, 8h + ST r3, r254, 96a, 8h + ST r3, r254, 104a, 8h + LD r11, r254, 96a, 8h + LD r1, r254, 0a, 8h + SUB64 r3, r11, r1 ST r3, r254, 16a, 8h - LD r6, r254, 88a, 8h - LD r7, r254, 72a, 8h - ADD64 r9, r6, r7 - ST r9, r254, 24a, 8h - BMC r8, r2, 16h - LD r3, r254, 8a, 8h - LD r4, r254, 0a, 8h - ADD64 r1, r3, r4 - 1: LD r32, r254, 352a, 88h - ADDI64 r254, r254, 440d + LD r7, r254, 8a, 8h + LD r8, r254, 104a, 8h + SUB64 r11, r8, r7 + ST r11, r254, 24a, 8h + BMC r4, r10, 16h + LD r3, r254, 16a, 8h + LD r5, r254, 64a, 8h + ADD64 r7, r3, r5 + ST r7, r254, 16a, 8h + LD r11, r254, 72a, 8h + LD r12, r254, 24a, 8h + ADD64 r2, r11, r12 + ST r2, r254, 24a, 8h + LD r7, r254, 80a, 8h + LD r8, r254, 32a, 8h + ADD64 r10, r7, r8 + ST r10, r254, 32a, 8h + LD r2, r254, 88a, 8h + LD r3, r254, 40a, 8h + ADD64 r5, r2, r3 + ST r5, r254, 40a, 8h + LD r8, r254, 16a, 8h + LD r10, r254, 32a, 8h + ADD64 r12, r10, r8 + ADDI64 r5, r254, 120d + ST r12, r254, 120a, 8h + LD r5, r254, 40a, 8h + LD r6, r254, 24a, 8h + ADD64 r8, r5, r6 + ST r8, r254, 128a, 8h + LD r12, r254, 120a, 8h + LD r2, r254, 128a, 8h + ADD64 r1, r2, r12 + 1: ADDI64 r254, r254, 136d JALA r0, r31, 0a -code size: 1460 +code size: 1231 ret: 10 status: Ok(()) diff --git a/lang/tests/son_tests_struct_patterns.txt b/lang/tests/son_tests_struct_patterns.txt index a47f4f4..b8a905e 100644 --- a/lang/tests/son_tests_struct_patterns.txt +++ b/lang/tests/son_tests_struct_patterns.txt @@ -32,26 +32,24 @@ fib_iter: JMP :2 1: JALA r0, r31, 0a main: - ADDI64 r254, r254, -20d - ST r31, r254, 4a, 16h - LI64 r2, 10d - ADDI64 r4, r254, 0d - ADDI64 r3, r254, 2d - ST r2, r254, 2a, 1h - ST r2, r254, 3a, 1h - BMC r3, r4, 2h - LD r10, r254, 0a, 1h - ANDI r2, r10, 255d + ADDI64 r254, r254, -18d + ST r31, r254, 2a, 16h + LI64 r1, 10d + ADDI64 r3, r254, 0d + ST r1, r254, 0a, 1h + ST r1, r254, 1a, 1h + LD r7, r254, 0a, 1h + ANDI r2, r7, 255d JAL r31, r0, :fib CP r32, r1 - LD r4, r254, 1a, 1h - ANDI r2, r4, 255d + LD r1, r254, 1a, 1h + ANDI r2, r1, 255d JAL r31, r0, :fib_iter - CP r11, r32 - SUB64 r1, r11, r1 - LD r31, r254, 4a, 16h - ADDI64 r254, r254, 20d + CP r8, r32 + SUB64 r1, r8, r1 + LD r31, r254, 2a, 16h + ADDI64 r254, r254, 18d JALA r0, r31, 0a -code size: 398 +code size: 382 ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_structs.txt b/lang/tests/son_tests_structs.txt index 395d3d8..2d4bf7f 100644 --- a/lang/tests/son_tests_structs.txt +++ b/lang/tests/son_tests_structs.txt @@ -1,28 +1,26 @@ main: - ADDI64 r254, r254, -96d - ST r31, r254, 72a, 24h + ADDI64 r254, r254, -88d + ST r31, r254, 64a, 24h LI64 r32, 3d LI64 r3, 4d - ADDI64 r33, r254, 16d - ADDI64 r8, r254, 32d - ADDI64 r9, r254, 48d + ADDI64 r33, r254, 0d + ADDI64 r7, r254, 16d + ADDI64 r5, r254, 48d ST r3, r254, 48a, 8h - ADDI64 r7, r254, 56d - BMC r9, r7, 8h - ST r32, r254, 64a, 8h - BMC r7, r8, 16h - LD r3, r7, 0a, 16h + ST r32, r254, 56a, 8h + BMC r5, r7, 16h + LD r3, r5, 0a, 16h JAL r31, r0, :odher_pass - ST r1, r254, 16a, 16h - ADDI64 r2, r254, 0d + ST r1, r254, 0a, 16h + ADDI64 r2, r254, 32d BMC r33, r2, 16h - LD r10, r254, 8a, 8h - JNE r10, r32, :0 + LD r7, r254, 40a, 8h + JNE r7, r32, :0 JAL r31, r0, :pass JMP :1 0: LI64 r1, 0d - 1: LD r31, r254, 72a, 24h - ADDI64 r254, r254, 96d + 1: LD r31, r254, 64a, 24h + ADDI64 r254, r254, 88d JALA r0, r31, 0a odher_pass: ADDI64 r254, r254, -16d @@ -34,6 +32,6 @@ odher_pass: pass: LD r1, r2, 0a, 8h JALA r0, r31, 0a -code size: 350 +code size: 334 ret: 4 status: Ok(()) diff --git a/lang/tests/son_tests_tests_ptr_to_ptr_copy.txt b/lang/tests/son_tests_tests_ptr_to_ptr_copy.txt index 3659f37..67fd43a 100644 --- a/lang/tests/son_tests_tests_ptr_to_ptr_copy.txt +++ b/lang/tests/son_tests_tests_ptr_to_ptr_copy.txt @@ -1,32 +1,30 @@ main: - ADDI64 r254, r254, -20480d - LI64 r8, 64d - LI64 r6, 1024d - LI64 r10, 1d - LI64 r9, 0d - ADDI64 r7, r254, 0d - ADDI64 r11, r254, 10240d - BMC r11, r7, 10240h - 4: JLTS r9, r6, :0 - LI64 r8, 10d - CP r11, r10 - 3: JLTS r11, r8, :1 - LD r12, r254, 2048a, 1h - ANDI r1, r12, 255d + ADDI64 r254, r254, -10240d + LI64 r7, 64d + LI64 r5, 1024d + LI64 r9, 1d + LI64 r8, 0d + ADDI64 r6, r254, 0d + 4: JLTS r8, r5, :0 + LI64 r7, 10d + CP r8, r9 + 3: JLTS r8, r7, :1 + LD r9, r254, 2048a, 1h + ANDI r1, r9, 255d JMP :2 - 1: ADD64 r9, r11, r10 - MUL64 r5, r11, r6 - ADD64 r11, r5, r7 - BMC r7, r11, 1024h - CP r11, r9 + 1: ADD64 r3, r8, r9 + MUL64 r2, r8, r5 + ADD64 r4, r2, r6 + BMC r6, r4, 1024h + CP r8, r3 JMP :3 - 0: ADD64 r5, r9, r10 - ADD64 r3, r9, r7 - ST r8, r3, 0a, 1h - CP r9, r5 + 0: ADD64 r2, r8, r9 + ADD64 r12, r8, r6 + ST r7, r12, 0a, 1h + CP r8, r2 JMP :4 - 2: ADDI64 r254, r254, 20480d + 2: ADDI64 r254, r254, 10240d JALA r0, r31, 0a -code size: 214 +code size: 198 ret: 64 status: Ok(()) diff --git a/lang/tests/son_tests_wide_ret.txt b/lang/tests/son_tests_wide_ret.txt index bfc1296..363b029 100644 --- a/lang/tests/son_tests_wide_ret.txt +++ b/lang/tests/son_tests_wide_ret.txt @@ -16,33 +16,31 @@ main: ADDI64 r254, r254, 48d JALA r0, r31, 0a maina: - ADDI64 r254, r254, -56d - ST r31, r254, 40a, 16h - ADDI64 r32, r254, 36d + ADDI64 r254, r254, -48d + ST r31, r254, 32a, 16h + ADDI64 r32, r254, 28d JAL r31, r0, :small_struct LI64 r2, 1d - LI64 r3, 3d + LI64 r4, 3d LI64 r1, 0d - ADDI64 r6, r254, 0d - ADDI64 r8, r6, 8d - ADDI64 r7, r254, 16d - ADDI64 r4, r254, 24d - ADDI64 r5, r254, 32d - BMC r32, r5, 4h - ST r1, r254, 24a, 1h - ST r1, r254, 25a, 1h - ST r1, r254, 26a, 1h - ST r3, r254, 27a, 1h - ST r2, r254, 28a, 1h - ST r1, r254, 29a, 1h - ST r1, r254, 30a, 1h - ST r1, r254, 31a, 1h - BMC r4, r7, 8h - BMC r4, r6, 8h - BMC r7, r8, 8h - LD r1, r6, 0a, 16h - LD r31, r254, 40a, 16h - ADDI64 r254, r254, 56d + ADDI64 r5, r254, 0d + ADDI64 r7, r5, 8d + ADDI64 r3, r254, 16d + ADDI64 r6, r254, 24d + BMC r32, r6, 4h + ST r1, r254, 16a, 1h + ST r1, r254, 17a, 1h + ST r1, r254, 18a, 1h + ST r4, r254, 19a, 1h + ST r2, r254, 20a, 1h + ST r1, r254, 21a, 1h + ST r1, r254, 22a, 1h + ST r1, r254, 23a, 1h + BMC r3, r7, 8h + BMC r3, r5, 8h + LD r1, r5, 0a, 16h + LD r31, r254, 32a, 16h + ADDI64 r254, r254, 48d JALA r0, r31, 0a small_struct: ADDI64 r254, r254, -4d @@ -53,6 +51,6 @@ small_struct: LD r1, r3, 0a, 4h ADDI64 r254, r254, 4d JALA r0, r31, 0a -code size: 560 +code size: 544 ret: 2 status: Ok(())