authorgravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2026-08-30 21:15:42+08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-30 22:54:04+02:00
logcca7c50b54bbf5d763da839582edff69bd9d051d
tree06d2cca8a02931066ad7ce0b02aa0ec107c6dca0
parentc772fef715c2faec422fb68b69b912780d68762e

loongarch: ABI resolve for f16/f32/f64/f128


1 files changed, 21 insertions(+), 5 deletions(-)

src/codegen/loongarch/Select.zig+21-5
......@@ -3758,7 +3758,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
37583758 } else if (dst_tag == .float and src_tag == .float) {
37593759 assert(dst_ty.floatBits(isel.target) == src_ty.floatBits(isel.target));
37603760 try dst_vi.value.defMove(isel, ty_op.operand);
3761 } else if (dst_ty.isAbiInt(zcu) and src_tag == .float and isel.canUseFprForFloat(src_ty)) {
3761 } else if (dst_ty.isAbiInt(zcu) and src_tag == .float and isel.canUseFprForFloat(src_ty.floatBits(isel.target))) {
37623762 const dst_int_info = dst_ty.intInfo(zcu);
37633763 assert(dst_int_info.bits == src_ty.floatBits(isel.target));
37643764
......@@ -3773,7 +3773,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
37733773 64 => .@"movfr2gr.d"(dst_reg, src_reg),
37743774 });
37753775 try src_mat.finish(isel);
3776 } else if (dst_tag == .float and src_ty.isAbiInt(zcu) and isel.canUseFprForFloat(dst_ty)) {
3776 } else if (dst_tag == .float and src_ty.isAbiInt(zcu) and isel.canUseFprForFloat(dst_ty.floatBits(isel.target))) {
37773777 const src_int_info = src_ty.intInfo(zcu);
37783778 assert(dst_ty.floatBits(isel.target) == src_int_info.bits);
37793779
......@@ -6942,6 +6942,7 @@ pub const CallAbiIterator = struct {
69426942 },
69436943 .simple_type => |simple_type| switch (simple_type) {
69446944 .f80 => continue :type_key .{ .int_type = .{ .signedness = .unsigned, .bits = 80 } },
6945 .f128 => continue :type_key .{ .int_type = .{ .signedness = .unsigned, .bits = 128 } },
69456946 .usize,
69466947 .isize,
69476948 .c_char,
......@@ -6959,7 +6960,22 @@ pub const CallAbiIterator = struct {
69596960 .signedness = .unsigned,
69606961 .bits = zcu.errorSetBits(),
69616962 } },
6962 .f16, .f32, .f64, .f128, .c_longdouble => return isel.fail("CallAbiIterator.resolve({t})", .{simple_type}),
6963 .f16, .f32, .f64 => {
6964 const bits = ty.floatBits(isel.target);
6965 if (isel.canUseFprForFloat(bits)) {
6966 if (it.allocReg(.fpr)) |reg| {
6967 wip_vi.setHintRegister(isel, reg);
6968 if (bits != 16) {
6969 wip_vi.setHintModifier(isel, .fromFloatBits(bits));
6970 } else {
6971 wip_vi.setHintModifier(isel, .floating32);
6972 }
6973 } else it.assignStack(wip_vi);
6974 } else {
6975 continue :type_key .{ .int_type = .{ .signedness = .unsigned, .bits = bits } };
6976 }
6977 },
6978 .c_longdouble => return isel.fail("CallAbiIterator.resolve({t})", .{simple_type}),
69636979 else => return isel.fail("CallAbiIterator.resolve({t})", .{simple_type}),
69646980 },
69656981 .struct_type => {
......@@ -7280,8 +7296,8 @@ fn vectorBits(isel: *Select) u7 {
72807296 }
72817297}
72827298
7283fn canUseFprForFloat(isel: *Select, ty: ZigType) bool {
7284 return ty.floatBits(isel.target) <= isel.fprBits();
7299fn canUseFprForFloat(isel: *Select, bits: u16) bool {
7300 return bits <= isel.fprBits();
72857301}
72867302
72877303fn typeOfField(isel: *Select, ty: ZigType, offset: u64) ?ZigType {