Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/download-bundled/jit-ir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd "$(dirname "$0")/../../.."
tmp_dir=/tmp/php-src-download-bundled/jit-ir
rm -rf "$tmp_dir"

revision=93f92f5b5a49a02295685e340ebb0b83562cbe79
revision=ed32c881a0d7c14ce7ace6ac00dead75647b69c6

git clone --depth 1 --revision="$revision" https://github.com/dstogov/ir.git "$tmp_dir"

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_arm.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM ARM encoding engine.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_arm.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM ARM module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------

Expand Down
66 changes: 34 additions & 32 deletions ext/opcache/jit/ir/dynasm/dasm_arm64.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM ARM64 encoding engine.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down Expand Up @@ -178,44 +178,46 @@ static int dasm_imm12(unsigned int n)
return -1;
}

static int dasm_ffs(unsigned long long x)
#if defined(__GNUC__) || defined(__clang__)
#define dasm_ctz(x) __builtin_ctzll(x)
#define dasm_clz(x) __builtin_clzll(x)
#else
static int dasm_ctz(unsigned long long x)
{
int n = 0;
x = ~x;
while (x & 1) { x >>= 1; n++; }
return n;
}

static int dasm_clz(unsigned long long x)
{
int n = -1;
while (x) { x >>= 1; n++; }
int n = 0;
x = ~x;
while ((long long)x < 0) { x <<= 1; n++; }
return n;
}
#endif

static unsigned long long dasm_ror(unsigned long long x, int n)
{
return (x << (-n & 63)) | (x >> n);
}

static int dasm_imm13(int lo, int hi)
{
int inv = 0, w = 64, s = 0xfff, xa, xb;
/* Thanks to: https://dougallj.wordpress.com/2021/10/30/ */
int rot, ones, size, immr, imms;
unsigned long long n = (((unsigned long long)hi) << 32) | (unsigned int)lo;
unsigned long long m = 1ULL, a, b, c;
if (n & 1) { n = ~n; inv = 1; }
a = n & (unsigned long long)-(long long)n;
b = (n+a)&(unsigned long long)-(long long)(n+a);
c = (n+a-b)&(unsigned long long)-(long long)(n+a-b);
xa = dasm_ffs(a); xb = dasm_ffs(b);
if (c) {
w = dasm_ffs(c) - xa;
if (w == 32) m = 0x0000000100000001UL;
else if (w == 16) m = 0x0001000100010001UL;
else if (w == 8) m = 0x0101010101010101UL;
else if (w == 4) m = 0x1111111111111111UL;
else if (w == 2) m = 0x5555555555555555UL;
else return -1;
s = (-2*w & 0x3f) - 1;
} else if (!a) {
return -1;
} else if (xb == -1) {
xb = 64;
}
if ((b-a) * m != n) return -1;
if (inv) {
return ((w - xb) << 6) | (s+w+xa-xb);
} else {
return ((w - xa) << 6) | (s+xb-xa);
}
return -1;
if ((n+1u) <= 1u) return -1; /* Neither all-zero nor all-ones are allowed. */
rot = (n & (n+1u)) ? dasm_ctz(n & (n+1u)) : 64;
n = dasm_ror(n, rot & 63);
ones = dasm_ctz(~n);
size = dasm_clz(n) + ones;
if (dasm_ror(n, size & 63) != n) return -1; /* Non-repeating? */
immr = -rot & (size - 1);
imms = (-(size << 1) | (ones - 1)) & 63;
return ((immr | (size & 64)) << 6) | imms;
}

/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */
Expand Down
24 changes: 23 additions & 1 deletion ext/opcache/jit/ir/dynasm/dasm_arm64.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM ARM64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------

Expand Down Expand Up @@ -244,6 +244,10 @@ local map_cond = {
hs = 2, lo = 3,
}

local map_bti = {
c = 0x40, j = 0x80, jc = 0xc0,
}

------------------------------------------------------------------------------

local parse_reg_type
Expand Down Expand Up @@ -475,6 +479,12 @@ local function parse_cond(expr, inv)
return shl(bit.bxor(c, inv), 12)
end

local function parse_map(expr, map)
local x = map[expr]
if not x then werror("bad operand") end
return x
end

local function parse_load(params, nparams, n, op)
if params[n+2] then werror("too many operands") end
local scale = shr(op, 30)
Expand Down Expand Up @@ -823,11 +833,21 @@ map_op = {
tbz_3 = "36000000DTBw|36000000DTBx",
tbnz_3 = "37000000DTBw|37000000DTBx",

-- Branch Target Identification.
bti_1 = "d503241ft",

-- ARM64e: Pointer authentication codes (PAC).
blraaz_1 = "d63f081fNx",
blrabz_1 = "d63f0c1fNx",
braa_2 = "d71f0800NDx",
brab_2 = "d71f0c00NDx",
braaz_1 = "d61f081fNx",
brabz_1 = "d61f0c1fNx",
paciasp_0 = "d503233f",
pacibsp_0 = "d503237f",
autiasp_0 = "d50323bf",
autibsp_0 = "d50323ff",
retaa_0 = "d65f0bff",
retab_0 = "d65f0fff",

-- Miscellaneous instructions.
Expand Down Expand Up @@ -996,6 +1016,8 @@ local function parse_template(params, template, nparams, pos)
op = op + parse_cond(q, 0); n = n + 1
elseif p == "c" then
op = op + parse_cond(q, 1); n = n + 1
elseif p == "t" then
op = op + parse_map(q, map_bti); n = n + 1

else
assert(false)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_mips.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM MIPS encoding engine.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_mips.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM MIPS32/MIPS64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_mips64.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM MIPS64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------
-- This module just sets 64 bit mode for the combined MIPS/MIPS64 module.
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_ppc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM PPC/PPC64 encoding engine.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_ppc.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM PPC/PPC64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
--
-- Support for various extensions contributed by Caio Souza Oliveira.
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_proto.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM encoding engine prototypes.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_x64.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM x64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------
-- This module just sets 64 bit mode for the combined x86/x64 module.
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_x86.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** DynASM x86 encoding engine.
** Copyright (C) 2005-2023 Mike Pall. All rights reserved.
** Copyright (C) 2005-2026 Mike Pall. All rights reserved.
** Released under the MIT license. See dynasm.lua for full copyright notice.
*/

Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/dynasm/dasm_x86.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- DynASM x86/x64 module.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See dynasm.lua for full copyright notice.
------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/jit/ir/dynasm/dynasm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- DynASM. A dynamic assembler for code generation engines.
-- Originally designed and implemented for LuaJIT.
--
-- Copyright (C) 2005-2023 Mike Pall. All rights reserved.
-- Copyright (C) 2005-2026 Mike Pall. All rights reserved.
-- See below for full copyright notice.
------------------------------------------------------------------------------

Expand All @@ -17,7 +17,7 @@ local _info = {
url = "https://luajit.org/dynasm.html",
license = "MIT",
copyright = [[
Copyright (C) 2005-2023 Mike Pall. All rights reserved.
Copyright (C) 2005-2026 Mike Pall. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
8 changes: 5 additions & 3 deletions ext/opcache/jit/ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted
#define ir_op_flag_xN (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_CALL | IR_OP_FLAG_VAR_INPUTS)
#define ir_op_flag_a1 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_ALLOC | 1 | (1 << IR_OP_FLAG_OPERANDS_SHIFT))
#define ir_op_flag_a2 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_ALLOC | 2 | (2 << IR_OP_FLAG_OPERANDS_SHIFT))
#define ir_op_flag_a2X1 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_ALLOC | 2 | (3 << IR_OP_FLAG_OPERANDS_SHIFT))

#define ir_op_kind____ IR_OPND_UNUSED
#define ir_op_kind_def IR_OPND_DATA
Expand All @@ -391,8 +392,9 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted
#define ir_op_kind_num IR_OPND_NUM
#define ir_op_kind_fld IR_OPND_STR
#define ir_op_kind_var IR_OPND_DATA
#define ir_op_kind_prb IR_OPND_PROB
#define ir_op_kind_opt IR_OPND_PROB
#define ir_op_kind_opt IR_OPND_OPT
#define ir_op_kind_prb IR_OPND_OPT
#define ir_op_kind_alg IR_OPND_OPT
#define ir_op_kind_pro IR_OPND_PROTO
#define ir_op_kind_lbl IR_OPND_LABEL_REF

Expand Down Expand Up @@ -620,7 +622,7 @@ static IR_NEVER_INLINE void ir_const_hash_rehash(ir_ctx *ctx)
ctx->const_hash = ir_mem_calloc(ctx->const_hash_mask + 1, sizeof(ir_ref));
for (ref = 1 - ctx->consts_count, insn = ctx->ir_base + ref; ref < IR_TRUE; ref++, insn++) {
if (insn->op == IR_LONG_CONST) {
hash = insn->val.u64;
hash = insn->val.addr;
insn->prev_const = ctx->const_hash[hash & ctx->const_hash_mask];
ctx->const_hash[hash & ctx->const_hash_mask] = ref;
ref += IR_ALIGNED_SIZE(insn->long_const_size, sizeof(ir_insn)) / sizeof(ir_insn);
Expand Down
26 changes: 16 additions & 10 deletions ext/opcache/jit/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ extern "C" {
# define IR_TARGET_TRIPLET "x86-freebsd-sysv"
# elif defined(__NetBSD__)
# define IR_TARGET_TRIPLET "x86-netbsd-sysv"
# elif defined(__OpenBSD__)
# define IR_TARGET_TRIPLET "x86-openbsd-sysv"
# else
# define IR_TARGET_TRIPLET "x86-unknown-sysv"
# endif
Expand All @@ -79,6 +81,8 @@ extern "C" {
# define IR_TARGET_TRIPLET "x86_64-freebsd-sysv"
# elif defined(__NetBSD__)
# define IR_TARGET_TRIPLET "x86_64-netbsd-sysv"
# elif defined(__OpenBSD__)
# define IR_TARGET_TRIPLET "x86_64-openbsd-sysv"
# else
# define IR_TARGET_TRIPLET "x86_64-unknown-sysv"
# endif
Expand All @@ -93,6 +97,8 @@ extern "C" {
# define IR_TARGET_TRIPLET "aarch64-freebsd-sysv"
# elif defined(__NetBSD__)
# define IR_TARGET_TRIPLET "aarch64-netbsd-sysv"
# elif defined(__OpenBSD__)
# define IR_TARGET_TRIPLET "aarch64-openbsd-sysv"
# else
# define IR_TARGET_TRIPLET "aarch64-unknown-sysv"
# endif
Expand Down Expand Up @@ -256,9 +262,9 @@ typedef enum _ir_type {
* E - control IR_OP_FLAG_CONTROL + IR_OP_FLAG_BB_END
* T - control IR_OP_FLAG_CONTROL + IR_OP_FLAG_BB_END + IR_OP_FLAG_TERMINATOR
* l - load IR_OP_FLAG_MEM + IR_OP_FLAG_MEM_LOAD
* s - store IR_OP_FLAG_MEM + IR_OP_FLAG_STORE
* x - call IR_OP_FLAG_MEM + IR_OP_FLAG_CALL
* a - alloc IR_OP_FLAG_MEM + IR_OP_FLAG_ALLOC
* s - store IR_OP_FLAG_MEM + IR_OP_FLAG_MEM_STORE
* x - call IR_OP_FLAG_MEM + IR_OP_FLAG_MEM_CALL
* a - alloc IR_OP_FLAG_MEM + IR_OP_FLAG_MEM_ALLOC
* 0-3 - number of input edges
* N - number of arguments is defined in the insn->inputs_count (MERGE, PHI, CALL)
* X1-X3 - number of extra data ops
Expand All @@ -279,6 +285,7 @@ typedef enum _ir_type {
* num - number: argument number (PARAM)
* prb - branch probability 1-99 (0 - unspecified): (IF_TRUE, IF_FALSE, CASE_VAL, CASE_DEFAULT)
* opt - optional number
* alg - optional alignment
* pro - function prototype
* lbl - label used as value (a reference to constant): (BEGIN)
*
Expand Down Expand Up @@ -389,7 +396,7 @@ typedef enum _ir_type {
\
/* data ops */ \
_(PARAM, p1X2, reg, str, num) /* incoming parameter proj. */ \
_(VAR, p1X1, reg, str, ___) /* local variable */ \
_(VAR, p1X2, reg, str, alg) /* local variable */ \
_(FUNC_ADDR, r0, ___, ___, ___) /* constant func ref */ \
_(FUNC, r0, ___, ___, ___) /* constant func ref */ \
_(SYM, r0, ___, ___, ___) /* constant symbol ref */ \
Expand All @@ -402,10 +409,10 @@ typedef enum _ir_type {
_(TAILCALL, xN, src, def, def) /* CALL+RETURN */ \
\
/* memory reference and load/store ops */ \
_(ALLOCA, a2, src, def, ___) /* alloca(def) */ \
_(AFREE, a2, src, def, ___) /* revert alloca(def) */ \
_(ALLOCA, a2X1, src, def, alg) /* alloca(def) */ \
_(AFREE, s2, src, def, ___) /* revert alloca(def) */ \
_(BLOCK_BEGIN, a1, src, ___, ___) /* stacksave */ \
_(BLOCK_END, a2, src, def, ___) /* stackrestore */ \
_(BLOCK_END, s2, src, def, ___) /* stackrestore */ \
_(VLOAD, l2, src, var, ___) /* load value of local var */ \
_(VLOAD_v, l2, src, var, ___) /* volatile variant of VLOAD */ \
_(VSTORE, s3, src, var, def) /* store value to local var */ \
Expand Down Expand Up @@ -712,7 +719,6 @@ typedef struct _ir_code_buffer {
typedef struct {
int size;
int align;
int offset;
} ir_value_param;

typedef struct _ir_bitqueue ir_bitqueue;
Expand Down Expand Up @@ -747,8 +753,8 @@ struct _ir_ctx {
uint32_t *cfg_map; /* map of instructions to basic block number */
uint32_t *cfg_schedule; /* BB order for code generation */
uint32_t *rules; /* array of target specific code-generation rules (for each instruction) */
uint32_t *vregs;
ir_ref vregs_count;
int32_t *vregs; /* map of insns to virtual regs (positive) or stack slots (negative) */
int32_t vregs_count;
ir_str func_name; /* Function name (should be set through ir_string()/ir_stringl()) */
int32_t spill_base; /* base register for special spill area (e.g. PHP VM frame pointer) */
uint64_t fixed_regset; /* fixed registers, excluded for regular register allocation */
Expand Down
Loading
Loading