diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-10 17:36:31 -0700 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-02-12 11:18:23 +0100 |
| commit | 166db1a3ed7eca9b04b0626eaea8de0634ab9667 (patch) | |
| tree | 958a97baa486eda299dc268a83f3e89fd9a81f63 /src/value.zig | |
| parent | f293fbbeaf6c48e6ce1410743181f89f359eb697 (diff) | |
| download | zig-166db1a3ed7eca9b04b0626eaea8de0634ab9667.tar.gz zig-166db1a3ed7eca9b04b0626eaea8de0634ab9667.zip | |
stage1: fix f80 size and alignment on x86 and arm
* F80Repr extern struct needs no explicit padding; let's match the
target padding.
* stage2: fix lowering of f80 constants.
* stage1: decide ABI size and alignment of f80 based on alignment of
u64. x86 has alignof u64 equal to 4 but arm has it as 8.
* stage2: fix Value.floatReadFromMemory to use F80Repr
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/value.zig b/src/value.zig index 33a75e08bb..aefb0a3e20 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1122,10 +1122,32 @@ pub const Value = extern union { fn floatReadFromMemory(comptime F: type, target: Target, buffer: []const u8) F { if (F == f80) { - // TODO: use std.math.F80Repr? - const int = std.mem.readInt(u128, buffer[0..16], target.cpu.arch.endian()); - // TODO shouldn't this be a bitcast from u80 to f80 instead of u128 to f80? - return @bitCast(F, int); + switch (target.cpu.arch.endian()) { + .Little => { + const TargetF80Repr = extern struct { + fraction: u64, + exp: u16, + }; + const target_repr = @ptrCast(*align(1) const TargetF80Repr, buffer.ptr); + const real_repr: std.math.F80Repr = .{ + .fraction = target_repr.fraction, + .exp = target_repr.exp, + }; + return @ptrCast(*const f80, &real_repr).*; + }, + .Big => { + const TargetF80Repr = extern struct { + exp: u16, + fraction: u64, + }; + const target_repr = @ptrCast(*align(1) const TargetF80Repr, buffer.ptr); + const real_repr: std.math.F80Repr = .{ + .fraction = target_repr.fraction, + .exp = target_repr.exp, + }; + return @ptrCast(*const f80, &real_repr).*; + }, + } } const Int = @Type(.{ .Int = .{ .signedness = .unsigned, |
