authorgravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2026-10-16 15:59:19+08:00
committergravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2026-10-17 10:27:04+08:00
log557a4cdc3af6cab7ba3390b1f057bb8f6f8cdcef
treedc3111538a1ac44eec83c9d4e58fe1f93c70f782
parent44b107863393eebb23283c1403726b57ed43598a
signature Signed by SSH key SHA256:IEYEjkZlkUTr5U9GiDAmZU/4eZus2t2RsxusyhQqwao

loongarch: implement constant loads for some floats


1 files changed, 25 insertions(+), 4 deletions(-)

src/codegen/loongarch/Select.zig+25-4
......@@ -6540,7 +6540,28 @@ fn moveConstant(isel: *Select, dst: Value.Location, init_constant: Constant, ini
65406540 }
65416541 },
65426542 .enum_tag => |enum_tag| continue :constant_key .{ .int = ip.indexToKey(enum_tag.int).int },
6543 .float => return isel.fail("float unimplemented", .{}),
6543 .float => |float| {
6544 if (isel.canUseFprForFloat(ZigType.fromInterned(float.ty).floatBits(isel.target))) {
6545 return isel.fail("float unimplemented", .{});
6546 } else {
6547 switch (float.ty) {
6548 .f16_type => continue :constant_key .{ .int = .{
6549 .ty = .u16_type,
6550 .storage = .{ .u64 = @as(u16, @bitCast(float.storage.f16)) },
6551 } },
6552 .f32_type => continue :constant_key .{ .int = .{
6553 .ty = .u32_type,
6554 .storage = .{ .u64 = @as(u32, @bitCast(float.storage.f32)) },
6555 } },
6556 .f64_type => continue :constant_key .{ .int = .{
6557 .ty = .u64_type,
6558 .storage = .{ .u64 = @as(u64, @bitCast(float.storage.f64)) },
6559 } },
6560 .f80_type, .f128_type => {},
6561 else => unreachable,
6562 }
6563 }
6564 },
65446565 .ptr => |ptr| {
65456566 assert(offset == 0 and size == isel.gprSize());
65466567 const dst_ra: Register.Alias, const use_tmp_reg = select_tmp: {
......@@ -7390,7 +7411,7 @@ fn gprAlignment(isel: *Select) std.mem.Alignment {
73907411 };
73917412}
73927413
7393fn fprBits(isel: *Select) u7 {
7414fn targetFprBits(isel: *Select) u7 {
73947415 const cpu = &isel.target.cpu;
73957416 if (cpu.has(.loongarch, .d)) {
73967417 return 64;
......@@ -7408,12 +7429,12 @@ fn vectorBits(isel: *Select) u7 {
74087429 } else if (cpu.has(.loongarch, .lsx)) {
74097430 return 128;
74107431 } else {
7411 return isel.fprBits();
7432 return isel.targetFprBits();
74127433 }
74137434}
74147435
74157436fn canUseFprForFloat(isel: *Select, bits: u16) bool {
7416 return bits <= isel.fprBits();
7437 return bits <= isel.targetFprBits();
74177438}
74187439
74197440fn typeOfField(isel: *Select, ty: ZigType, offset: u64) ?ZigType {