authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-04-11 04:23:36-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-04-11 07:06:01-04:00
logb31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61
treed35fef3fbf408fed83b3572ce16ff488ec09cdd2
parented9aa8f259d452cb344064ee412fc5af18877d55

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.

24 files changed, 167 insertions(+), 133 deletions(-)

lib/compiler_rt/divmodei4.zig+10-8
...@@ -33,18 +33,20 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {...@@ -33,18 +33,20 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
33 if (r) |x| if (u_sign < 0) neg(x);33 if (r) |x| if (u_sign < 0) neg(x);
34}34}
3535
36pub fn __divei4(r_q: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void {36pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
37 @setRuntimeSafety(builtin.is_test);37 @setRuntimeSafety(builtin.is_test);
38 const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];38 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
39 const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];39 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
40 const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];40 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
41 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
41 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;42 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
42}43}
4344
44pub fn __modei4(r_p: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void {45pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
45 @setRuntimeSafety(builtin.is_test);46 @setRuntimeSafety(builtin.is_test);
46 const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];47 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
47 const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];48 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
48 const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];49 const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
50 const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
49 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;51 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
50}52}
lib/compiler_rt/fixdfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixdfei, .{ .name = "__fixdfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixdfei, .{ .name = "__fixdfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void {12pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
12 return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixhfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixhfei, .{ .name = "__fixhfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixhfei, .{ .name = "__fixhfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixhfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void {12pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
12 return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixsfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixsfei, .{ .name = "__fixsfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixsfei, .{ .name = "__fixsfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixsfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void {12pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
12 return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixtfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixtfei, .{ .name = "__fixtfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixtfei, .{ .name = "__fixtfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixtfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void {12pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
12 return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixunsdfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixunsdfei, .{ .name = "__fixunsdfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixunsdfei, .{ .name = "__fixunsdfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixunsdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void {12pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
12 return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixunshfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixunshfei, .{ .name = "__fixunshfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixunshfei, .{ .name = "__fixunshfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixunshfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void {12pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
12 return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixunssfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixunssfei, .{ .name = "__fixunssfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixunssfei, .{ .name = "__fixunssfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixunssfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void {12pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
12 return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixunstfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixunstfei, .{ .name = "__fixunstfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixunstfei, .{ .name = "__fixunstfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixunstfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void {12pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
12 return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixunsxfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixunsxfei, .{ .name = "__fixunsxfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixunsxfei, .{ .name = "__fixunsxfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixunsxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void {12pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
12 return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/fixxfei.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat;3const common = @import("common.zig");
4const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__fixxfei, .{ .name = "__fixxfei", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__fixxfei, .{ .name = "__fixxfei", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __fixxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void {12pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
12 return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
13}15}
lib/compiler_rt/float_from_int_test.zig+1-5
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const testing = std.testing;2const testing = std.testing;
4const math = std.math;3const math = std.math;
5const endian = builtin.cpu.arch.endian();
64
7const __floatunsihf = @import("floatunsihf.zig").__floatunsihf;5const __floatunsihf = @import("floatunsihf.zig").__floatunsihf;
86
...@@ -237,12 +235,10 @@ test "floatuntisf" {...@@ -237,12 +235,10 @@ test "floatuntisf" {
237235
238fn test_floateisf(expected: u32, comptime T: type, a: T) !void {236fn test_floateisf(expected: u32, comptime T: type, a: T) !void {
239 const int = @typeInfo(T).int;237 const int = @typeInfo(T).int;
240 var a_buf: [@divExact(int.bits, 32)]u32 = undefined;
241 std.mem.writeInt(T, std.mem.asBytes(&a_buf), a, endian);
242 const r = switch (int.signedness) {238 const r = switch (int.signedness) {
243 .signed => __floateisf,239 .signed => __floateisf,
244 .unsigned => __floatuneisf,240 .unsigned => __floatuneisf,
245 }(&a_buf, int.bits);241 }(@ptrCast(&a), int.bits);
246 try testing.expect(expected == @as(u32, @bitCast(r)));242 try testing.expect(expected == @as(u32, @bitCast(r)));
247}243}
248244
lib/compiler_rt/floateidf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floateidf, .{ .name = "__floateidf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floateidf, .{ .name = "__floateidf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floateidf(a: [*]const u32, bits: usize) callconv(.c) f64 {12pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
12 return floatFromBigInt(f64, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floateihf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floateihf, .{ .name = "__floateihf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floateihf, .{ .name = "__floateihf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floateihf(a: [*]const u32, bits: usize) callconv(.c) f16 {12pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
12 return floatFromBigInt(f16, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floateisf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floateisf, .{ .name = "__floateisf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floateisf, .{ .name = "__floateisf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floateisf(a: [*]const u32, bits: usize) callconv(.c) f32 {12pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
12 return floatFromBigInt(f32, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floateitf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floateitf, .{ .name = "__floateitf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floateitf, .{ .name = "__floateitf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floateitf(a: [*]const u32, bits: usize) callconv(.c) f128 {12pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
12 return floatFromBigInt(f128, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floateixf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floateixf, .{ .name = "__floateixf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floateixf, .{ .name = "__floateixf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floateixf(a: [*]const u32, bits: usize) callconv(.c) f80 {12pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
12 return floatFromBigInt(f80, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floatuneidf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floatuneidf, .{ .name = "__floatuneidf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floatuneidf, .{ .name = "__floatuneidf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floatuneidf(a: [*]const u32, bits: usize) callconv(.c) f64 {12pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
12 return floatFromBigInt(f64, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floatuneihf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floatuneihf, .{ .name = "__floatuneihf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floatuneihf, .{ .name = "__floatuneihf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floatuneihf(a: [*]const u32, bits: usize) callconv(.c) f16 {12pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
12 return floatFromBigInt(f16, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floatuneisf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floatuneisf, .{ .name = "__floatuneisf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floatuneisf, .{ .name = "__floatuneisf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floatuneisf(a: [*]const u32, bits: usize) callconv(.c) f32 {12pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
12 return floatFromBigInt(f32, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floatuneitf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floatuneitf, .{ .name = "__floatuneitf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floatuneitf, .{ .name = "__floatuneitf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floatuneitf(a: [*]const u32, bits: usize) callconv(.c) f128 {12pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
12 return floatFromBigInt(f128, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/floatuneixf.zig+7-5
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const divCeil = @import("std").math.divCeil;1const std = @import("std");
2const common = @import("./common.zig");2const builtin = @import("builtin");
3const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt;3const common = @import("common.zig");
4const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt;
45
5pub const panic = common.panic;6pub const panic = common.panic;
67
...@@ -8,6 +9,7 @@ comptime {...@@ -8,6 +9,7 @@ comptime {
8 @export(&__floatuneixf, .{ .name = "__floatuneixf", .linkage = common.linkage, .visibility = common.visibility });9 @export(&__floatuneixf, .{ .name = "__floatuneixf", .linkage = common.linkage, .visibility = common.visibility });
9}10}
1011
11pub fn __floatuneixf(a: [*]const u32, bits: usize) callconv(.c) f80 {12pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
12 return floatFromBigInt(f80, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]);13 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
14 return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
13}15}
lib/compiler_rt/int_from_float_test.zig+6-12
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const testing = std.testing;2const testing = std.testing;
4const math = std.math;3const math = std.math;
5const endian = builtin.cpu.arch.endian();
64
7const __fixunshfti = @import("fixunshfti.zig").__fixunshfti;5const __fixunshfti = @import("fixunshfti.zig").__fixunshfti;
8const __fixunsxfti = @import("fixunsxfti.zig").__fixunsxfti;6const __fixunsxfti = @import("fixunsxfti.zig").__fixunsxfti;
...@@ -350,14 +348,12 @@ test "fixunssfti" {...@@ -350,14 +348,12 @@ test "fixunssfti" {
350348
351fn test_fixsfei(comptime T: type, expected: T, a: f32) !void {349fn test_fixsfei(comptime T: type, expected: T, a: f32) !void {
352 const int = @typeInfo(T).int;350 const int = @typeInfo(T).int;
353 var expected_buf: [@divExact(int.bits, 32)]u32 = undefined;351 var actual: T = undefined;
354 std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian);
355 var actual_buf: [@divExact(int.bits, 32)]u32 = undefined;
356 _ = switch (int.signedness) {352 _ = switch (int.signedness) {
357 .signed => __fixsfei,353 .signed => __fixsfei,
358 .unsigned => __fixunssfei,354 .unsigned => __fixunssfei,
359 }(&actual_buf, int.bits, a);355 }(@ptrCast(&actual), int.bits, a);
360 try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf));356 try testing.expect(expected == actual);
361}357}
362358
363test "fixsfei" {359test "fixsfei" {
...@@ -685,14 +681,12 @@ test "fixunsdfti" {...@@ -685,14 +681,12 @@ test "fixunsdfti" {
685681
686fn test_fixdfei(comptime T: type, expected: T, a: f64) !void {682fn test_fixdfei(comptime T: type, expected: T, a: f64) !void {
687 const int = @typeInfo(T).int;683 const int = @typeInfo(T).int;
688 var expected_buf: [@divExact(int.bits, 32)]u32 = undefined;684 var actual: T = undefined;
689 std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian);
690 var actual_buf: [@divExact(int.bits, 32)]u32 = undefined;
691 _ = switch (int.signedness) {685 _ = switch (int.signedness) {
692 .signed => __fixdfei,686 .signed => __fixdfei,
693 .unsigned => __fixunsdfei,687 .unsigned => __fixunsdfei,
694 }(&actual_buf, int.bits, a);688 }(@ptrCast(&actual), int.bits, a);
695 try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf));689 try testing.expect(expected == actual);
696}690}
697691
698test "fixdfei" {692test "fixdfei" {
lib/compiler_rt/udivmodei4.zig+10-8
...@@ -112,19 +112,21 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {...@@ -112,19 +112,21 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
112 }112 }
113}113}
114114
115pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void {115pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
116 @setRuntimeSafety(builtin.is_test);116 @setRuntimeSafety(builtin.is_test);
117 const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];117 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
118 const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];118 const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
119 const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];119 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
120 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
120 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;121 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
121}122}
122123
123pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void {124pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
124 @setRuntimeSafety(builtin.is_test);125 @setRuntimeSafety(builtin.is_test);
125 const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];126 const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
126 const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];127 const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
127 const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable];128 const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
129 const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
128 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;130 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
129}131}
130132