Skip to content

Commit

Permalink
[X64] trying to implement something for x64 which did not work (const…
Browse files Browse the repository at this point in the history
… fp loading)
  • Loading branch information
Cr0a3 committed Oct 13, 2024
1 parent 6171111 commit 70721a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/CodeGen/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ impl MachineInstr {

let constant = module.addConst(&format!(".cimm{}", index));
constant.private();
constant.data = Vec::from(imm.to_ne_bytes());

if self.meta == TypeMetadata::f32 {
constant.data = Vec::from((imm as f32).to_bits().to_be_bytes());
} else { // f64
constant.data = Vec::from(imm.to_bits().to_le_bytes());
}

let stack_off = helper.alloc.alloc_stack(self.meta);

Expand All @@ -93,6 +98,14 @@ impl MachineInstr {

out.push(adrm);

let mut load = MachineInstr::new(MachineMnemonic::Load);
load.set_out(stack_off.into());
load.add_operand(stack_off.into());

load.meta = TypeMetadata::i64;

out.push(load);

*operand = stack_off.into();

index += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/IR/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl Module {
lines.push_str("section .rodata\n\n");

for (_, consta) in &self.consts {
lines.push_str(&format!("{}: {:?} # {}\n", consta.name, consta.data, consta.data.iter()
lines.push_str(&format!("{}: {:02X?} # {}\n", consta.name, consta.data, consta.data.iter()
.filter_map(|&byte| {
if byte >= 32 && byte <= 126 {
Some(byte as char)
Expand Down
4 changes: 4 additions & 0 deletions src/Target/x64/asm/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,10 @@ impl Into<MemoryOperand> for MemOp {
displ_size = 1;
}

if self.rip {
base = Register::RIP;
}

MemoryOperand::new(
base,
index,
Expand Down

0 comments on commit 70721a3

Please sign in to comment.