From fb4b7069842491eb66272587422a1f61d41eb869 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 17 Mar 2015 13:51:02 +0300 Subject: [PATCH] Enable GCC global register variables if available --- Zend/Zend.m4 | 45 +++++++++++++++++++++++++++++++++++++++++++++ Zend/zend_execute.c | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 16f2d5f923..e12b00d5ef 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -409,3 +409,48 @@ else AC_MSG_RESULT(no) fi fi + +AC_ARG_ENABLE(gcc-global-regs, +[ --disable-gcc-global-regs + whether to enable GCC global register variables],[ + ZEND_GCC_GLOBAL_REGS=$enableval +],[ + ZEND_GCC_GLOBAL_REGS=yes +]) +AC_MSG_CHECKING(for global register variables support) +if test "$ZEND_GCC_GLOBAL_REGS" != "no"; then + AC_TRY_COMPILE([ + ],[ +#if defined(__GNUC__) && defined(i386) +# define ZEND_VM_FP_GLOBAL_REG "%esi" +# define ZEND_VM_IP_GLOBAL_REG "%edi" +#elif defined(__GNUC__) && defined(__x86_64__) +# define ZEND_VM_FP_GLOBAL_REG "%r14" +# define ZEND_VM_IP_GLOBAL_REG "%r15" +#else +# error "global register variables are not supported" +#endif +typedef int (*opcode_handler_t)(void); +register void *FP __asm__(ZEND_VM_FP_GLOBAL_REG); +register const opcode_handler_t *IP __asm__(ZEND_VM_IP_GLOBAL_REG); +int emu(const opcode_handler_t *ip, void *fp) { + const opcode_handler_t *orig_ip = IP; + void *orig_fp = FP; + IP = ip; + FP = fp; + while ((*ip)()); + FP = orig_fp; + IP = orig_ip; +} + ], [ + ZEND_GCC_GLOBAL_REGS=yes + ], [ + ZEND_GCC_GLOBAL_REGS=no + ]) +fi +if test "$ZEND_GCC_GLOBAL_REGS" = "yes"; then + AC_DEFINE([HAVE_GCC_GLOBAL_REGS], 1, [Define if the target system has support for global register variables]) +else + HAVE_GCC_GLOBAL_REGS=no +fi +AC_MSG_RESULT(ZEND_GCC_GLOBAL_REGS) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index b24218a2b2..17e68dc55d 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2049,7 +2049,7 @@ static zend_always_inline void zend_vm_stack_extend_call_frame(zend_execute_data } /* }}} */ -#if HAVE_GCC_GLOBAL_REGS +#ifdef HAVE_GCC_GLOBAL_REGS # if defined(__GNUC__) && defined(i386) # define ZEND_VM_FP_GLOBAL_REG "%esi" # define ZEND_VM_IP_GLOBAL_REG "%edi" -- 2.40.0