diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-04-28 01:56:45 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-01 19:22:52 -0400 |
| commit | db76ae82607b941373064b05a348950802a21217 (patch) | |
| tree | 45839e9e12480ccc343e76d432cf3df4eb281f78 /src/codegen.zig | |
| parent | 1fd48815c6e22b266b318f58c6b3c828b20ace80 (diff) | |
| download | zig-db76ae82607b941373064b05a348950802a21217.tar.gz zig-db76ae82607b941373064b05a348950802a21217.zip | |
x86_64: fix emitting f80 globals
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 0043b38a5b..f967566034 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -91,12 +91,10 @@ pub fn generateFunction( fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian, code: []u8) void { _ = target; - const Int = @Type(.{ .Int = .{ - .signedness = .unsigned, - .bits = @typeInfo(F).Float.bits, - } }); + const bits = @typeInfo(F).Float.bits; + const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } }); const int = @bitCast(Int, f); - mem.writeInt(Int, code[0..@sizeOf(Int)], int, endian); + mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian); } pub fn generateLazySymbol( @@ -187,18 +185,14 @@ pub fn generateSymbol( }; }, .Float => { - const float_bits = typed_value.ty.floatBits(target); - switch (float_bits) { + switch (typed_value.ty.floatBits(target)) { 16 => writeFloat(f16, typed_value.val.toFloat(f16), target, endian, try code.addManyAsArray(2)), 32 => writeFloat(f32, typed_value.val.toFloat(f32), target, endian, try code.addManyAsArray(4)), 64 => writeFloat(f64, typed_value.val.toFloat(f64), target, endian, try code.addManyAsArray(8)), - 80 => return Result{ - .fail = try ErrorMsg.create( - bin_file.allocator, - src_loc, - "TODO handle f80 in generateSymbol", - .{}, - ), + 80 => { + writeFloat(f80, typed_value.val.toFloat(f80), target, endian, try code.addManyAsArray(10)); + const abi_size = math.cast(usize, typed_value.ty.abiSize(target)) orelse return error.Overflow; + try code.appendNTimes(0, abi_size - 10); }, 128 => writeFloat(f128, typed_value.val.toFloat(f128), target, endian, try code.addManyAsArray(16)), else => unreachable, |
