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
+7 -5
View File
@@ -1,6 +1,7 @@
const divCeil = @import("std").math.divCeil;
const common = @import("./common.zig");
const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;
const std = @import("std");
const builtin = @import("builtin");
const common = @import("common.zig");
const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
pub const panic = common.panic;
@@ -8,6 +9,7 @@ comptime {
@export(&__fixdfei, .{ .name = "__fixdfei", .linkage = common.linkage, .visibility = common.visibility });
}
pub fn __fixdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void {
return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}