Skip to content

Commit 1030ff5

Browse files
committed
Use cheaper code for scalar type check
1 parent 6e226c1 commit 1030ff5

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8967,13 +8967,18 @@ static int zend_jit_recv(dasm_State **Dst, const zend_op *opline, zend_op_array
89678967
| add r0, offsetof(zend_reference, val)
89688968
}
89698969
if (!ZEND_TYPE_IS_CLASS(type)) {
8970-
// TODO: Use bt?
89718970
uint32_t type_mask = ZEND_TYPE_MASK(type);
8972-
| mov edx, 1
8973-
| mov cl, byte [r0 + 8]
8974-
| shl edx, cl
8975-
| test edx, type_mask
8976-
| je >8
8971+
if (is_power_of_two(type_mask)) {
8972+
uint32_t type_code = concrete_type(type_mask);
8973+
| cmp byte [r0 + 8], type_code
8974+
| jne >8
8975+
} else {
8976+
| mov edx, 1
8977+
| mov cl, byte [r0 + 8]
8978+
| shl edx, cl
8979+
| test edx, type_mask
8980+
| je >8
8981+
}
89778982
} else {
89788983
| SAVE_VALID_OPLINE opline
89798984
| cmp byte [r0 + 8], IS_OBJECT
@@ -9111,12 +9116,18 @@ static int zend_jit_recv_init(dasm_State **Dst, const zend_op *opline, zend_op_a
91119116
| LOAD_ZVAL_ADDR r0, res_addr
91129117
| ZVAL_DEREF r0, MAY_BE_REF
91139118
if (!ZEND_TYPE_IS_CLASS(arg_info->type)) {
9114-
// TODO: Use bt?
9115-
| mov edx, 1
9116-
| mov cl, byte [r0 + 8]
9117-
| shl edx, cl
9118-
| test edx, ZEND_TYPE_MASK(arg_info->type)
9119-
| je >8
9119+
uint32_t type_mask = ZEND_TYPE_MASK(arg_info->type);
9120+
if (is_power_of_two(type_mask)) {
9121+
uint32_t type_code = concrete_type(type_mask);
9122+
| cmp byte [r0 + 8], type_code
9123+
| jne >8
9124+
} else {
9125+
| mov edx, 1
9126+
| mov cl, byte [r0 + 8]
9127+
| shl edx, cl
9128+
| test edx, type_mask
9129+
| je >8
9130+
}
91209131
} else {
91219132
| cmp byte [r0 + 8], IS_OBJECT
91229133
| jne >8

0 commit comments

Comments
 (0)