Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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 Zend/zend_vm_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ function gen_vm_opcodes_header(
$str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_HYBRID\n";
}
if ($GLOBALS["vm_kind_name"][ZEND_VM_GEN_KIND] === "ZEND_VM_KIND_HYBRID" || $GLOBALS["vm_kind_name"][ZEND_VM_GEN_KIND] === "ZEND_VM_KIND_CALL") {
$str .= "#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(__aarch64__))\n";
$str .= "#elif defined(HAVE_MUSTTAIL) && defined(HAVE_PRESERVE_NONE) && (defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64))\n";
$str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_TAILCALL\n";
$str .= "#else\n";
$str .= "# define ZEND_VM_KIND\t\tZEND_VM_KIND_CALL\n";
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_opcodes.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3314,6 +3314,27 @@ static PRUNTIME_FUNCTION zend_jit_unwind_callback(DWORD64 pc, PVOID context)

static void zend_jit_setup_unwinder(void)
{
#if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL
/* TAILCALL VM: fixed_save_regset=0, no registers pushed in prologue.
* fixed_stack_frame_size=40, fixed_call_stack_size=48 (16+IR_SHADOW_ARGS).
* Prologue is: sub rsp, 0x58 (88 bytes = 40+48). */
static const unsigned char uw_data[] = {
0x01, // Version=1, Flags=0
0x04, // Size of prolog (sub rsp,imm8 = 4 bytes: 48 83 ec 58)
0x01, // Count of unwind codes
0x00, // Frame Register=none
0x04, 0xa2, // offset 4: UWOP_ALLOC_SMALL info=10, alloc=(10+1)*8=88
0x00, 0x00, // padding
};
/* Exit call variant: base 88 + 304 (shadow+GP+FP+padding) = 392 (0x188) */
static const unsigned char uw_data_exitcall[] = {
0x01, // Version=1, Flags=0
0x07, // Size of prolog (sub rsp,imm32 = 7 bytes: 48 81 ec 88 01 00 00)
0x02, // Count of unwind codes
0x00, // Frame Register=none
0x07, 0x01, 0x31, 0x00, // offset 7: UWOP_ALLOC_LARGE info=0, size/8=49, alloc=392
};
#else
/* Hardcoded SEH unwind data for JIT-ed PHP functions with "fixed stack frame" */
static const unsigned char uw_data[] = {
0x01, // UBYTE: 3 Version , UBYTE: 5 Flags
Expand Down Expand Up @@ -3348,6 +3369,7 @@ static void zend_jit_setup_unwinder(void)
0x02, 0x50, // 1: pushq %rbp
0x01, 0x30, // 0: pushq %rbx
};
#endif

zend_jit_uw_func = (PRUNTIME_FUNCTION)*dasm_ptr;
*dasm_ptr = (char*)*dasm_ptr + ZEND_MM_ALIGNED_SIZE_EX(sizeof(RUNTIME_FUNCTION) * 4 +
Expand Down
4 changes: 4 additions & 0 deletions win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3374,6 +3374,10 @@ function toolset_setup_common_cflags()

var vc_ver = probe_binary(PATH_PROG('cl', null));
ADD_FLAG("CFLAGS"," -fms-compatibility -fms-compatibility-version=" + vc_ver + " -fms-extensions");

if (CLANGVERS >= 1900 && (TARGET_ARCH === 'x64' || TARGET_ARCH === 'arm64')) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an ARM64 windows pc to test this with, neither does the CI. Should I perhaps limit this to x64 only as a defensive check for now? We only do x64 releases at FrankenPHP anyhow.

I know clang can do tailcalls on arm64, but I'm not sure if the jit changes work for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @shivammathur is able to test on arm64?

Otherwise it would be fine to limit this to x64 until someone can test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that would be great. Could you add the CI: All variations tag please so that the Clang compilation actually runs?

Perhaps we should also add a test to make sure clang on windows actually produces a php binary with ZEND_VM_KIND = tailcall vm?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that would be great. Could you add the CI: All variations tag please so that the Clang compilation actually runs?

Done, you can push again to retrigger CI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henderkes There is a windows-11-arm runner you can use to test this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails because the sdk tools don't include an arm64 bat file. I'll just revert the commit and add a safety check to only use tailcall VM on x64.

AC_DEFINE('HAVE_PRESERVE_NONE', 1, 'Whether the compiler supports __attribute__((preserve_none))');
}
}

if (!CLANG_TOOLSET) {
Expand Down
Loading