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