From b31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 11 Apr 2025 04:23:36 -0400 Subject: 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. --- lib/compiler_rt/fixxfei.zig | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/compiler_rt/fixxfei.zig') diff --git a/lib/compiler_rt/fixxfei.zig b/lib/compiler_rt/fixxfei.zig index 8a4d3d0de1..5efe7da7e9 100644 --- a/lib/compiler_rt/fixxfei.zig +++ b/lib/compiler_rt/fixxfei.zig @@ -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(&__fixxfei, .{ .name = "__fixxfei", .linkage = common.linkage, .visibility = common.visibility }); } -pub fn __fixxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void { - return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); +pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void { + const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits)); + return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a); } -- cgit v1.2.3