improved ABI alignment/size for >= 128-bit integers

* riscv64: adjust alignment and size of 128-bit integers.
 * take ofmt=c into account for ABI alignment of 128-bit integers and
   structs.
 * Type: make packed struct support intInfo
 * fix f80 alignment for i386-windows-msvc
This commit is contained in:
Andrew Kelley
2022-08-18 20:34:36 -07:00
parent b975f7a56f
commit cee82c7ce4
4 changed files with 69 additions and 32 deletions

View File

@@ -948,21 +948,29 @@ pub const Struct = struct {
switch (layout) {
.Packed => return 0,
.Auto => return field.ty.abiAlignment(target),
.Extern => {
// This logic is duplicated in Type.abiAlignmentAdvanced.
const ty_abi_align = field.ty.abiAlignment(target);
if (field.ty.isAbiInt() and field.ty.intInfo(target).bits >= 128) {
// The C ABI requires 128 bit integer fields of structs
// to be 16-bytes aligned.
return @maximum(ty_abi_align, 16);
.Auto => {
if (target.ofmt == .c) {
return alignmentExtern(field, target);
} else {
return field.ty.abiAlignment(target);
}
return ty_abi_align;
},
.Extern => return alignmentExtern(field, target),
}
}
pub fn alignmentExtern(field: Field, target: Target) u32 {
// This logic is duplicated in Type.abiAlignmentAdvanced.
const ty_abi_align = field.ty.abiAlignment(target);
if (field.ty.isAbiInt() and field.ty.intInfo(target).bits >= 128) {
// The C ABI requires 128 bit integer fields of structs
// to be 16-bytes aligned.
return @maximum(ty_abi_align, 16);
}
return ty_abi_align;
}
};
pub fn getFullyQualifiedName(s: *Struct, mod: *Module) ![:0]u8 {