Skip to content

Commit

Permalink
chore(patches): apply the LuaJIT ARM64 LDP/STP fusion fix from LuaJIT (
Browse files Browse the repository at this point in the history
…#11537)

upstream

LuaJIT/LuaJIT@b8c6ccd

KAG-2473

(cherry picked from commit b0ca424)
  • Loading branch information
dndx committed Sep 12, 2023
1 parent f9edf7d commit 0e63ee8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG/unreleased/kong/luajit_ldp_stp_fusion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
message: "Fix incorrect LuaJIT LDP/STP fusion on ARM64 which may sometimes cause incorrect logic"
type: dependency
scope: Core
prs:
jiras:
- "KAG-2473"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From b8c6ccd50c61b7a2df5123ddc5a85ac7d089542b Mon Sep 17 00:00:00 2001
From: Mike Pall <mike>
Date: Sat, 9 Sep 2023 18:01:37 +0200
Subject: [PATCH] ARM64: Fix LDP/STP fusion (again).

Reported and analyzed by Zhongwei Yao. Fix by Peter Cawley. #1075
---
src/lj_emit_arm64.h | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h b/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h
index d4c542557..9161c9582 100644
--- a/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h
+++ b/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h
@@ -113,6 +113,17 @@ static int emit_checkofs(A64Ins ai, int64_t ofs)
}
}

+static LJ_AINLINE uint32_t emit_lso_pair_candidate(A64Ins ai, int ofs, int sc)
+{
+ if (ofs >= 0) {
+ return ai | A64F_U12(ofs>>sc); /* Subsequent lj_ror checks ofs. */
+ } else if (ofs >= -256) {
+ return (ai^A64I_LS_U) | A64F_S9(ofs & 0x1ff);
+ } else {
+ return A64F_D(31); /* Will mismatch prev. */
+ }
+}
+
static void emit_lso(ASMState *as, A64Ins ai, Reg rd, Reg rn, int64_t ofs)
{
int ot = emit_checkofs(ai, ofs), sc = (ai >> 30) & 3;
@@ -124,11 +135,9 @@ static void emit_lso(ASMState *as, A64Ins ai, Reg rd, Reg rn, int64_t ofs)
uint32_t prev = *as->mcp & ~A64F_D(31);
int ofsm = ofs - (1<<sc), ofsp = ofs + (1<<sc);
A64Ins aip;
- if (prev == (ai | A64F_N(rn) | A64F_U12(ofsm>>sc)) ||
- prev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsm&0x1ff))) {
+ if (prev == emit_lso_pair_candidate(ai | A64F_N(rn), ofsm, sc)) {
aip = (A64F_A(rd) | A64F_D(*as->mcp & 31));
- } else if (prev == (ai | A64F_N(rn) | A64F_U12(ofsp>>sc)) ||
- prev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsp&0x1ff))) {
+ } else if (prev == emit_lso_pair_candidate(ai | A64F_N(rn), ofsp, sc)) {
aip = (A64F_D(rd) | A64F_A(*as->mcp & 31));
ofsm = ofs;
} else {

0 comments on commit 0e63ee8

Please sign in to comment.