qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 09/30] tcg/loongarch64: Implement tcg_out_mov and tcg_out_


From: Richard Henderson
Subject: Re: [PATCH v2 09/30] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi
Date: Tue, 21 Sep 2021 21:25:10 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 9/21/21 1:18 PM, WANG Xuerui wrote:
+    /* Test for PC-relative values that can be loaded faster.  */
+    intptr_t pc_offset = val - (uintptr_t)s->code_ptr;

This isn't quite right for split r^x code buffer.
You should have seen this with --enable-debug-tcg...

You need pc_offset = tcg_pcrel_diff(s, (void *)val).

+    if (pc_offset == (int32_t)pc_offset) {
+        tcg_target_long lo = sextreg(pc_offset, 0, 12);
+        tcg_target_long hi = pc_offset - lo;
+        tcg_out_opc_pcaddu12i(s, rd, hi >> 12);

And... this doesn't quite work, right at the edges. If lo is negative, hi can overflow out of range. There are a number of ways to fix this. One is to extract the pieces and re-assemble to see if it matches. Another is to rearrange the arithmetic just a little and use PCALAU12I.

+    tcg_target_long upper = (val >> 12) & 0xfffff;
+    tcg_target_long higher = (val >> 32) & 0xfffff;

Better to use extract64(val, 12, 20) and extract64(val, 32, 30).


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]