Skip to content

Commit dae662f

Browse files
committed
Fixed zend_long_is_power_of_two/zend_long_floor_log2 mess
1 parent d6d0b1c commit dae662f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,9 +3902,9 @@ static int zend_jit_math_long_long(dasm_State **Dst,
39023902
| lsl Rx(result_reg), Rx(result_reg), TMP1
39033903
} else if (opcode == ZEND_DIV &&
39043904
(Z_MODE(op2_addr) == IS_CONST_ZVAL &&
3905-
is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr))))) {
3905+
zend_long_is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr))))) {
39063906
| GET_ZVAL_LVAL result_reg, op1_addr, TMP1
3907-
| asr Rx(result_reg), Rx(result_reg), #floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
3907+
| asr Rx(result_reg), Rx(result_reg), #zend_long_floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
39083908
#if 0
39093909
/* x86 specific optimizations through LEA instraction are not supported on ARM */
39103910
} else if (opcode == ZEND_ADD &&

ext/opcache/jit/zend_jit_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef ZEND_JIT_INTERNAL_H
2222
#define ZEND_JIT_INTERNAL_H
2323

24+
#include "zend_bitset.h"
25+
2426
/* Register Set */
2527
#define ZEND_REGSET_EMPTY 0
2628

@@ -743,10 +745,10 @@ static zend_always_inline bool zend_long_is_power_of_two(zend_long x)
743745
return (x > 0) && !(x & (x - 1));
744746
}
745747

746-
static zend_always_inline uint32_t zend_long_floor_log2(uint64_t x)
748+
static zend_always_inline uint32_t zend_long_floor_log2(zend_long x)
747749
{
748750
ZEND_ASSERT(zend_long_is_power_of_two(x));
749-
return __builtin_ctzll(x);
751+
return zend_ulong_ntz(x);
750752
}
751753

752754
/* from http://aggregate.org/MAGIC/ */

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,10 +4212,9 @@ static int zend_jit_math_long_long(dasm_State **Dst,
42124212
Z_MODE(op2_addr) == IS_CONST_ZVAL &&
42134213
!may_overflow &&
42144214
Z_LVAL_P(Z_ZV(op2_addr)) > 0 &&
4215-
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op2_addr))) &&
4216-
is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr)))) {
4215+
zend_long_is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr)))) {
42174216
| GET_ZVAL_LVAL result_reg, op1_addr
4218-
| shl Ra(result_reg), floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
4217+
| shl Ra(result_reg), zend_long_floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
42194218
} else if (opcode == ZEND_MUL &&
42204219
Z_MODE(op1_addr) == IS_CONST_ZVAL &&
42214220
Z_LVAL_P(Z_ZV(op1_addr)) == 2) {
@@ -4229,15 +4228,14 @@ static int zend_jit_math_long_long(dasm_State **Dst,
42294228
Z_MODE(op1_addr) == IS_CONST_ZVAL &&
42304229
!may_overflow &&
42314230
Z_LVAL_P(Z_ZV(op1_addr)) > 0 &&
4232-
IS_SIGNED_32BIT(Z_LVAL_P(Z_ZV(op1_addr))) &&
4233-
is_power_of_two(Z_LVAL_P(Z_ZV(op1_addr)))) {
4231+
zend_long_is_power_of_two(Z_LVAL_P(Z_ZV(op1_addr)))) {
42344232
| GET_ZVAL_LVAL result_reg, op2_addr
4235-
| shl Ra(result_reg), floor_log2(Z_LVAL_P(Z_ZV(op1_addr)))
4233+
| shl Ra(result_reg), zend_long_floor_log2(Z_LVAL_P(Z_ZV(op1_addr)))
42364234
} else if (opcode == ZEND_DIV &&
42374235
(Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4238-
is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr))))) {
4236+
zend_long_is_power_of_two(Z_LVAL_P(Z_ZV(op2_addr))))) {
42394237
| GET_ZVAL_LVAL result_reg, op1_addr
4240-
| shr Ra(result_reg), floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
4238+
| shr Ra(result_reg), zend_long_floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
42414239
} else if (opcode == ZEND_ADD &&
42424240
!may_overflow &&
42434241
Z_MODE(op1_addr) == IS_REG &&

0 commit comments

Comments
 (0)