diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-13 13:14:37 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-13 13:14:37 -0700 |
| commit | 92bc3cbe27792be0300fb5f104c011a11f3cf40f (patch) | |
| tree | 8d9e7f2df29a824d104cfa01d2eb832d456554aa /src/value.zig | |
| parent | 35e70111248f795fbdcefd5ae0d6fc494d1b0683 (diff) | |
| download | zig-92bc3cbe27792be0300fb5f104c011a11f3cf40f.tar.gz zig-92bc3cbe27792be0300fb5f104c011a11f3cf40f.zip | |
stage2: fix comptime bitcast involving f80
* Sema: implement comptime bitcast of f80 with integer-like types
bitwise rather than taking a round trip through memory layout.
* Type: introduce `isAbiInt`.
* Value: comptime memory write of f80 writes 0 bytes for padding
instead of leaving the memory uninitialized.
* Value: floatReadFromMemory has a more general implementation, checking
the endianness rather than checking for specific architectures.
This fixes behavior test failures occurring on MIPS.
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/value.zig b/src/value.zig index 04999c778a..b52e67e31c 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1468,8 +1468,7 @@ pub const Value = extern union { const repr = std.math.break_f80(f); std.mem.writeInt(u64, buffer[0..8], repr.fraction, endian); std.mem.writeInt(u16, buffer[8..10], repr.exp, endian); - // TODO set the rest of the bytes to undefined. should we use 0xaa - // or is there a different way? + std.mem.set(u8, buffer[10..], 0); return; } const Int = @Type(.{ .Int = .{ @@ -1481,20 +1480,18 @@ pub const Value = extern union { } fn floatReadFromMemory(comptime F: type, target: Target, buffer: []const u8) F { + const endian = target.cpu.arch.endian(); if (F == f80) { - switch (target.cpu.arch) { - .i386, .x86_64 => return std.math.make_f80(.{ - .fraction = std.mem.readIntLittle(u64, buffer[0..8]), - .exp = std.mem.readIntLittle(u16, buffer[8..10]), - }), - else => {}, - } + return std.math.make_f80(.{ + .fraction = readInt(u64, buffer[0..8], endian), + .exp = readInt(u16, buffer[8..10], endian), + }); } const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @typeInfo(F).Float.bits, } }); - const int = readInt(Int, buffer[0..@sizeOf(Int)], target.cpu.arch.endian()); + const int = readInt(Int, buffer[0..@sizeOf(Int)], endian); return @bitCast(F, int); } |
