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...@@ -6540,7 +6540,28 @@ fn moveConstant(isel: *Select, dst: Value.Location, init_constant: Constant, ini
6540 }6540 }
6541 },6541 },
6542 .enum_tag => |enum_tag| continue :constant_key .{ .int = ip.indexToKey(enum_tag.int).int },6542 .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 },
6544 .ptr => |ptr| {6565 .ptr => |ptr| {
6545 assert(offset == 0 and size == isel.gprSize());6566 assert(offset == 0 and size == isel.gprSize());
6546 const dst_ra: Register.Alias, const use_tmp_reg = select_tmp: {6567 const dst_ra: Register.Alias, const use_tmp_reg = select_tmp: {
...@@ -7390,7 +7411,7 @@ fn gprAlignment(isel: *Select) std.mem.Alignment {...@@ -7390,7 +7411,7 @@ fn gprAlignment(isel: *Select) std.mem.Alignment {
7390 };7411 };
7391}7412}
73927413
7393fn fprBits(isel: *Select) u7 {7414fn targetFprBits(isel: *Select) u7 {
7394 const cpu = &isel.target.cpu;7415 const cpu = &isel.target.cpu;
7395 if (cpu.has(.loongarch, .d)) {7416 if (cpu.has(.loongarch, .d)) {
7396 return 64;7417 return 64;
...@@ -7408,12 +7429,12 @@ fn vectorBits(isel: *Select) u7 {...@@ -7408,12 +7429,12 @@ fn vectorBits(isel: *Select) u7 {
7408 } else if (cpu.has(.loongarch, .lsx)) {7429 } else if (cpu.has(.loongarch, .lsx)) {
7409 return 128;7430 return 128;
7410 } else {7431 } else {
7411 return isel.fprBits();7432 return isel.targetFprBits();
7412 }7433 }
7413}7434}
74147435
7415fn canUseFprForFloat(isel: *Select, bits: u16) bool {7436fn canUseFprForFloat(isel: *Select, bits: u16) bool {
7416 return bits <= isel.fprBits();7437 return bits <= isel.targetFprBits();
7417}7438}
74187439
7419fn typeOfField(isel: *Select, ty: ZigType, offset: u64) ?ZigType {7440fn typeOfField(isel: *Select, ty: ZigType, offset: u64) ?ZigType {