History

Fix pointer difference issue in aarch64/riscv64

When calculating the difference between two pointers (TOK_PDIV), the AArch64 and RISC-V64 backends used unsigned division instructions (udiv/divu). This patch moves TOK_PDIV to use signed division instructions (sdiv/div) for both backends, ensuring correct behavior as per the C standard.

Dylan Fei committed 10 months ago

Commit 11118be1 parent 5a370d82 files · +2 −2Browse files

Unified · Split

2 files
  1. arm64-gen.c +1 −1
  2. riscv64-gen.c +1 −1
arm64-gen.c+1−1
@@ -1756,6 +1756,7 @@ static void arm64_gen_opil(int op, uint32_t l) · 1755 unmodified lines
17561756 o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
17571757 break;
17581758 case '/':
1759+ case TOK_PDIV:
17591760 o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
17601761 break;
17611762 case '^':
@@ -1798,7 +1799,6 @@ static void arm64_gen_opil(int op, uint32_t l) · 36 unmodified lines
17981799 o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
17991800 break;
18001801 case TOK_UDIV:
1801− case TOK_PDIV:
18021802 o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
18031803 break;
18041804 case TOK_UGE:
riscv64-gen.c+1−1
@@ -1110,6 +1110,7 @@ static void gen_opil(int op, int ll) · 1109 unmodified lines
11101110 ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b
11111111 break;
11121112 case '/':
1113+ case TOK_PDIV:
11131114 ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b
11141115 break;
11151116 case '&':
@@ -1127,7 +1128,6 @@ static void gen_opil(int op, int ll) · 11 unmodified lines
11271128 case TOK_UMOD:
11281129 ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b
11291130 break;
1130− case TOK_PDIV:
11311131 case TOK_UDIV:
11321132 ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b
11331133 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t