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=a4d13e263dd3010de06cd05235e006bfefa927a5

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

Expand Down
1 change: 1 addition & 0 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
jit/ir/ir_patch.c
jit/ir/ir_perf.c
jit/ir/ir_ra.c
jit/ir/ir_ra_simple.c
jit/ir/ir_save.c
jit/ir/ir_sccp.c
jit/ir/ir_strtab.c
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (PHP_OPCACHE_JIT == "yes") {
} else if (CHECK_HEADER("ir/ir.h", "CFLAGS_OPCACHE", PHP_OPCACHE + ";ext\\opcache\\jit")) {
var dasm_flags = (X64 ? "-D X64=1" : "") + (X64 ? " -D X64WIN=1" : "") + " -D WIN=1";
var ir_target = (X64 ? "IR_TARGET_X64" : "IR_TARGET_X86");
var ir_src = "ir_strtab.c ir_cfg.c ir_sccp.c ir_gcm.c ir_ra.c ir_save.c \
var ir_src = "ir_strtab.c ir_cfg.c ir_sccp.c ir_gcm.c ir_ra.c ir_ra_simple.c ir_save.c \
ir_dump.c ir_check.c ir_patch.c";

DEFINE("IR_TARGET", ir_target);
Expand Down
5 changes: 5 additions & 0 deletions ext/opcache/jit/Makefile.frag.w32
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ $(BUILD_DIR)\ext\opcache\jit\ir\ir_ra.obj: \
ext\opcache\jit\ir\ir_private.h \
ext\opcache\jit\ir\ir_x86.h

$(BUILD_DIR)\ext\opcache\jit\ir\ir_ra_simple.obj: \
ext\opcache\jit\ir\ir.h \
ext\opcache\jit\ir\ir_private.h \
ext\opcache\jit\ir\ir_x86.h

$(BUILD_DIR)\ext\opcache\jit\ir\ir_emit.obj: \
ext\opcache\jit\ir\ir.h \
ext\opcache\jit\ir\ir_private.h \
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
13 changes: 10 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 Expand Up @@ -1299,6 +1301,11 @@ ir_ref ir_fold(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3)
if (UNEXPECTED(!(ctx->flags & IR_OPT_FOLDING))) {
if ((opt & IR_OPT_OP_MASK) == IR_PHI) {
opt |= (3 << IR_OPT_INPUTS_SHIFT);
} else if ((ir_op_flags[(opt & IR_OPT_OP_MASK)] & IR_OP_FLAG_COMMUTATIVE)
&& op1 < op2
&& IR_IS_CONST_REF(op1)) {
/* Move constants to op2 for better instruction selection with (this is for -O0) */
SWAP_REFS(op1, op2);
}
return ir_emit(ctx, opt, op1, op2, op3);
}
Expand Down
Loading
Loading