compiler-rt: compute correct integer sizes from bits at runtime

Also, accepting `align(1)` pointers ensures that the alignment is safety
checked rather than assumed.
This commit is contained in:
Jacob Young
2025-04-11 04:23:36 -04:00
parent ed9aa8f259
commit b31a91bbef
24 changed files with 167 additions and 133 deletions

View File

@@ -1,6 +1,7 @@
const divCeil = @import("std").math.divCeil;
const common = @import("./common.zig");
const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;
const std = @import("std");
const builtin = @import("builtin");
const common = @import("common.zig");
const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
pub const panic = common.panic;
@@ -8,6 +9,7 @@ comptime {
@export(&__floatuneitf, .{ .name = "__floatuneitf", .linkage = common.linkage, .visibility = common.visibility });
}
pub fn __floatuneitf(a: [*]const u32, bits: usize) callconv(.c) f128 {
return floatFromBigInt(f128, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}