From 7e383093644b819e7951268ae2e88dc588346413 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 26 Jan 2022 17:24:52 +0100 Subject: [PATCH] make alignment target-specific --- compiler/builtins/src/bitcode.rs | 18 ++++++++++++++++-- compiler/target/src/lib.rs | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler/builtins/src/bitcode.rs b/compiler/builtins/src/bitcode.rs index 9321d08637..0284e9e774 100644 --- a/compiler/builtins/src/bitcode.rs +++ b/compiler/builtins/src/bitcode.rs @@ -48,13 +48,20 @@ impl FloatWidth { } pub const fn alignment_bytes(&self, target_info: TargetInfo) -> u32 { + use roc_target::Architecture; use std::mem::align_of; use FloatWidth::*; // TODO actually alignment is architecture-specific match self { F32 => align_of::() as u32, - F64 => align_of::() as u32, + F64 => match target_info.architecture { + Architecture::X86_64 + | Architecture::Aarch64 + | Architecture::Arm + | Architecture::Wasm32 => 8, + Architecture::X86_32 => 4, + }, F128 => align_of::() as u32, } } @@ -108,6 +115,7 @@ impl IntWidth { } pub const fn alignment_bytes(&self, target_info: TargetInfo) -> u32 { + use roc_target::Architecture; use std::mem::align_of; use IntWidth::*; @@ -115,7 +123,13 @@ impl IntWidth { U8 | I8 => align_of::() as u32, U16 | I16 => align_of::() as u32, U32 | I32 => align_of::() as u32, - U64 | I64 => align_of::() as u32, + U64 | I64 => match target_info.architecture { + Architecture::X86_64 + | Architecture::Aarch64 + | Architecture::Arm + | Architecture::Wasm32 => 8, + Architecture::X86_32 => 4, + }, U128 | I128 => align_of::() as u32, } } diff --git a/compiler/target/src/lib.rs b/compiler/target/src/lib.rs index e62cefb710..68269a3849 100644 --- a/compiler/target/src/lib.rs +++ b/compiler/target/src/lib.rs @@ -4,7 +4,7 @@ #[derive(Debug, Clone, Copy)] pub struct TargetInfo { - architecture: Architecture, + pub architecture: Architecture, } impl TargetInfo {