re-add loading small string literals

This commit is contained in:
Brendan Hansknecht 2022-02-17 17:47:25 -08:00
parent d33c02febd
commit e71da49dd1
2 changed files with 36 additions and 36 deletions

View file

@ -1073,34 +1073,29 @@ impl<
let val = *x as f32;
ASM::mov_freg32_imm32(&mut self.buf, &mut self.relocs, reg, val);
}
// (Literal::Str(x), Layout::Builtin(Builtin::Str)) if x.len() < 16 => {
(Literal::Str(x), Layout::Builtin(Builtin::Str)) if x.len() < 16 => {
// Load small string.
// let reg = self.get_tmp_general_reg();
self.storage_manager.with_tmp_general_reg(
&mut self.buf,
|storage_manager, buf, reg| {
let base_offset = storage_manager.claim_stack_area(sym, 16);
let mut bytes = [0; 16];
bytes[..x.len()].copy_from_slice(x.as_bytes());
bytes[15] = (x.len() as u8) | 0b1000_0000;
// let offset = self.claim_stack_size(16);
// self.symbol_storage_map.insert(
// *sym,
// SymbolStorage::Base {
// offset,
// size: 16,
// owned: true,
// },
// );
// let mut bytes = [0; 16];
// bytes[..x.len()].copy_from_slice(x.as_bytes());
// bytes[15] = (x.len() as u8) | 0b1000_0000;
let mut num_bytes = [0; 8];
num_bytes.copy_from_slice(&bytes[..8]);
let num = i64::from_ne_bytes(num_bytes);
ASM::mov_reg64_imm64(buf, reg, num);
ASM::mov_base32_reg64(buf, base_offset, reg);
// let mut num_bytes = [0; 8];
// num_bytes.copy_from_slice(&bytes[..8]);
// let num = i64::from_ne_bytes(num_bytes);
// ASM::mov_reg64_imm64(&mut self.buf, reg, num);
// ASM::mov_base32_reg64(&mut self.buf, offset, reg);
// num_bytes.copy_from_slice(&bytes[8..]);
// let num = i64::from_ne_bytes(num_bytes);
// ASM::mov_reg64_imm64(&mut self.buf, reg, num);
// ASM::mov_base32_reg64(&mut self.buf, offset + 8, reg);
// }
num_bytes.copy_from_slice(&bytes[8..]);
let num = i64::from_ne_bytes(num_bytes);
ASM::mov_reg64_imm64(buf, reg, num);
ASM::mov_base32_reg64(buf, base_offset + 8, reg);
},
);
}
x => todo!("loading literal, {:?}", x),
}
}

View file

@ -48,6 +48,7 @@ enum StackStorage<GeneralReg: RegTrait, FloatReg: RegTrait> {
// Note, this is also used for referencing a value within a struct/union.
// It has no alignment guarantees.
// When a primitive value is being loaded from this, it should be moved into a register.
// To start, the primitive can just be loaded as a ReferencePrimitive.
Complex {
// Offset from the base pointer in bytes.
base_offset: i32,
@ -419,16 +420,7 @@ impl<
self.symbol_storage_map.insert(*sym, NoData);
return;
}
let base_offset = self.claim_stack_size(struct_size);
self.symbol_storage_map.insert(
*sym,
Stack(Complex {
base_offset,
size: struct_size,
}),
);
self.allocation_map
.insert(*sym, Rc::new((base_offset, struct_size)));
let base_offset = self.claim_stack_area(sym, struct_size);
if let Layout::Struct(field_layouts) = layout {
let mut current_offset = base_offset;
@ -540,6 +532,19 @@ impl<
}
}
/// claim_stack_area is the public wrapper around claim_stack_size.
/// It also deals with updating symbol storage.
/// It returns the base offset of the stack area.
/// It should only be used for complex data and not primitives.
pub fn claim_stack_area(&mut self, sym: &Symbol, size: u32) -> i32 {
let base_offset = self.claim_stack_size(size);
self.symbol_storage_map
.insert(*sym, Stack(Complex { base_offset, size }));
self.allocation_map
.insert(*sym, Rc::new((base_offset, size)));
base_offset
}
/// claim_stack_size claims `amount` bytes from the stack alignind to 8.
/// This may be free space in the stack or result in increasing the stack size.
/// It returns base pointer relative offset of the new data.