[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~
- [PATCH v2 01/30] elf: Add machine type value for LoongArch, (continued)
- [PATCH v2 01/30] elf: Add machine type value for LoongArch, WANG Xuerui, 2021/09/21
- [PATCH v2 02/30] MAINTAINERS: Add tcg/loongarch64 entry with myself as maintainer, WANG Xuerui, 2021/09/21
- [PATCH v2 07/30] tcg/loongarch64: Implement necessary relocation operations, WANG Xuerui, 2021/09/21
- [PATCH v2 06/30] tcg/loongarch64: Define the operand constraints, WANG Xuerui, 2021/09/21
- [PATCH v2 03/30] tcg/loongarch64: Add the tcg-target.h file, WANG Xuerui, 2021/09/21
- [PATCH v2 09/30] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi, WANG Xuerui, 2021/09/21
- Re: [PATCH v2 09/30] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi,
Richard Henderson <=
[PATCH v2 04/30] tcg/loongarch64: Add generated instruction opcodes and encoding helpers, WANG Xuerui, 2021/09/21
[PATCH v2 08/30] tcg/loongarch64: Implement the memory barrier op, WANG Xuerui, 2021/09/21
[PATCH v2 05/30] tcg/loongarch64: Add register names, allocation order and input/output sets, WANG Xuerui, 2021/09/21
[PATCH v2 10/30] tcg/loongarch64: Implement goto_ptr, WANG Xuerui, 2021/09/21
[PATCH v2 12/30] tcg/loongarch64: Implement not/and/or/xor/nor/andc/orc/eqv ops, WANG Xuerui, 2021/09/21