Skip to content

Commit 2ab1c3d

Browse files
committed
Update IR
IR commit: 76dea0e897bff7e67f560f9768672519bd9783d4
1 parent 6aa8687 commit 2ab1c3d

24 files changed

+243
-176
lines changed

ext/opcache/jit/ir/dynasm/dasm_arm.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
** DynASM ARM encoding engine.
3-
** Copyright (C) 2005-2021 Mike Pall. All rights reserved.
3+
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
44
** Released under the MIT license. See dynasm.lua for full copyright notice.
55
*/
66

@@ -70,7 +70,7 @@ struct dasm_State {
7070
size_t lgsize;
7171
int *pclabels; /* PC label chains/pos ptrs. */
7272
size_t pcsize;
73-
void **globals; /* Array of globals (bias -10). */
73+
void **globals; /* Array of globals. */
7474
dasm_Section *section; /* Pointer to active section. */
7575
size_t codesize; /* Total size of all code sections. */
7676
int maxsection; /* 0 <= sectionidx < maxsection. */
@@ -87,7 +87,6 @@ void dasm_init(Dst_DECL, int maxsection)
8787
{
8888
dasm_State *D;
8989
size_t psz = 0;
90-
int i;
9190
Dst_REF = NULL;
9291
DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
9392
D = Dst_REF;
@@ -98,12 +97,7 @@ void dasm_init(Dst_DECL, int maxsection)
9897
D->pcsize = 0;
9998
D->globals = NULL;
10099
D->maxsection = maxsection;
101-
for (i = 0; i < maxsection; i++) {
102-
D->sections[i].buf = NULL; /* Need this for pass3. */
103-
D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
104-
D->sections[i].bsize = 0;
105-
D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
106-
}
100+
memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
107101
}
108102

109103
/* Free DynASM state. */
@@ -123,7 +117,7 @@ void dasm_free(Dst_DECL)
123117
void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
124118
{
125119
dasm_State *D = Dst_REF;
126-
D->globals = gl - 10; /* Negative bias to compensate for locals. */
120+
D->globals = gl;
127121
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
128122
}
129123

@@ -148,6 +142,7 @@ void dasm_setup(Dst_DECL, const void *actionlist)
148142
if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
149143
for (i = 0; i < D->maxsection; i++) {
150144
D->sections[i].pos = DASM_SEC2POS(i);
145+
D->sections[i].rbuf = D->sections[i].buf - D->sections[i].pos;
151146
D->sections[i].ofs = 0;
152147
}
153148
}
@@ -372,7 +367,7 @@ int dasm_encode(Dst_DECL, void *buffer)
372367
break;
373368
case DASM_REL_LG:
374369
if (n < 0) {
375-
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp - 4);
370+
n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp - 4);
376371
goto patchrel;
377372
}
378373
/* fallthrough */
@@ -396,7 +391,7 @@ int dasm_encode(Dst_DECL, void *buffer)
396391
}
397392
break;
398393
case DASM_LABEL_LG:
399-
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
394+
ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
400395
break;
401396
case DASM_LABEL_PC: break;
402397
case DASM_IMM:

ext/opcache/jit/ir/dynasm/dasm_arm.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- DynASM ARM module.
33
--
4-
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
55
-- See dynasm.lua for full copyright notice.
66
------------------------------------------------------------------------------
77

ext/opcache/jit/ir/dynasm/dasm_arm64.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
** DynASM ARM64 encoding engine.
3-
** Copyright (C) 2005-2021 Mike Pall. All rights reserved.
3+
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
44
** Released under the MIT license. See dynasm.lua for full copyright notice.
55
*/
66

@@ -72,7 +72,7 @@ struct dasm_State {
7272
size_t lgsize;
7373
int *pclabels; /* PC label chains/pos ptrs. */
7474
size_t pcsize;
75-
void **globals; /* Array of globals (bias -10). */
75+
void **globals; /* Array of globals. */
7676
dasm_Section *section; /* Pointer to active section. */
7777
size_t codesize; /* Total size of all code sections. */
7878
int maxsection; /* 0 <= sectionidx < maxsection. */
@@ -89,7 +89,6 @@ void dasm_init(Dst_DECL, int maxsection)
8989
{
9090
dasm_State *D;
9191
size_t psz = 0;
92-
int i;
9392
Dst_REF = NULL;
9493
DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
9594
D = Dst_REF;
@@ -100,12 +99,7 @@ void dasm_init(Dst_DECL, int maxsection)
10099
D->pcsize = 0;
101100
D->globals = NULL;
102101
D->maxsection = maxsection;
103-
for (i = 0; i < maxsection; i++) {
104-
D->sections[i].buf = NULL; /* Need this for pass3. */
105-
D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
106-
D->sections[i].bsize = 0;
107-
D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
108-
}
102+
memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
109103
}
110104

111105
/* Free DynASM state. */
@@ -125,7 +119,7 @@ void dasm_free(Dst_DECL)
125119
void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
126120
{
127121
dasm_State *D = Dst_REF;
128-
D->globals = gl - 10; /* Negative bias to compensate for locals. */
122+
D->globals = gl;
129123
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
130124
}
131125

@@ -150,6 +144,7 @@ void dasm_setup(Dst_DECL, const void *actionlist)
150144
if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
151145
for (i = 0; i < D->maxsection; i++) {
152146
D->sections[i].pos = DASM_SEC2POS(i);
147+
D->sections[i].rbuf = D->sections[i].buf - D->sections[i].pos;
153148
D->sections[i].ofs = 0;
154149
}
155150
}
@@ -158,10 +153,10 @@ void dasm_setup(Dst_DECL, const void *actionlist)
158153
#ifdef DASM_CHECKS
159154
#define CK(x, st) \
160155
do { if (!(x)) { \
161-
D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
156+
D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)
162157
#define CKPL(kind, st) \
163158
do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
164-
D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
159+
D->status = DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)
165160
#else
166161
#define CK(x, st) ((void)0)
167162
#define CKPL(kind, st) ((void)0)
@@ -190,7 +185,9 @@ static int dasm_imm13(int lo, int hi)
190185
unsigned long long n = (((unsigned long long)hi) << 32) | (unsigned int)lo;
191186
unsigned long long m = 1ULL, a, b, c;
192187
if (n & 1) { n = ~n; inv = 1; }
193-
a = n & -n; b = (n+a)&-(n+a); c = (n+a-b)&-(n+a-b);
188+
a = n & (unsigned long long)-(long long)n;
189+
b = (n+a)&(unsigned long long)-(long long)(n+a);
190+
c = (n+a-b)&(unsigned long long)-(long long)(n+a-b);
194191
xa = dasm_ffs(a); xb = dasm_ffs(b);
195192
if (c) {
196193
w = dasm_ffs(c) - xa;
@@ -415,7 +412,7 @@ int dasm_link(Dst_DECL, size_t *szp)
415412

416413
#ifdef DASM_CHECKS
417414
#define CK(x, st) \
418-
do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
415+
do { if (!(x)) return DASM_S_##st|(int)(p-D->actionlist-1); } while (0)
419416
#else
420417
#define CK(x, st) ((void)0)
421418
#endif
@@ -451,7 +448,7 @@ int dasm_encode(Dst_DECL, void *buffer)
451448
break;
452449
case DASM_REL_LG:
453450
if (n < 0) {
454-
ptrdiff_t na = (ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4;
451+
ptrdiff_t na = (ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp + 4;
455452
n = (int)na;
456453
CK_REL((ptrdiff_t)n == na, na);
457454
goto patchrel;
@@ -494,7 +491,7 @@ int dasm_encode(Dst_DECL, void *buffer)
494491
goto patchrel;
495492
}
496493
case DASM_LABEL_LG:
497-
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
494+
ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
498495
break;
499496
case DASM_LABEL_PC: break;
500497
case DASM_IMM:
@@ -563,7 +560,7 @@ int dasm_checkstep(Dst_DECL, int secmatch)
563560
}
564561
if (D->status == DASM_S_OK && secmatch >= 0 &&
565562
D->section != &D->sections[secmatch])
566-
D->status = DASM_S_MATCH_SEC|(D->section-D->sections);
563+
D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections);
567564
return D->status;
568565
}
569566
#endif

ext/opcache/jit/ir/dynasm/dasm_arm64.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- DynASM ARM64 module.
33
--
4-
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
55
-- See dynasm.lua for full copyright notice.
66
------------------------------------------------------------------------------
77

@@ -549,7 +549,7 @@ end
549549
local function parse_load_pair(params, nparams, n, op)
550550
if params[n+2] then werror("too many operands") end
551551
local pn, p2 = params[n], params[n+1]
552-
local scale = shr(op, 30) == 0 and 2 or 3
552+
local scale = 2 + shr(op, 31 - band(shr(op, 26), 1))
553553
local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$")
554554
if not p1 then
555555
if not p2 then
@@ -806,8 +806,8 @@ map_op = {
806806
["ldrsw_*"] = "98000000DxB|b8800000DxL",
807807
-- NOTE: ldur etc. are handled by ldr et al.
808808

809-
["stp_*"] = "28000000DAwP|a8000000DAxP|2c000000DAsP|6c000000DAdP",
810-
["ldp_*"] = "28400000DAwP|a8400000DAxP|2c400000DAsP|6c400000DAdP",
809+
["stp_*"] = "28000000DAwP|a8000000DAxP|2c000000DAsP|6c000000DAdP|ac000000DAqP",
810+
["ldp_*"] = "28400000DAwP|a8400000DAxP|2c400000DAsP|6c400000DAdP|ac400000DAqP",
811811
["ldpsw_*"] = "68400000DAxP",
812812

813813
-- Branches.
@@ -823,6 +823,13 @@ map_op = {
823823
tbz_3 = "36000000DTBw|36000000DTBx",
824824
tbnz_3 = "37000000DTBw|37000000DTBx",
825825

826+
-- ARM64e: Pointer authentication codes (PAC).
827+
blraaz_1 = "d63f081fNx",
828+
braa_2 = "d71f0800NDx",
829+
braaz_1 = "d61f081fNx",
830+
pacibsp_0 = "d503237f",
831+
retab_0 = "d65f0fff",
832+
826833
-- Miscellaneous instructions.
827834
-- TODO: hlt, hvc, smc, svc, eret, dcps[123], drps, mrs, msr
828835
-- TODO: sys, sysl, ic, dc, at, tlbi
@@ -935,7 +942,7 @@ local function parse_template(params, template, nparams, pos)
935942
werror("bad register type")
936943
end
937944
parse_reg_type = false
938-
elseif p == "x" or p == "w" or p == "d" or p == "s" then
945+
elseif p == "x" or p == "w" or p == "d" or p == "s" or p == "q" then
939946
if parse_reg_type ~= p then
940947
werror("register size mismatch")
941948
end

ext/opcache/jit/ir/dynasm/dasm_mips.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
** DynASM MIPS encoding engine.
3-
** Copyright (C) 2005-2021 Mike Pall. All rights reserved.
3+
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
44
** Released under the MIT license. See dynasm.lua for full copyright notice.
55
*/
66

@@ -69,7 +69,7 @@ struct dasm_State {
6969
size_t lgsize;
7070
int *pclabels; /* PC label chains/pos ptrs. */
7171
size_t pcsize;
72-
void **globals; /* Array of globals (bias -10). */
72+
void **globals; /* Array of globals. */
7373
dasm_Section *section; /* Pointer to active section. */
7474
size_t codesize; /* Total size of all code sections. */
7575
int maxsection; /* 0 <= sectionidx < maxsection. */
@@ -86,7 +86,6 @@ void dasm_init(Dst_DECL, int maxsection)
8686
{
8787
dasm_State *D;
8888
size_t psz = 0;
89-
int i;
9089
Dst_REF = NULL;
9190
DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
9291
D = Dst_REF;
@@ -97,12 +96,7 @@ void dasm_init(Dst_DECL, int maxsection)
9796
D->pcsize = 0;
9897
D->globals = NULL;
9998
D->maxsection = maxsection;
100-
for (i = 0; i < maxsection; i++) {
101-
D->sections[i].buf = NULL; /* Need this for pass3. */
102-
D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
103-
D->sections[i].bsize = 0;
104-
D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
105-
}
99+
memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
106100
}
107101

108102
/* Free DynASM state. */
@@ -122,7 +116,7 @@ void dasm_free(Dst_DECL)
122116
void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
123117
{
124118
dasm_State *D = Dst_REF;
125-
D->globals = gl - 10; /* Negative bias to compensate for locals. */
119+
D->globals = gl;
126120
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
127121
}
128122

@@ -147,6 +141,7 @@ void dasm_setup(Dst_DECL, const void *actionlist)
147141
if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
148142
for (i = 0; i < D->maxsection; i++) {
149143
D->sections[i].pos = DASM_SEC2POS(i);
144+
D->sections[i].rbuf = D->sections[i].buf - D->sections[i].pos;
150145
D->sections[i].ofs = 0;
151146
}
152147
}
@@ -155,10 +150,10 @@ void dasm_setup(Dst_DECL, const void *actionlist)
155150
#ifdef DASM_CHECKS
156151
#define CK(x, st) \
157152
do { if (!(x)) { \
158-
D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
153+
D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)
159154
#define CKPL(kind, st) \
160155
do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
161-
D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
156+
D->status = DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)
162157
#else
163158
#define CK(x, st) ((void)0)
164159
#define CKPL(kind, st) ((void)0)
@@ -314,7 +309,7 @@ int dasm_link(Dst_DECL, size_t *szp)
314309

315310
#ifdef DASM_CHECKS
316311
#define CK(x, st) \
317-
do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
312+
do { if (!(x)) return DASM_S_##st|(int)(p-D->actionlist-1); } while (0)
318313
#else
319314
#define CK(x, st) ((void)0)
320315
#endif
@@ -350,7 +345,7 @@ int dasm_encode(Dst_DECL, void *buffer)
350345
break;
351346
case DASM_REL_LG:
352347
if (n < 0) {
353-
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);
348+
n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp);
354349
goto patchrel;
355350
}
356351
/* fallthrough */
@@ -369,7 +364,7 @@ int dasm_encode(Dst_DECL, void *buffer)
369364
}
370365
break;
371366
case DASM_LABEL_LG:
372-
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
367+
ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n);
373368
break;
374369
case DASM_LABEL_PC: break;
375370
case DASM_IMMS:
@@ -417,7 +412,7 @@ int dasm_checkstep(Dst_DECL, int secmatch)
417412
}
418413
if (D->status == DASM_S_OK && secmatch >= 0 &&
419414
D->section != &D->sections[secmatch])
420-
D->status = DASM_S_MATCH_SEC|(D->section-D->sections);
415+
D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections);
421416
return D->status;
422417
}
423418
#endif

ext/opcache/jit/ir/dynasm/dasm_mips.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- DynASM MIPS32/MIPS64 module.
33
--
4-
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
55
-- See dynasm.lua for full copyright notice.
66
------------------------------------------------------------------------------
77

ext/opcache/jit/ir/dynasm/dasm_mips64.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- DynASM MIPS64 module.
33
--
4-
-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.
4+
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
55
-- See dynasm.lua for full copyright notice.
66
------------------------------------------------------------------------------
77
-- This module just sets 64 bit mode for the combined MIPS/MIPS64 module.

0 commit comments

Comments
 (0)