Skip to content

Commit

Permalink
Move avx check into a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 27, 2020
1 parent f4e1768 commit 4a7ebb6
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ static void* dasm_labels[zend_lb_MAX];

#define BP_JIT_IS 6

#define CAN_USE_AVX() (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX)

|.macro LOAD_ADDR, reg, addr
| .if X64
|| if (IS_32BIT(addr)) {
Expand Down Expand Up @@ -544,7 +546,7 @@ static void* dasm_labels[zend_lb_MAX];
|.endmacro

|.macro SSE_AVX_INS, sse_ins, avx_ins, op1, op2
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| avx_ins op1, op2
|| } else {
| sse_ins op1, op2
Expand Down Expand Up @@ -586,7 +588,7 @@ static void* dasm_labels[zend_lb_MAX];

|.macro SSE_GET_LONG, reg, lval
|| if (lval == 0) {
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
|| } else {
| xorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
Expand All @@ -601,7 +603,7 @@ static void* dasm_labels[zend_lb_MAX];
|.else
| mov r0, lval
|.endif
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
| vcvtsi2sd, xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), r0
|| } else {
Expand All @@ -615,15 +617,15 @@ static void* dasm_labels[zend_lb_MAX];
|| if (Z_MODE(addr) == IS_CONST_ZVAL) {
| SSE_GET_LONG reg, Z_LVAL_P(Z_ZV(addr))
|| } else if (Z_MODE(addr) == IS_MEM_ZVAL) {
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
| vcvtsi2sd xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), aword [Ra(Z_REG(addr))+Z_OFFSET(addr)]
|| } else {
| xorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
| cvtsi2sd xmm(reg-ZREG_XMM0), aword [Ra(Z_REG(addr))+Z_OFFSET(addr)]
|| }
|| } else if (Z_MODE(addr) == IS_REG) {
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0)
| vcvtsi2sd xmm(reg-ZREG_XMM0), xmm(reg-ZREG_XMM0), Ra(Z_REG(addr))
|| } else {
Expand Down Expand Up @@ -903,7 +905,7 @@ static void* dasm_labels[zend_lb_MAX];
|| if (Z_TYPE_P(zv) == IS_DOUBLE) {
|| zend_reg dst_reg = (Z_MODE(dst_addr) == IS_REG) ? Z_REG(dst_addr) : ZREG_XMM0;
|| if (Z_DVAL_P(zv) == 0.0 && !is_signed(Z_DVAL_P(zv))) {
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0)
|| } else {
| xorps xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0)
Expand Down Expand Up @@ -957,7 +959,7 @@ static void* dasm_labels[zend_lb_MAX];
|| zend_reg dst_reg = (Z_MODE(dst_addr) == IS_REG) ?
|| Z_REG(dst_addr) : ((Z_MODE(res_addr) == IS_REG) ? Z_MODE(res_addr) : ZREG_XMM0);
|| if (Z_DVAL_P(zv) == 0.0 && !is_signed(Z_DVAL_P(zv))) {
|| if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
|| if (CAN_USE_AVX()) {
| vxorps xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0)
|| } else {
| xorps xmm(dst_reg-ZREG_XMM0), xmm(dst_reg-ZREG_XMM0)
Expand Down Expand Up @@ -4128,13 +4130,13 @@ static int zend_jit_inc_dec(dasm_State **Dst, const zend_op *opline, uint32_t op
}
| SSE_GET_ZVAL_DVAL tmp_reg, op1_addr
if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) {
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| vaddsd xmm(tmp_reg-ZREG_XMM0), xmm(tmp_reg-ZREG_XMM0), qword [->one]
} else {
| addsd xmm(tmp_reg-ZREG_XMM0), qword [->one]
}
} else {
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| vsubsd xmm(tmp_reg-ZREG_XMM0), xmm(tmp_reg-ZREG_XMM0), qword [->one]
} else {
| subsd xmm(tmp_reg-ZREG_XMM0), qword [->one]
Expand Down Expand Up @@ -4330,7 +4332,7 @@ static int zend_jit_math_long_long(dasm_State **Dst,

| SSE_GET_ZVAL_LVAL tmp_reg1, op1_addr
| SSE_GET_ZVAL_LVAL tmp_reg2, op2_addr
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| AVX_MATH_REG opcode, tmp_reg1, tmp_reg1, tmp_reg2
} else {
| SSE_MATH_REG opcode, tmp_reg1, tmp_reg2
Expand Down Expand Up @@ -4366,13 +4368,13 @@ static int zend_jit_math_long_double(dasm_State **Dst,

if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_R0) {
/* ASSIGN_DIM_OP */
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| AVX_MATH opcode, result_reg, result_reg, op2_addr, r1
} else {
| SSE_MATH opcode, result_reg, op2_addr, r1
}
} else {
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| AVX_MATH opcode, result_reg, result_reg, op2_addr, r0
} else {
| SSE_MATH opcode, result_reg, op2_addr, r0
Expand Down Expand Up @@ -4408,13 +4410,13 @@ static int zend_jit_math_double_long(dasm_State **Dst,
| SSE_GET_ZVAL_LVAL result_reg, op2_addr
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_R0) {
/* ASSIGN_DIM_OP */
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| AVX_MATH opcode, result_reg, result_reg, op1_addr, r1
} else {
| SSE_MATH opcode, result_reg, op1_addr, r1
}
} else {
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| AVX_MATH opcode, result_reg, result_reg, op1_addr, r0
} else {
| SSE_MATH opcode, result_reg, op1_addr, r0
Expand All @@ -4433,7 +4435,7 @@ static int zend_jit_math_double_long(dasm_State **Dst,
result_reg = ZREG_XMM0;
tmp_reg = ZREG_XMM1;
}
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
zend_reg op1_reg;

if (Z_MODE(op1_addr) == IS_REG) {
Expand Down Expand Up @@ -4495,7 +4497,7 @@ static int zend_jit_math_double_double(dasm_State **Dst,
result_reg = ZREG_XMM0;
}

if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
zend_reg op1_reg;
zend_jit_addr val_addr;

Expand Down Expand Up @@ -8424,7 +8426,7 @@ static int zend_jit_bool_jmpznz(dasm_State **Dst, const zend_op *opline, uint32_
}

if ((op1_info & MAY_BE_ANY) == MAY_BE_DOUBLE) {
if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) {
if (CAN_USE_AVX()) {
| vxorps xmm0, xmm0, xmm0
} else {
| xorps xmm0, xmm0
Expand Down

0 comments on commit 4a7ebb6

Please sign in to comment.