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.
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user