[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.0.2 10/22] tcg/loongarch64: Fix tcg_out_movi vs some pcrel poi
From: |
Michael Tokarev |
Subject: |
[Stable-9.0.2 10/22] tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers |
Date: |
Fri, 5 Jul 2024 00:00:40 +0300 |
From: Richard Henderson <richard.henderson@linaro.org>
Simplify the logic for two-part, 32-bit pc-relative addresses.
Rather than assume all such fit in int32_t, do some arithmetic
and assert a result, do some arithmetic first and then check
to see if the pieces are in range.
Cc: qemu-stable@nongnu.org
Fixes: dacc51720db ("tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi")
Reviewed-by: Song Gao <gaosong@loongson.cn>
Reported-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit 521d7fb3ebdf88112ed13556a93e3037742b9eb8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
index 06ca1ab11c..8f68bd3e51 100644
--- a/tcg/loongarch64/tcg-target.c.inc
+++ b/tcg/loongarch64/tcg-target.c.inc
@@ -366,8 +366,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type,
TCGReg rd,
* back to the slow path.
*/
- intptr_t pc_offset;
- tcg_target_long val_lo, val_hi, pc_hi, offset_hi;
+ intptr_t src_rx, pc_offset;
tcg_target_long hi12, hi32, hi52;
/* Value fits in signed i32. */
@@ -377,24 +376,23 @@ static void tcg_out_movi(TCGContext *s, TCGType type,
TCGReg rd,
}
/* PC-relative cases. */
- pc_offset = tcg_pcrel_diff(s, (void *)val);
- if (pc_offset == sextreg(pc_offset, 0, 22) && (pc_offset & 3) == 0) {
- /* Single pcaddu2i. */
- tcg_out_opc_pcaddu2i(s, rd, pc_offset >> 2);
- return;
+ src_rx = (intptr_t)tcg_splitwx_to_rx(s->code_ptr);
+ if ((val & 3) == 0) {
+ pc_offset = val - src_rx;
+ if (pc_offset == sextreg(pc_offset, 0, 22)) {
+ /* Single pcaddu2i. */
+ tcg_out_opc_pcaddu2i(s, rd, pc_offset >> 2);
+ return;
+ }
}
- if (pc_offset == (int32_t)pc_offset) {
- /* Offset within 32 bits; load with pcalau12i + ori. */
- val_lo = sextreg(val, 0, 12);
- val_hi = val >> 12;
- pc_hi = (val - pc_offset) >> 12;
- offset_hi = val_hi - pc_hi;
-
- tcg_debug_assert(offset_hi == sextreg(offset_hi, 0, 20));
- tcg_out_opc_pcalau12i(s, rd, offset_hi);
+ pc_offset = (val >> 12) - (src_rx >> 12);
+ if (pc_offset == sextreg(pc_offset, 0, 20)) {
+ /* Load with pcalau12i + ori. */
+ tcg_target_long val_lo = val & 0xfff;
+ tcg_out_opc_pcalau12i(s, rd, pc_offset);
if (val_lo != 0) {
- tcg_out_opc_ori(s, rd, rd, val_lo & 0xfff);
+ tcg_out_opc_ori(s, rd, rd, val_lo);
}
return;
}
--
2.39.2
- [Stable-9.0.2 00/22] Patch Round-up for stable 9.0.2, freeze on 2024-07-14, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 01/22] target/i386: fix size of EBP writeback in gen_enter(), Michael Tokarev, 2024/07/04
- [Stable-9.0.2 02/22] virtio-net: drop too short packets early, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 04/22] Revert "monitor: use aio_co_reschedule_self()", Michael Tokarev, 2024/07/04
- [Stable-9.0.2 03/22] ui/gtk: Draw guest frame at refresh cycle, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 06/22] stdvga: fix screen blanking, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 07/22] accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 05/22] hw/audio/virtio-snd: Always use little endian audio format, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 08/22] linux-user: Make TARGET_NR_setgroups affect only the current thread, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 09/22] target/sparc: use signed denominator in sdiv helper, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 10/22] tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers,
Michael Tokarev <=
- [Stable-9.0.2 12/22] tests: Update our CI to use CentOS Stream 9 instead of 8, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 11/22] migration: Fix file migration with fdset, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 14/22] target/arm: Fix VCMLA Dd, Dn, Dm[idx], Michael Tokarev, 2024/07/04
- [Stable-9.0.2 13/22] i386/cpu: fixup number of addressable IDs for processor cores in the physical package, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 15/22] target/arm: Fix FJCVTZS vs flush-to-zero, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 19/22] iotests/244: Don't store data-file with protocol in image, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 18/22] qcow2: Don't open data_file with BDRV_O_NO_IO, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 16/22] hw/core: allow parameter=1 for SMP topology on any machine, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 17/22] tests: add testing of parameter=1 for SMP topology, Michael Tokarev, 2024/07/04
- [Stable-9.0.2 20/22] iotests/270: Don't store data-file with json: prefix in image, Michael Tokarev, 2024/07/04