Skip to content

Commit

Permalink
rt: Emit float constants in epilog also on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 5, 2025
1 parent 1df4b3f commit 9331c08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 15 additions & 0 deletions dora-asm/src/arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct ForwardJump {
}

enum JumpKind {
Adr(Register),
Unconditional,
Conditional(Cond),
Zero {
Expand Down Expand Up @@ -276,6 +277,11 @@ impl AssemblerArm64 {
self.set_position(jmp.offset as usize);

match jmp.kind {
JumpKind::Adr(rd) => {
let distance: i32 = lbl_offset as i32 - jmp.offset as i32;
self.adr_imm(rd, distance);
}

JumpKind::Conditional(cond) => {
self.bc_imm(cond.into(), distance);
}
Expand Down Expand Up @@ -436,6 +442,15 @@ impl AssemblerArm64 {
self.emit_u32(cls::pcrel(0, imm, rd));
}

pub fn adr_label(&mut self, rd: Register, label: Label) {
self.unresolved_jumps.push(ForwardJump {
offset: self.position().try_into().expect("overflow"),
label,
kind: JumpKind::Adr(rd),
});
self.emit_u32(0);
}

pub fn adrp_imm(&mut self, rd: Register, imm: i32) {
self.emit_u32(cls::pcrel(1, imm, rd));
}
Expand Down
15 changes: 7 additions & 8 deletions dora-runtime/src/masm/arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::compiler::codegen::AnyReg;
use crate::cpu::*;
use crate::gc::swiper::LARGE_OBJECT_SIZE;
use crate::gc::Address;
use crate::masm::{CondCode, Label, MacroAssembler, Mem};
use crate::masm::{CondCode, EpilogConstant, Label, MacroAssembler, Mem};
use crate::mem::ptr_width;
use crate::mirror::{offset_of_array_data, offset_of_array_length, Header, REMEMBERED_BIT_SHIFT};
use crate::mode::MachineMode;
Expand Down Expand Up @@ -883,17 +883,16 @@ impl MacroAssembler {
}

pub fn load_float_const(&mut self, mode: MachineMode, dest: FReg, imm: f64) {
let off = match mode {
MachineMode::Float32 => self.add_const_f32(imm as f32),
MachineMode::Float64 => self.add_const_f64(imm),
let const_value = match mode {
MachineMode::Float32 => EpilogConstant::Float32(imm as f32),
MachineMode::Float64 => EpilogConstant::Float64(imm),
_ => unreachable!(),
};

let pos = self.pos() as i32;
let disp = off + pos;
let label = self.asm.create_label();
self.epilog_constants.push((label, const_value));

let scratch = self.get_scratch();
self.asm.adr_imm((*scratch).into(), -disp);
self.asm.adr_label((*scratch).into(), label);

self.load_mem(mode, dest.into(), Mem::Base(*scratch, 0));
}
Expand Down

0 comments on commit 9331c08

Please sign in to comment.