Skip to content

Commit

Permalink
16 byte align stack slots (like rustc does it)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenawanel committed Jun 18, 2024
1 parent 0df0e91 commit efe9d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions crates/codegen/src/compiler/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl FunctionCompiler<'_> {
let param_ty = param_tys[old_idx as usize];
if param_ty.is_aggregate() {
// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
const ABI_ALIGN_MASK: u32 = 16 - 1;

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
Expand Down Expand Up @@ -581,7 +581,7 @@ impl FunctionCompiler<'_> {
let value = self.world_bodies[self.file_name][local_def].value;

// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
const ABI_ALIGN_MASK: u32 = 16 - 1;

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
Expand Down Expand Up @@ -921,7 +921,7 @@ impl FunctionCompiler<'_> {

let (_, sub_ty) = ty.as_array().expect("array literals must have array types");
// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
const ABI_ALIGN_MASK: u32 = 16 - 1;
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: (ty.stride() + ABI_ALIGN_MASK) & !ABI_ALIGN_MASK,
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl FunctionCompiler<'_> {

// println!("{:?} = {inner_size}", self.tys[self.fqn.module][expr]);
// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
const ABI_ALIGN_MASK: u32 = 16 - 1;

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
Expand Down Expand Up @@ -1327,7 +1327,7 @@ impl FunctionCompiler<'_> {
let ret_addr = if return_ty.is_aggregate() {
let aggregate_size = return_ty.size();
// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
const ABI_ALIGN_MASK: u32 = 16 - 1;

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
Expand Down Expand Up @@ -1822,13 +1822,13 @@ impl FunctionCompiler<'_> {
} => {
let ty = self.tys[self.file_name][expr];

// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 8 - 1;
// TODO: this most likely oveshoots the abi align on some architectures
const ABI_ALIGN_MASK: u32 = 16 - 1;

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: (ty.stride() + ABI_ALIGN_MASK) & !ABI_ALIGN_MASK,
});
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: (ty.stride() + ABI_ALIGN_MASK) & !ABI_ALIGN_MASK,
});

let memory = MemoryLoc::from_stack(stack_slot, 0, &mut self.builder, self.ptr_ty);

Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn calc_single(ty: Intern<Ty>, ptr_ty: types::Type) {
},
hir_ty::Ty::Array { sub_ty, .. } => {
calc_single(*sub_ty, ptr_ty);
let mask = ptr_ty.bytes() - 1;
let mask = 16 - 1;
FinalTy::Pointer {
ty: ptr_ty,
aggr_pointee_size: Some((ty.stride() + mask) & !mask),
Expand Down Expand Up @@ -284,7 +284,7 @@ fn calc_single(ty: Intern<Ty>, ptr_ty: types::Type) {
for (_, ty) in members {
calc_single(*ty, ptr_ty);
}
let mask = ptr_ty.bytes() - 1;
let mask = 16 - 1;
FinalTy::Pointer {
ty: ptr_ty,
aggr_pointee_size: Some((ty.stride() + mask) & !mask),
Expand Down

0 comments on commit efe9d67

Please sign in to comment.