aboutsummaryrefslogtreecommitdiff
path: root/lib/compiler_rt/fixdfei.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-04-11 04:23:36 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-04-11 07:06:01 -0400
commitb31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61 (patch)
treed35fef3fbf408fed83b3572ce16ff488ec09cdd2 /lib/compiler_rt/fixdfei.zig
parented9aa8f259d452cb344064ee412fc5af18877d55 (diff)
downloadzig-b31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61.tar.gz
zig-b31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61.zip
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.
Diffstat (limited to 'lib/compiler_rt/fixdfei.zig')
-rw-r--r--lib/compiler_rt/fixdfei.zig12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/compiler_rt/fixdfei.zig b/lib/compiler_rt/fixdfei.zig
index 9be2719422..95189b0f7b 100644
--- a/lib/compiler_rt/fixdfei.zig
+++ b/lib/compiler_rt/fixdfei.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(&__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);
}