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:
Jacob Young
2025-04-11 04:23:36 -04:00
parent ed9aa8f259
commit b31a91bbef
24 changed files with 167 additions and 133 deletions

View File

@@ -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)));
}