| author | |
| committer | |
| log | b31a91bbef2bafb19fd2b76cd8a1c8a4ed15eb61 |
| tree | d35fef3fbf408fed83b3572ce16ff488ec09cdd2 |
| parent | ed9aa8f259d452cb344064ee412fc5af18877d55 |
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 | 33 | if (r) |x| if (u_sign < 0) neg(x); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | pub fn __divei4(r_q: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void { | |
| 36 | pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void { | |
| 37 | 37 | @setRuntimeSafety(builtin.is_test); |
| 38 | const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 39 | const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 40 | const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 38 | const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits)); | |
| 39 | const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size])); | |
| 40 | const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size])); | |
| 41 | const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size])); | |
| 41 | 42 | @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | pub fn __modei4(r_p: [*]u32, u_p: [*]u32, v_p: [*]u32, bits: usize) callconv(.c) void { | |
| 45 | pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void { | |
| 45 | 46 | @setRuntimeSafety(builtin.is_test); |
| 46 | const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 47 | const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 48 | const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 47 | const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits)); | |
| 48 | const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size])); | |
| 49 | const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size])); | |
| 50 | const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size])); | |
| 49 | 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixdfei, .{ .name = "__fixdfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixhfei, .{ .name = "__fixhfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixhfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixsfei, .{ .name = "__fixsfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixsfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixtfei, .{ .name = "__fixtfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixtfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixunsdfei, .{ .name = "__fixunsdfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixunsdfei(r: [*]u32, bits: usize, a: f64) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixunshfei, .{ .name = "__fixunshfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixunshfei(r: [*]u32, bits: usize, a: f16) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixunssfei, .{ .name = "__fixunssfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixunssfei(r: [*]u32, bits: usize, a: f32) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixunstfei, .{ .name = "__fixunstfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixunstfei(r: [*]u32, bits: usize, a: f128) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixunsxfei, .{ .name = "__fixunsxfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixunsxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.unsigned, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const bigIntFromFloat = @import("./int_from_float.zig").bigIntFromFloat; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__fixxfei, .{ .name = "__fixxfei", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __fixxfei(r: [*]u32, bits: usize, a: f80) callconv(.c) void { | |
| 12 | return bigIntFromFloat(.signed, r[0 .. divCeil(usize, bits, 32) catch unreachable], a); | |
| 12 | pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void { | |
| 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 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const testing = std.testing; |
| 4 | 3 | const math = std.math; |
| 5 | const endian = builtin.cpu.arch.endian(); | |
| 6 | 4 | |
| 7 | 5 | const __floatunsihf = @import("floatunsihf.zig").__floatunsihf; |
| 8 | 6 | |
| ... | ... | @@ -237,12 +235,10 @@ test "floatuntisf" { |
| 237 | 235 | |
| 238 | 236 | fn test_floateisf(expected: u32, comptime T: type, a: T) !void { |
| 239 | 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 | 238 | const r = switch (int.signedness) { |
| 243 | 239 | .signed => __floateisf, |
| 244 | 240 | .unsigned => __floatuneisf, |
| 245 | }(&a_buf, int.bits); | |
| 241 | }(@ptrCast(&a), int.bits); | |
| 246 | 242 | try testing.expect(expected == @as(u32, @bitCast(r))); |
| 247 | 243 | } |
| 248 | 244 |
lib/compiler_rt/floateidf.zig+7-5| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floateidf, .{ .name = "__floateidf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floateidf(a: [*]const u32, bits: usize) callconv(.c) f64 { | |
| 12 | return floatFromBigInt(f64, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floateihf, .{ .name = "__floateihf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floateihf(a: [*]const u32, bits: usize) callconv(.c) f16 { | |
| 12 | return floatFromBigInt(f16, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floateisf, .{ .name = "__floateisf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floateisf(a: [*]const u32, bits: usize) callconv(.c) f32 { | |
| 12 | return floatFromBigInt(f32, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floateitf, .{ .name = "__floateitf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floateitf(a: [*]const u32, bits: usize) callconv(.c) f128 { | |
| 12 | return floatFromBigInt(f128, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floateixf, .{ .name = "__floateixf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floateixf(a: [*]const u32, bits: usize) callconv(.c) f80 { | |
| 12 | return floatFromBigInt(f80, .signed, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floatuneidf, .{ .name = "__floatuneidf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floatuneidf(a: [*]const u32, bits: usize) callconv(.c) f64 { | |
| 12 | return floatFromBigInt(f64, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floatuneihf, .{ .name = "__floatuneihf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floatuneihf(a: [*]const u32, bits: usize) callconv(.c) f16 { | |
| 12 | return floatFromBigInt(f16, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floatuneisf, .{ .name = "__floatuneisf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floatuneisf(a: [*]const u32, bits: usize) callconv(.c) f32 { | |
| 12 | return floatFromBigInt(f32, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floatuneitf, .{ .name = "__floatuneitf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floatuneitf(a: [*]const u32, bits: usize) callconv(.c) f128 { | |
| 12 | return floatFromBigInt(f128, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 { | |
| 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 | const divCeil = @import("std").math.divCeil; | |
| 2 | const common = @import("./common.zig"); | |
| 3 | const floatFromBigInt = @import("./float_from_int.zig").floatFromBigInt; | |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const common = @import("common.zig"); | |
| 4 | const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; | |
| 4 | 5 | |
| 5 | 6 | pub const panic = common.panic; |
| 6 | 7 | |
| ... | ... | @@ -8,6 +9,7 @@ comptime { |
| 8 | 9 | @export(&__floatuneixf, .{ .name = "__floatuneixf", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 10 | } |
| 10 | 11 | |
| 11 | pub fn __floatuneixf(a: [*]const u32, bits: usize) callconv(.c) f80 { | |
| 12 | return floatFromBigInt(f80, .unsigned, a[0 .. divCeil(usize, bits, 32) catch unreachable]); | |
| 12 | pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 { | |
| 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 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const testing = std.testing; |
| 4 | 3 | const math = std.math; |
| 5 | const endian = builtin.cpu.arch.endian(); | |
| 6 | 4 | |
| 7 | 5 | const __fixunshfti = @import("fixunshfti.zig").__fixunshfti; |
| 8 | 6 | const __fixunsxfti = @import("fixunsxfti.zig").__fixunsxfti; |
| ... | ... | @@ -350,14 +348,12 @@ test "fixunssfti" { |
| 350 | 348 | |
| 351 | 349 | fn test_fixsfei(comptime T: type, expected: T, a: f32) !void { |
| 352 | 350 | const int = @typeInfo(T).int; |
| 353 | var expected_buf: [@divExact(int.bits, 32)]u32 = undefined; | |
| 354 | std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian); | |
| 355 | var actual_buf: [@divExact(int.bits, 32)]u32 = undefined; | |
| 351 | var actual: T = undefined; | |
| 356 | 352 | _ = switch (int.signedness) { |
| 357 | 353 | .signed => __fixsfei, |
| 358 | 354 | .unsigned => __fixunssfei, |
| 359 | }(&actual_buf, int.bits, a); | |
| 360 | try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf)); | |
| 355 | }(@ptrCast(&actual), int.bits, a); | |
| 356 | try testing.expect(expected == actual); | |
| 361 | 357 | } |
| 362 | 358 | |
| 363 | 359 | test "fixsfei" { |
| ... | ... | @@ -685,14 +681,12 @@ test "fixunsdfti" { |
| 685 | 681 | |
| 686 | 682 | fn test_fixdfei(comptime T: type, expected: T, a: f64) !void { |
| 687 | 683 | const int = @typeInfo(T).int; |
| 688 | var expected_buf: [@divExact(int.bits, 32)]u32 = undefined; | |
| 689 | std.mem.writeInt(T, std.mem.asBytes(&expected_buf), expected, endian); | |
| 690 | var actual_buf: [@divExact(int.bits, 32)]u32 = undefined; | |
| 684 | var actual: T = undefined; | |
| 691 | 685 | _ = switch (int.signedness) { |
| 692 | 686 | .signed => __fixdfei, |
| 693 | 687 | .unsigned => __fixunsdfei, |
| 694 | }(&actual_buf, int.bits, a); | |
| 695 | try testing.expect(std.mem.eql(u32, &expected_buf, &actual_buf)); | |
| 688 | }(@ptrCast(&actual), int.bits, a); | |
| 689 | try testing.expect(expected == actual); | |
| 696 | 690 | } |
| 697 | 691 | |
| 698 | 692 | test "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 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void { | |
| 115 | pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void { | |
| 116 | 116 | @setRuntimeSafety(builtin.is_test); |
| 117 | const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 118 | const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 119 | const q = r_q[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 117 | const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits)); | |
| 118 | const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size])); | |
| 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 | 121 | @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable; |
| 121 | 122 | } |
| 122 | 123 | |
| 123 | pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) callconv(.c) void { | |
| 124 | pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void { | |
| 124 | 125 | @setRuntimeSafety(builtin.is_test); |
| 125 | const u = u_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 126 | const v = v_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 127 | const r = r_p[0 .. std.math.divCeil(usize, bits, 32) catch unreachable]; | |
| 126 | const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits)); | |
| 127 | const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size])); | |
| 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 | 130 | @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable; |
| 129 | 131 | } |
| 130 | 132 |