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
1756 o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub1756 o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
1757 break;1757 break;
1758 case '/':1758 case '/':
1759 case TOK_PDIV:
1759 o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv1760 o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
1760 break;1761 break;
1761 case '^':1762 case '^':
@@ -1798,7 +1799,6 @@ static void arm64_gen_opil(int op, uint32_t l) · 36 unmodified lines
1798 o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr1799 o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
1799 break;1800 break;
1800 case TOK_UDIV:1801 case TOK_UDIV:
1801 case TOK_PDIV:
1802 o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv1802 o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
1803 break;1803 break;
1804 case TOK_UGE:1804 case TOK_UGE:
riscv64-gen.c+1−1
@@ -1110,6 +1110,7 @@ static void gen_opil(int op, int ll) · 1109 unmodified lines
1110 ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b1110 ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b
1111 break;1111 break;
1112 case '/':1112 case '/':
1113 case TOK_PDIV:
1113 ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b1114 ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b
1114 break;1115 break;
1115 case '&':1116 case '&':
@@ -1127,7 +1128,6 @@ static void gen_opil(int op, int ll) · 11 unmodified lines
1127 case TOK_UMOD:1128 case TOK_UMOD:
1128 ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b1129 ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b
1129 break;1130 break;
1130 case TOK_PDIV:
1131 case TOK_UDIV:1131 case TOK_UDIV:
1132 ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b1132 ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b
1133 break;1133 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