| ... | @@ -990,44 +990,44 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 | ... | @@ -990,44 +990,44 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32 |
| 990 | return result; | 990 | return result; |
| 991 | } | 991 | } |
| 992 | | 992 | |
| 993 | /// Using a given `Type`, returns the corresponding type | 993 | /// Using a given `Type`, returns the corresponding valtype for .auto callconv |
| 994 | fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype { | 994 | fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype { |
| 995 | const mod = pt.zcu; | 995 | const mod = pt.zcu; |
| 996 | const target = mod.getTarget(); | 996 | const target = mod.getTarget(); |
| 997 | const ip = &mod.intern_pool; | 997 | const ip = &mod.intern_pool; |
| 998 | return switch (ty.zigTypeTag(mod)) { | 998 | return switch (ty.zigTypeTag(mod)) { |
| 999 | .Float => switch (ty.floatBits(target)) { | 999 | .Float => switch (ty.floatBits(target)) { |
| 1000 | 16 => wasm.Valtype.i32, // stored/loaded as u16 | 1000 | 16 => .i32, // stored/loaded as u16 |
| 1001 | 32 => wasm.Valtype.f32, | 1001 | 32 => .f32, |
| 1002 | 64 => wasm.Valtype.f64, | 1002 | 64 => .f64, |
| 1003 | 80, 128 => wasm.Valtype.i64, | 1003 | 80, 128 => .i32, |
| 1004 | else => unreachable, | 1004 | else => unreachable, |
| 1005 | }, | 1005 | }, |
| 1006 | .Int, .Enum => blk: { | 1006 | .Int, .Enum => switch (ty.intInfo(pt.zcu).bits) { |
| 1007 | const info = ty.intInfo(pt.zcu); | 1007 | 0...32 => .i32, |
| 1008 | if (info.bits <= 32) break :blk wasm.Valtype.i32; | 1008 | 33...64 => .i64, |
| 1009 | if (info.bits > 32 and info.bits <= 128) break :blk wasm.Valtype.i64; | 1009 | else => .i32, |
| 1010 | break :blk wasm.Valtype.i32; // represented as pointer to stack | | |
| 1011 | }, | 1010 | }, |
| 1012 | .Struct => { | 1011 | .Struct => blk: { |
| 1013 | if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| { | 1012 | if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| { |
| 1014 | return typeToValtype(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt); | 1013 | const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)); |
| | 1014 | break :blk typeToValtype(backing_int_ty, pt); |
| 1015 | } else { | 1015 | } else { |
| 1016 | return wasm.Valtype.i32; | 1016 | break :blk .i32; |
| 1017 | } | 1017 | } |
| 1018 | }, | 1018 | }, |
| 1019 | .Vector => switch (determineSimdStoreStrategy(ty, pt)) { | 1019 | .Vector => switch (determineSimdStoreStrategy(ty, pt)) { |
| 1020 | .direct => wasm.Valtype.v128, | 1020 | .direct => .v128, |
| 1021 | .unrolled => wasm.Valtype.i32, | 1021 | .unrolled => .i32, |
| 1022 | }, | 1022 | }, |
| 1023 | .Union => switch (ty.containerLayout(pt.zcu)) { | 1023 | .Union => switch (ty.containerLayout(pt.zcu)) { |
| 1024 | .@"packed" => { | 1024 | .@"packed" => blk: { |
| 1025 | const int_ty = pt.intType(.unsigned, @as(u16, @intCast(ty.bitSize(pt)))) catch @panic("out of memory"); | 1025 | const int_ty = pt.intType(.unsigned, @as(u16, @intCast(ty.bitSize(pt)))) catch @panic("out of memory"); |
| 1026 | return typeToValtype(int_ty, pt); | 1026 | break :blk typeToValtype(int_ty, pt); |
| 1027 | }, | 1027 | }, |
| 1028 | else => wasm.Valtype.i32, | 1028 | else => .i32, |
| 1029 | }, | 1029 | }, |
| 1030 | else => wasm.Valtype.i32, // all represented as reference/immediate | 1030 | else => .i32, // all represented as reference/immediate |
| 1031 | }; | 1031 | }; |
| 1032 | } | 1032 | } |
| 1033 | | 1033 | |
| ... | @@ -1180,20 +1180,20 @@ fn genFunctype( | ... | @@ -1180,20 +1180,20 @@ fn genFunctype( |
| 1180 | switch (cc) { | 1180 | switch (cc) { |
| 1181 | .C => { | 1181 | .C => { |
| 1182 | const param_classes = abi.classifyType(param_type, pt); | 1182 | const param_classes = abi.classifyType(param_type, pt); |
| 1183 | for (param_classes) |class| { | 1183 | if (param_classes[1] == .none) { |
| 1184 | if (class == .none) continue; | 1184 | if (param_classes[0] == .direct) { |
| 1185 | if (class == .direct) { | | |
| 1186 | const scalar_type = abi.scalarType(param_type, pt); | 1185 | const scalar_type = abi.scalarType(param_type, pt); |
| 1187 | try temp_params.append(typeToValtype(scalar_type, pt)); | 1186 | try temp_params.append(typeToValtype(scalar_type, pt)); |
| 1188 | } else { | 1187 | } else { |
| 1189 | try temp_params.append(typeToValtype(param_type, pt)); | 1188 | try temp_params.append(typeToValtype(param_type, pt)); |
| 1190 | } | 1189 | } |
| | 1190 | } else { |
| | 1191 | // i128/f128 |
| | 1192 | try temp_params.append(.i64); |
| | 1193 | try temp_params.append(.i64); |
| 1191 | } | 1194 | } |
| 1192 | }, | 1195 | }, |
| 1193 | else => if (isByRef(param_type, pt)) | 1196 | else => try temp_params.append(typeToValtype(param_type, pt)), |
| 1194 | try temp_params.append(.i32) | | |
| 1195 | else | | |
| 1196 | try temp_params.append(typeToValtype(param_type, pt)), | | |
| 1197 | } | 1197 | } |
| 1198 | } | 1198 | } |
| 1199 | | 1199 | |