diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Target.zig | 62 | ||||
| -rw-r--r-- | lib/std/zig/target.zig | 32 |
2 files changed, 94 insertions, 0 deletions
diff --git a/lib/std/Target.zig b/lib/std/Target.zig index ea7be17697..e445ab42e6 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -3273,6 +3273,68 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 { ); } +pub fn cMaxIntAlignment(target: std.Target) u16 { + return switch (target.cpu.arch) { + .avr => 1, + + .msp430 => 2, + + .xcore, + .propeller, + => 4, + + .amdgcn, + .arm, + .armeb, + .thumb, + .thumbeb, + .lanai, + .hexagon, + .mips, + .mipsel, + .powerpc, + .powerpcle, + .riscv32, + .s390x, + => 8, + + // Even LLVMABIAlignmentOfType(i128) agrees on these targets. + .aarch64, + .aarch64_be, + .bpfel, + .bpfeb, + .mips64, + .mips64el, + .nvptx, + .nvptx64, + .powerpc64, + .powerpc64le, + .riscv64, + .sparc, + .sparc64, + .wasm32, + .wasm64, + .x86, + .x86_64, + => 16, + + // Below this comment are unverified but based on the fact that C requires + // int128_t to be 16 bytes aligned, it's a safe default. + .arc, + .csky, + .kalimba, + .loongarch32, + .loongarch64, + .m68k, + .spirv, + .spirv32, + .spirv64, + .ve, + .xtensa, + => 16, + }; +} + pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention { return switch (target.cpu.arch) { .x86_64 => switch (target.os.tag) { diff --git a/lib/std/zig/target.zig b/lib/std/zig/target.zig index 2574f26d18..4b20c132a6 100644 --- a/lib/std/zig/target.zig +++ b/lib/std/zig/target.zig @@ -352,6 +352,38 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool { } } +pub fn intByteSize(target: std.Target, bits: u16) u19 { + return std.mem.alignForward(u19, @intCast((@as(u17, bits) + 7) / 8), intAlignment(target, bits)); +} + +pub fn intAlignment(target: std.Target, bits: u16) u16 { + return switch (target.cpu.arch) { + .x86 => switch (bits) { + 0 => 0, + 1...8 => 1, + 9...16 => 2, + 17...32 => 4, + 33...64 => switch (target.os.tag) { + .uefi, .windows => 8, + else => 4, + }, + else => 16, + }, + .x86_64 => switch (bits) { + 0 => 0, + 1...8 => 1, + 9...16 => 2, + 17...32 => 4, + 33...64 => 8, + else => 16, + }, + else => return @min( + std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))), + target.cMaxIntAlignment(), + ), + }; +} + const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; |
