diff --git a/lib/compiler_rt/divmodei4.zig b/lib/compiler_rt/divmodei4.zig index f5ed41d9d70f7717a63319e6adf73933a4456c16..9e5e4333b999ba546a6e1d10eca98c3ff8929a3f 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 9be2719422a952e097a9181ccb7e32f9958f189f..95189b0f7b410e04c3997597a970c49c97da6141 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 4211007f9985d021e30e4fce6817f93497230dfe..c4532f18c043aca6597d139c3ce171ab16dd66f7 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 bad397e494db817eeec09a53e864c8a21ea512df..8182ca055108697e61f7529614c2816a787e8633 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 5f5085b135e7c9c606ed138754a65a1b828c1184..02a2c164a6245ec18498f43f062793a51f66d6a6 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 bda88b5134782c75d0bdc62b3b6144a5e8676770..a88c344bc66f0db6adfbcdc24f2ae4fe3bf37c3d 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 afa0be969199ba1fb8a156ad043ca7c755fa4f31..056d2faaf74a7096d4c89609258c3c765ce3cdf1 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 0f8c1a2948ec09ce55a06799d445d41d1cfb29ec..179e395de0773920a8683ce4d3394146c4a0a798 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 8668e439846eceeed0cb92fd9673864726e48b5b..b69fb31ab600c0605db05afcae32929a6d99946c 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 079aa7fe9f779edc5538c1a2197b8ab493004b68..ca1bae9a805aadb6394ee0a5c19755e2fdbdb16d 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 8a4d3d0de121aab68f7402220af0b5e15e596f25..5efe7da7e9520ad8632b1ac7dd89c79771f9ca11 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 f04dd30bfc5fdc694c399270ba339ad37b87ba09..8c908f420959b28fe107f290cb0bcb709c9ffd85 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 4cdaf37ce7ba58e2bccc19303a0d6d41a0b81eb9..c540cc1d1c40d1daa76fb1508f9c02e2aa4bf943 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 7b74a981e738aab90b58948a7a05040db6cbdbc9..b9544cc9b021a011c6bb5451b1dcf95b3f273e51 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 2857b807857e595d421648c67b27bf5b6c2d9026..6420016d00deb2303a56efcbdca7390ef7d07967 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 bedd37e21db61ba653c00e7e778dff2c7e2dbe06..6dfaac29557425b2f9375726fb71a83253336151 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 e0b72e075f2d99e423386c010aab55c102cbaf5a..4c76e8b12f1afec63fd2c409dc720b664cf5966a 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 34d700c2d3680a4f0f9d30591e5abae4655cc9f3..e47ae0309ba6d1c77d898d6cbc750889a545f9d9 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 93ebe4221efa98ced0d8a44731b0351b289751a5..cc8962161cdd0fab48f713ac2c6e37a3e2422833 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 58e873e81e193930c5cc5ff4a264f73a54de57e0..325b0afe708874388890f95ee7e3d7efa773c180 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 61c2c93b2895f2f022b1dda223a71e03aa56a803..727d301f7bf3dceb4265369f660c8b708f8a24ed 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 f2043dabba1f6d8cf8363d72ceea5be9bdddc585..adfa8aa5ee1c685a2283b1071482dfb7d1242359 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 5305ecf2a065749040accc5fc9c4434acb85be6b..de96954dd15474c6d9f9c5109c717b3d5b6417c2 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 fa7f9746b10bf704f84c376fd136ffad5ac368b7..d84bace9fbac8300386bc62a32cbaa3226e15a3f 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; }