aboutsummaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/compiler_rt/divmodei4.zig18
-rw-r--r--lib/compiler_rt/fixdfei.zig12
-rw-r--r--lib/compiler_rt/fixhfei.zig12
-rw-r--r--lib/compiler_rt/fixsfei.zig12
-rw-r--r--lib/compiler_rt/fixtfei.zig12
-rw-r--r--lib/compiler_rt/fixunsdfei.zig12
-rw-r--r--lib/compiler_rt/fixunshfei.zig12
-rw-r--r--lib/compiler_rt/fixunssfei.zig12
-rw-r--r--lib/compiler_rt/fixunstfei.zig12
-rw-r--r--lib/compiler_rt/fixunsxfei.zig12
-rw-r--r--lib/compiler_rt/fixxfei.zig12
-rw-r--r--lib/compiler_rt/float_from_int_test.zig6
-rw-r--r--lib/compiler_rt/floateidf.zig12
-rw-r--r--lib/compiler_rt/floateihf.zig12
-rw-r--r--lib/compiler_rt/floateisf.zig12
-rw-r--r--lib/compiler_rt/floateitf.zig12
-rw-r--r--lib/compiler_rt/floateixf.zig12
-rw-r--r--lib/compiler_rt/floatuneidf.zig12
-rw-r--r--lib/compiler_rt/floatuneihf.zig12
-rw-r--r--lib/compiler_rt/floatuneisf.zig12
-rw-r--r--lib/compiler_rt/floatuneitf.zig12
-rw-r--r--lib/compiler_rt/floatuneixf.zig12
-rw-r--r--lib/compiler_rt/int_from_float_test.zig18
-rw-r--r--lib/compiler_rt/udivmodei4.zig18
24 files changed, 167 insertions, 133 deletions
diff --git a/lib/compiler_rt/divmodei4.zig b/lib/compiler_rt/divmodei4.zig
index f5ed41d9d7..9e5e4333b9 100644
--- a/lib/compiler_rt/divmodei4.zig
+++ b/lib/compiler_rt/divmodei4.zig
@@ -33,18 +33,20 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
if (r) |x| if (u_sign < 0) neg(x);
}
-pub fn __divei4(r_q: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void {
+pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
- const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
+ const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
+ const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
}
-pub fn __modei4(r_p: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void {
+pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
- const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
+ const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
+ const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
}
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);
}
diff --git a/lib/compiler_rt/fixhfei.zig b/lib/compiler_rt/fixhfei.zig
index 4211007f99..c4532f18c0 100644
--- a/lib/compiler_rt/fixhfei.zig
+++ b/lib/compiler_rt/fixhfei.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(&__fixhfei, .{ .name = "__fixhfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixhfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void {
- return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixsfei.zig b/lib/compiler_rt/fixsfei.zig
index bad397e494..8182ca0551 100644
--- a/lib/compiler_rt/fixsfei.zig
+++ b/lib/compiler_rt/fixsfei.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(&__fixsfei, .{ .name = "__fixsfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixsfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void {
- return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixtfei.zig b/lib/compiler_rt/fixtfei.zig
index 5f5085b135..02a2c164a6 100644
--- a/lib/compiler_rt/fixtfei.zig
+++ b/lib/compiler_rt/fixtfei.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(&__fixtfei, .{ .name = "__fixtfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixtfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void {
- return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixunsdfei.zig b/lib/compiler_rt/fixunsdfei.zig
index bda88b5134..a88c344bc6 100644
--- a/lib/compiler_rt/fixunsdfei.zig
+++ b/lib/compiler_rt/fixunsdfei.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(&__fixunsdfei, .{ .name = "__fixunsdfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixunsdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void {
- return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixunshfei.zig b/lib/compiler_rt/fixunshfei.zig
index afa0be9691..056d2faaf7 100644
--- a/lib/compiler_rt/fixunshfei.zig
+++ b/lib/compiler_rt/fixunshfei.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(&__fixunshfei, .{ .name = "__fixunshfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixunshfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void {
- return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixunssfei.zig b/lib/compiler_rt/fixunssfei.zig
index 0f8c1a2948..179e395de0 100644
--- a/lib/compiler_rt/fixunssfei.zig
+++ b/lib/compiler_rt/fixunssfei.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(&__fixunssfei, .{ .name = "__fixunssfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixunssfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void {
- return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixunstfei.zig b/lib/compiler_rt/fixunstfei.zig
index 8668e43984..b69fb31ab6 100644
--- a/lib/compiler_rt/fixunstfei.zig
+++ b/lib/compiler_rt/fixunstfei.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(&__fixunstfei, .{ .name = "__fixunstfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixunstfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void {
- return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
diff --git a/lib/compiler_rt/fixunsxfei.zig b/lib/compiler_rt/fixunsxfei.zig
index 079aa7fe9f..ca1bae9a80 100644
--- a/lib/compiler_rt/fixunsxfei.zig
+++ b/lib/compiler_rt/fixunsxfei.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(&__fixunsxfei, .{ .name = "__fixunsxfei", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __fixunsxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void {
- return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);
+pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
}
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);
}
diff --git a/lib/compiler_rt/float_from_int_test.zig b/lib/compiler_rt/float_from_int_test.zig
index f04dd30bfc..8c908f4209 100644
--- a/lib/compiler_rt/float_from_int_test.zig
+++ b/lib/compiler_rt/float_from_int_test.zig
@@ -1,8 +1,6 @@
const std = @import("std");
-const builtin = @import("builtin");
const testing = std.testing;
const math = std.math;
-const endian = builtin.cpu.arch.endian();
const __floatunsihf = @import("floatunsihf.zig").__floatunsihf;
@@ -237,12 +235,10 @@ test "floatuntisf" {
fn test_floateisf(expected: u32, comptime T: type, a: T) !void {
const int = @typeInfo(T).int;
- var a_buf: [@divExact(int.bits, 32)]u32 = undefined;
- std.mem.writeInt(T, std.mem.asBytes(&a_buf), a, endian);
const r = switch (int.signedness) {
.signed => __floateisf,
.unsigned => __floatuneisf,
- }(&a_buf, int.bits);
+ }(@ptrCast(&a), int.bits);
try testing.expect(expected == @as(u32, @bitCast(r)));
}
diff --git a/lib/compiler_rt/floateidf.zig b/lib/compiler_rt/floateidf.zig
index 4cdaf37ce7..c540cc1d1c 100644
--- a/lib/compiler_rt/floateidf.zig
+++ b/lib/compiler_rt/floateidf.zig
@@ -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(&__floateidf, .{ .name = "__floateidf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floateidf(a: [*]const u32, bits: usize) callconv(.c) f64 {
- return floatFromBigInt(f64, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floateihf.zig b/lib/compiler_rt/floateihf.zig
index 7b74a981e7..b9544cc9b0 100644
--- a/lib/compiler_rt/floateihf.zig
+++ b/lib/compiler_rt/floateihf.zig
@@ -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(&__floateihf, .{ .name = "__floateihf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floateihf(a: [*]const u32, bits: usize) callconv(.c) f16 {
- return floatFromBigInt(f16, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floateisf.zig b/lib/compiler_rt/floateisf.zig
index 2857b80785..6420016d00 100644
--- a/lib/compiler_rt/floateisf.zig
+++ b/lib/compiler_rt/floateisf.zig
@@ -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(&__floateisf, .{ .name = "__floateisf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floateisf(a: [*]const u32, bits: usize) callconv(.c) f32 {
- return floatFromBigInt(f32, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floateitf.zig b/lib/compiler_rt/floateitf.zig
index bedd37e21d..6dfaac2955 100644
--- a/lib/compiler_rt/floateitf.zig
+++ b/lib/compiler_rt/floateitf.zig
@@ -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(&__floateitf, .{ .name = "__floateitf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floateitf(a: [*]const u32, bits: usize) callconv(.c) f128 {
- return floatFromBigInt(f128, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floateixf.zig b/lib/compiler_rt/floateixf.zig
index e0b72e075f..4c76e8b12f 100644
--- a/lib/compiler_rt/floateixf.zig
+++ b/lib/compiler_rt/floateixf.zig
@@ -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(&__floateixf, .{ .name = "__floateixf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floateixf(a: [*]const u32, bits: usize) callconv(.c) f80 {
- return floatFromBigInt(f80, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floatuneidf.zig b/lib/compiler_rt/floatuneidf.zig
index 34d700c2d3..e47ae0309b 100644
--- a/lib/compiler_rt/floatuneidf.zig
+++ b/lib/compiler_rt/floatuneidf.zig
@@ -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(&__floatuneidf, .{ .name = "__floatuneidf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floatuneidf(a: [*]const u32, bits: usize) callconv(.c) f64 {
- return floatFromBigInt(f64, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floatuneihf.zig b/lib/compiler_rt/floatuneihf.zig
index 93ebe4221e..cc8962161c 100644
--- a/lib/compiler_rt/floatuneihf.zig
+++ b/lib/compiler_rt/floatuneihf.zig
@@ -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(&__floatuneihf, .{ .name = "__floatuneihf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floatuneihf(a: [*]const u32, bits: usize) callconv(.c) f16 {
- return floatFromBigInt(f16, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floatuneisf.zig b/lib/compiler_rt/floatuneisf.zig
index 58e873e81e..325b0afe70 100644
--- a/lib/compiler_rt/floatuneisf.zig
+++ b/lib/compiler_rt/floatuneisf.zig
@@ -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(&__floatuneisf, .{ .name = "__floatuneisf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floatuneisf(a: [*]const u32, bits: usize) callconv(.c) f32 {
- return floatFromBigInt(f32, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/floatuneitf.zig b/lib/compiler_rt/floatuneitf.zig
index 61c2c93b28..727d301f7b 100644
--- a/lib/compiler_rt/floatuneitf.zig
+++ b/lib/compiler_rt/floatuneitf.zig
@@ -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])));
}
diff --git a/lib/compiler_rt/floatuneixf.zig b/lib/compiler_rt/floatuneixf.zig
index f2043dabba..adfa8aa5ee 100644
--- a/lib/compiler_rt/floatuneixf.zig
+++ b/lib/compiler_rt/floatuneixf.zig
@@ -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(&__floatuneixf, .{ .name = "__floatuneixf", .linkage = common.linkage, .visibility = common.visibility });
}
-pub fn __floatuneixf(a: [*]const u32, bits: usize) callconv(.c) f80 {
- return floatFromBigInt(f80, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);
+pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
}
diff --git a/lib/compiler_rt/int_from_float_test.zig b/lib/compiler_rt/int_from_float_test.zig
index 5305ecf2a0..de96954dd1 100644
--- a/lib/compiler_rt/int_from_float_test.zig
+++ b/lib/compiler_rt/int_from_float_test.zig
@@ -1,8 +1,6 @@
const std = @import("std");
-const builtin = @import("builtin");
const testing = std.testing;
const math = std.math;
-const endian = builtin.cpu.arch.endian();
const __fixunshfti = @import("fixunshfti.zig").__fixunshfti;
const __fixunsxfti = @import("fixunsxfti.zig").__fixunsxfti;
@@ -350,14 +348,12 @@ test "fixunssfti" {
fn test_fixsfei(comptime T: type, expected: T, a: f32) !void {
const int = @typeInfo(T).int;
- var expected_buf: [@divExact(int.bits, 32)]u32 = undefined;
- std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian);
- var actual_buf: [@divExact(int.bits, 32)]u32 = undefined;
+ var actual: T = undefined;
_ = switch (int.signedness) {
.signed => __fixsfei,
.unsigned => __fixunssfei,
- }(&actual_buf, int.bits, a);
- try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf));
+ }(@ptrCast(&actual), int.bits, a);
+ try testing.expect(expected == actual);
}
test "fixsfei" {
@@ -685,14 +681,12 @@ test "fixunsdfti" {
fn test_fixdfei(comptime T: type, expected: T, a: f64) !void {
const int = @typeInfo(T).int;
- var expected_buf: [@divExact(int.bits, 32)]u32 = undefined;
- std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian);
- var actual_buf: [@divExact(int.bits, 32)]u32 = undefined;
+ var actual: T = undefined;
_ = switch (int.signedness) {
.signed => __fixdfei,
.unsigned => __fixunsdfei,
- }(&actual_buf, int.bits, a);
- try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf));
+ }(@ptrCast(&actual), int.bits, a);
+ try testing.expect(expected == actual);
}
test "fixdfei" {
diff --git a/lib/compiler_rt/udivmodei4.zig b/lib/compiler_rt/udivmodei4.zig
index fa7f9746b1..d84bace9fb 100644
--- a/lib/compiler_rt/udivmodei4.zig
+++ b/lib/compiler_rt/udivmodei4.zig
@@ -112,19 +112,21 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
}
}
-pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void {
+pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
- const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
+ const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
+ const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
}
-pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void {
+pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
@setRuntimeSafety(builtin.is_test);
- const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
- const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];
+ const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
+ const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
+ const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
+ const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
}