authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 17:51:54+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 17:51:54+03:00
log76220781279a2dc42572b7819a834aebb85eb354
tree8d75386c37c0d09f33948d3c9fef0c2ee85d0759
parent972c39e2c00c487a483bad002ef33ca1a5c21d02

aarc64 C ABI: fix handling of packed structs and unions

* Packed unions were not handled at all previously. * Packed unions and structs are integers so their floats should not be counted.

1 files changed, 8 insertions(+), 7 deletions(-)

src/arch/aarch64/abi.zig+8-7
...@@ -9,23 +9,24 @@ pub const Class = enum(u8) { memory, integer, none, float_array, _ };...@@ -9,23 +9,24 @@ pub const Class = enum(u8) { memory, integer, none, float_array, _ };
99
10/// For `float_array` the second element will be the amount of floats.10/// For `float_array` the second element will be the amount of floats.
11pub fn classifyType(ty: Type, target: std.Target) [2]Class {11pub fn classifyType(ty: Type, target: std.Target) [2]Class {
12 var maybe_float_bits: ?u16 = null;
13 const float_count = countFloats(ty, target, &maybe_float_bits);
14 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
15 return classifyTypeInner(ty, target);
16}
17
18fn classifyTypeInner(ty: Type, target: std.Target) [2]Class {
19 if (!ty.hasRuntimeBitsIgnoreComptime()) return .{ .none, .none };12 if (!ty.hasRuntimeBitsIgnoreComptime()) return .{ .none, .none };
13 var maybe_float_bits: ?u16 = null;
20 switch (ty.zigTypeTag()) {14 switch (ty.zigTypeTag()) {
21 .Struct => {15 .Struct => {
22 if (ty.containerLayout() == .Packed) return .{ .integer, .none };16 if (ty.containerLayout() == .Packed) return .{ .integer, .none };
17 const float_count = countFloats(ty, target, &maybe_float_bits);
18 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
19
23 const bit_size = ty.bitSize(target);20 const bit_size = ty.bitSize(target);
24 if (bit_size > 128) return .{ .memory, .none };21 if (bit_size > 128) return .{ .memory, .none };
25 if (bit_size > 64) return .{ .integer, .integer };22 if (bit_size > 64) return .{ .integer, .integer };
26 return .{ .integer, .none };23 return .{ .integer, .none };
27 },24 },
28 .Union => {25 .Union => {
26 if (ty.containerLayout() == .Packed) return .{ .integer, .none };
27 const float_count = countFloats(ty, target, &maybe_float_bits);
28 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
29
29 const bit_size = ty.bitSize(target);30 const bit_size = ty.bitSize(target);
30 if (bit_size > 128) return .{ .memory, .none };31 if (bit_size > 128) return .{ .memory, .none };
31 if (bit_size > 64) return .{ .integer, .integer };32 if (bit_size > 64) return .{ .integer, .integer };