| ... | ... | @@ -5,42 +5,41 @@ const Register = bits.Register; |
| 5 | 5 | const RegisterManagerFn = @import("../../register_manager.zig").RegisterManager; |
| 6 | 6 | const Type = @import("../../type.zig").Type; |
| 7 | 7 | |
| 8 | | pub const Class = enum(u8) { memory, integer, none, float_array, _ }; |
| 8 | pub const Class = union(enum) { memory, integer, double_integer, none, float_array: u8 }; |
| 9 | 9 | |
| 10 | 10 | /// For `float_array` the second element will be the amount of floats. |
| 11 | | pub fn classifyType(ty: Type, target: std.Target) [2]Class { |
| 12 | | if (!ty.hasRuntimeBitsIgnoreComptime()) return .{ .none, .none }; |
| 11 | pub fn classifyType(ty: Type, target: std.Target) Class { |
| 12 | if (!ty.hasRuntimeBitsIgnoreComptime()) return .none; |
| 13 | 13 | var maybe_float_bits: ?u16 = null; |
| 14 | 14 | switch (ty.zigTypeTag()) { |
| 15 | 15 | .Struct => { |
| 16 | | if (ty.containerLayout() == .Packed) return .{ .integer, .none }; |
| 16 | if (ty.containerLayout() == .Packed) return .integer; |
| 17 | 17 | const float_count = countFloats(ty, target, &maybe_float_bits); |
| 18 | | if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) }; |
| 18 | if (float_count <= sret_float_count) return .{ .float_array = float_count }; |
| 19 | 19 | |
| 20 | 20 | const bit_size = ty.bitSize(target); |
| 21 | | if (bit_size > 128) return .{ .memory, .none }; |
| 22 | | if (bit_size > 64) return .{ .integer, .integer }; |
| 23 | | return .{ .integer, .none }; |
| 21 | if (bit_size > 128) return .memory; |
| 22 | if (bit_size > 64) return .double_integer; |
| 23 | return .integer; |
| 24 | 24 | }, |
| 25 | 25 | .Union => { |
| 26 | | if (ty.containerLayout() == .Packed) return .{ .integer, .none }; |
| 26 | if (ty.containerLayout() == .Packed) return .integer; |
| 27 | 27 | const float_count = countFloats(ty, target, &maybe_float_bits); |
| 28 | | if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) }; |
| 28 | if (float_count <= sret_float_count) return .{ .float_array = float_count }; |
| 29 | 29 | |
| 30 | 30 | const bit_size = ty.bitSize(target); |
| 31 | | if (bit_size > 128) return .{ .memory, .none }; |
| 32 | | if (bit_size > 64) return .{ .integer, .integer }; |
| 33 | | return .{ .integer, .none }; |
| 31 | if (bit_size > 128) return .memory; |
| 32 | if (bit_size > 64) return .double_integer; |
| 33 | return .integer; |
| 34 | 34 | }, |
| 35 | | .Int, .Enum, .ErrorSet, .Vector, .Float, .Bool => return .{ .integer, .none }, |
| 36 | | .Array => return .{ .memory, .none }, |
| 35 | .Int, .Enum, .ErrorSet, .Vector, .Float, .Bool => return .integer, |
| 37 | 36 | .Optional => { |
| 38 | 37 | std.debug.assert(ty.isPtrLikeOptional()); |
| 39 | | return .{ .integer, .none }; |
| 38 | return .integer; |
| 40 | 39 | }, |
| 41 | 40 | .Pointer => { |
| 42 | 41 | std.debug.assert(!ty.isSlice()); |
| 43 | | return .{ .integer, .none }; |
| 42 | return .integer; |
| 44 | 43 | }, |
| 45 | 44 | .ErrorUnion, |
| 46 | 45 | .Frame, |
| ... | ... | @@ -56,17 +55,18 @@ pub fn classifyType(ty: Type, target: std.Target) [2]Class { |
| 56 | 55 | .Fn, |
| 57 | 56 | .Opaque, |
| 58 | 57 | .EnumLiteral, |
| 58 | .Array, |
| 59 | 59 | => unreachable, |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | const sret_float_count = 4; |
| 64 | | fn countFloats(ty: Type, target: std.Target, maybe_float_bits: *?u16) u32 { |
| 65 | | const invalid = std.math.maxInt(u32); |
| 64 | fn countFloats(ty: Type, target: std.Target, maybe_float_bits: *?u16) u8 { |
| 65 | const invalid = std.math.maxInt(u8); |
| 66 | 66 | switch (ty.zigTypeTag()) { |
| 67 | 67 | .Union => { |
| 68 | 68 | const fields = ty.unionFields(); |
| 69 | | var max_count: u32 = 0; |
| 69 | var max_count: u8 = 0; |
| 70 | 70 | for (fields.values()) |field| { |
| 71 | 71 | const field_count = countFloats(field.ty, target, maybe_float_bits); |
| 72 | 72 | if (field_count == invalid) return invalid; |
| ... | ... | @@ -77,7 +77,7 @@ fn countFloats(ty: Type, target: std.Target, maybe_float_bits: *?u16) u32 { |
| 77 | 77 | }, |
| 78 | 78 | .Struct => { |
| 79 | 79 | const fields_len = ty.structFieldCount(); |
| 80 | | var count: u32 = 0; |
| 80 | var count: u8 = 0; |
| 81 | 81 | var i: u32 = 0; |
| 82 | 82 | while (i < fields_len) : (i += 1) { |
| 83 | 83 | const field_ty = ty.structFieldType(i); |