| ... | ... | @@ -108,7 +108,6 @@ pub fn emitMir( |
| 108 | 108 | |
| 109 | 109 | .eor_shifted_register => try emit.mirLogicalShiftedRegister(inst), |
| 110 | 110 | |
| 111 | | .load_memory => try emit.mirLoadMemory(inst), |
| 112 | 111 | .load_memory_got => try emit.mirLoadMemoryPie(inst), |
| 113 | 112 | .load_memory_direct => try emit.mirLoadMemoryPie(inst), |
| 114 | 113 | |
| ... | ... | @@ -210,16 +209,6 @@ fn instructionSize(emit: *Emit, inst: Mir.Inst.Index) usize { |
| 210 | 209 | .load_memory_got, |
| 211 | 210 | .load_memory_direct, |
| 212 | 211 | => return 2 * 4, |
| 213 | | .load_memory => { |
| 214 | | const load_memory = emit.mir.instructions.items(.data)[inst].load_memory; |
| 215 | | const addr = load_memory.addr; |
| 216 | | |
| 217 | | // movz, [movk, ...], ldr |
| 218 | | if (addr <= math.maxInt(u16)) return 2 * 4; |
| 219 | | if (addr <= math.maxInt(u32)) return 3 * 4; |
| 220 | | if (addr <= math.maxInt(u48)) return 4 * 4; |
| 221 | | return 5 * 4; |
| 222 | | }, |
| 223 | 212 | .pop_regs, .push_regs => { |
| 224 | 213 | const reg_list = emit.mir.instructions.items(.data)[inst].reg_list; |
| 225 | 214 | const number_of_regs = @popCount(u32, reg_list); |
| ... | ... | @@ -655,21 +644,6 @@ fn mirLogicalShiftedRegister(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 655 | 644 | } |
| 656 | 645 | } |
| 657 | 646 | |
| 658 | | fn mirLoadMemory(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 659 | | assert(emit.mir.instructions.items(.tag)[inst] == .load_memory); |
| 660 | | const load_memory = emit.mir.instructions.items(.data)[inst].load_memory; |
| 661 | | const reg = @intToEnum(Register, load_memory.register); |
| 662 | | const addr = load_memory.addr; |
| 663 | | // The value is in memory at a hard-coded address. |
| 664 | | // If the type is a pointer, it means the pointer address is at this memory location. |
| 665 | | try emit.moveImmediate(reg, addr); |
| 666 | | try emit.writeInstruction(Instruction.ldr( |
| 667 | | reg, |
| 668 | | reg, |
| 669 | | Instruction.LoadStoreOffset.none, |
| 670 | | )); |
| 671 | | } |
| 672 | | |
| 673 | 647 | fn mirLoadMemoryPie(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 674 | 648 | const tag = emit.mir.instructions.items(.tag)[inst]; |
| 675 | 649 | const payload = emit.mir.instructions.items(.data)[inst].payload; |
| ... | ... | @@ -741,6 +715,7 @@ fn mirLoadStoreRegisterPair(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 741 | 715 | fn mirLoadStoreStack(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 742 | 716 | const tag = emit.mir.instructions.items(.tag)[inst]; |
| 743 | 717 | const load_store_stack = emit.mir.instructions.items(.data)[inst].load_store_stack; |
| 718 | const rt = load_store_stack.rt; |
| 744 | 719 | |
| 745 | 720 | const raw_offset = emit.stack_size - load_store_stack.offset; |
| 746 | 721 | const offset = switch (tag) { |
| ... | ... | @@ -760,7 +735,7 @@ fn mirLoadStoreStack(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 760 | 735 | } |
| 761 | 736 | }, |
| 762 | 737 | .ldr_stack, .str_stack => blk: { |
| 763 | | const alignment: u32 = switch (load_store_stack.rt.size()) { |
| 738 | const alignment: u32 = switch (rt.size()) { |
| 764 | 739 | 32 => 4, |
| 765 | 740 | 64 => 8, |
| 766 | 741 | else => unreachable, |
| ... | ... | @@ -777,36 +752,12 @@ fn mirLoadStoreStack(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 777 | 752 | }; |
| 778 | 753 | |
| 779 | 754 | switch (tag) { |
| 780 | | .ldr_stack => try emit.writeInstruction(Instruction.ldr( |
| 781 | | load_store_stack.rt, |
| 782 | | Register.sp, |
| 783 | | offset, |
| 784 | | )), |
| 785 | | .ldrb_stack => try emit.writeInstruction(Instruction.ldrb( |
| 786 | | load_store_stack.rt, |
| 787 | | Register.sp, |
| 788 | | offset, |
| 789 | | )), |
| 790 | | .ldrh_stack => try emit.writeInstruction(Instruction.ldrh( |
| 791 | | load_store_stack.rt, |
| 792 | | Register.sp, |
| 793 | | offset, |
| 794 | | )), |
| 795 | | .str_stack => try emit.writeInstruction(Instruction.str( |
| 796 | | load_store_stack.rt, |
| 797 | | Register.sp, |
| 798 | | offset, |
| 799 | | )), |
| 800 | | .strb_stack => try emit.writeInstruction(Instruction.strb( |
| 801 | | load_store_stack.rt, |
| 802 | | Register.sp, |
| 803 | | offset, |
| 804 | | )), |
| 805 | | .strh_stack => try emit.writeInstruction(Instruction.strh( |
| 806 | | load_store_stack.rt, |
| 807 | | Register.sp, |
| 808 | | offset, |
| 809 | | )), |
| 755 | .ldr_stack => try emit.writeInstruction(Instruction.ldr(rt, .sp, offset)), |
| 756 | .ldrb_stack => try emit.writeInstruction(Instruction.ldrb(rt, .sp, offset)), |
| 757 | .ldrh_stack => try emit.writeInstruction(Instruction.ldrh(rt, .sp, offset)), |
| 758 | .str_stack => try emit.writeInstruction(Instruction.str(rt, .sp, offset)), |
| 759 | .strb_stack => try emit.writeInstruction(Instruction.strb(rt, .sp, offset)), |
| 760 | .strh_stack => try emit.writeInstruction(Instruction.strh(rt, .sp, offset)), |
| 810 | 761 | else => unreachable, |
| 811 | 762 | } |
| 812 | 763 | } |
| ... | ... | @@ -914,7 +865,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 914 | 865 | if (count == number_of_regs - 1) { |
| 915 | 866 | try emit.writeInstruction(Instruction.ldr( |
| 916 | 867 | reg, |
| 917 | | Register.sp, |
| 868 | .sp, |
| 918 | 869 | Instruction.LoadStoreOffset.imm_post_index(16), |
| 919 | 870 | )); |
| 920 | 871 | } else { |
| ... | ... | @@ -924,7 +875,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 924 | 875 | try emit.writeInstruction(Instruction.ldp( |
| 925 | 876 | reg, |
| 926 | 877 | other_reg, |
| 927 | | Register.sp, |
| 878 | .sp, |
| 928 | 879 | Instruction.LoadStorePairOffset.post_index(16), |
| 929 | 880 | )); |
| 930 | 881 | } |
| ... | ... | @@ -944,7 +895,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 944 | 895 | if (count == number_of_regs - 1) { |
| 945 | 896 | try emit.writeInstruction(Instruction.str( |
| 946 | 897 | reg, |
| 947 | | Register.sp, |
| 898 | .sp, |
| 948 | 899 | Instruction.LoadStoreOffset.imm_pre_index(-16), |
| 949 | 900 | )); |
| 950 | 901 | } else { |
| ... | ... | @@ -954,7 +905,7 @@ fn mirPushPopRegs(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 954 | 905 | try emit.writeInstruction(Instruction.stp( |
| 955 | 906 | other_reg, |
| 956 | 907 | reg, |
| 957 | | Register.sp, |
| 908 | .sp, |
| 958 | 909 | Instruction.LoadStorePairOffset.pre_index(-16), |
| 959 | 910 | )); |
| 960 | 911 | } |