tcg: Add min/max opcodes
cover tcg: Add min/max opcodes
Since two hosts now have (optional) support for min/max, I thought it might be worth implementing natively.
While I was there, use some more of the FEAT_CSSC extension.
r~
Richard Henderson (7):
tcg: Add integer min/max opcodes
tcg/optimize: Handle min/max opcodes
util/cpuinfo-aarch64: Detect FEAT_CSSC
tcg/aarch64: Implement min/max with FEAT_CSSC
target/riscv64: Implement min/max with Zbb
tcg/aarch64: Implement ctpop with FEAT_CSSC
tcg/aarch64: Use CTZ from FEAT_CSSC
host/include/aarch64/host/cpuinfo.h | 1 + include/tcg/tcg-opc.h | 4 + tcg/aarch64/tcg-target-con-set.h | 2 + tcg/aarch64/tcg-target-con-str.h | 2 + tcg/optimize.c | 52 +++++++++ tcg/tcg-op.c | 48 ++++++-- tcg/tcg.c | 4 + util/cpuinfo-aarch64.c | 13 ++- docs/devel/tcg-ops.rst | 14 ++- tcg/aarch64/tcg-target.c.inc | 169 ++++++++++++++++++++++++++-- tcg/loongarch64/tcg-target.c.inc | 16 +++ tcg/ppc64/tcg-target.c.inc | 16 +++ tcg/riscv64/tcg-target.c.inc | 52 +++++++++ tcg/s390x/tcg-target.c.inc | 16 +++ tcg/sparc64/tcg-target.c.inc | 16 +++ tcg/tci/tcg-target.c.inc | 16 +++ tcg/x86_64/tcg-target.c.inc | 16 +++ 17 files changed, 435 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/7 tcg: Add integer min/max opcodes
We already have these for vectors; replicate for integers.
--- include/tcg/tcg-opc.h | 4 +++ tcg/tcg-op.c | 48 ++++++++++++++++++++++++++------ tcg/tcg.c | 4 +++ docs/devel/tcg-ops.rst | 14 +++++++++- tcg/aarch64/tcg-target.c.inc | 16 +++++++++++ tcg/loongarch64/tcg-target.c.inc | 16 +++++++++++ tcg/ppc64/tcg-target.c.inc | 16 +++++++++++ tcg/riscv64/tcg-target.c.inc | 16 +++++++++++ tcg/s390x/tcg-target.c.inc | 16 +++++++++++ tcg/sparc64/tcg-target.c.inc | 16 +++++++++++ tcg/tci/tcg-target.c.inc | 16 +++++++++++ tcg/x86_64/tcg-target.c.inc | 16 +++++++++++ 12 files changed, 189 insertions(+), 9 deletions(-)
include/tcg/tcg-opc.h +4 -0
@@ -89,11 +89,15 @@ DEF(setcond, 1, 2, 1, TCG_OPF_INT) DEF(sextract, 1, 1, 2, TCG_OPF_INT) DEF(shl, 1, 2, 0, TCG_OPF_INT) DEF(shr, 1, 2, 0, TCG_OPF_INT) +DEF(smax, 1, 2, 0, TCG_OPF_INT) +DEF(smin, 1, 2, 0, TCG_OPF_INT) DEF(st8, 0, 2, 1, TCG_OPF_INT) DEF(st16, 0, 2, 1, TCG_OPF_INT) DEF(st32, 0, 2, 1, TCG_OPF_INT) DEF(st, 0, 2, 1, TCG_OPF_INT) DEF(sub, 1, 2, 0, TCG_OPF_INT) +DEF(umax, 1, 2, 0, TCG_OPF_INT) +DEF(umin, 1, 2, 0, TCG_OPF_INT) DEF(xor, 1, 2, 0, TCG_OPF_INT)DEF (addco,1 ,2 ,0 ,TCG_OPF_INT |TCG_OPF_CARRY_OUT )
tcg/tcg-op.c +40 -8
84 lines not on this page · raw message
tcg/tcg.c +4 -0
@@ -5512,6 +5512,10 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)case INDEX_op_sar:case INDEX_op_shl:case INDEX_op_shr: +case INDEX_op_smax: +case INDEX_op_smin: +case INDEX_op_umax: +case INDEX_op_umin:case INDEX_op_xor: { const TCGOutOpBinary *out =
docs/devel/tcg-ops.rst +13 -1
@@ -317,6 +317,18 @@ Arithmetic pass 0 to *nh* to make a simple zero-extension of *nl*, so overflow should never occur. + * - smax *t0*, *t1*, *t2* + + umax *t0*, *t1*, *t2* + + - | *t0* = MAX(*t1*, *t2*), for signed and unsigned integers. + + * - smin *t0*, *t1*, *t2* + + umin *t0*, *t1*, *t2* + + - | *t0* = MIN(*t1*, *t2*), for signed and unsigned integers. + Logical -------
@@ -512,7 +524,7 @@ Misc - | Reverse the 64 bits of input *t1* with output in *dest*. -Conditional moves +Conditional motes ----------------- .. list-table::
tcg/aarch64/tcg-target.c.inc +16 -0
@@ -2592,6 +2592,22 @@ static void tcg_out_set_borrow(TCGContext *s) TCG_REG_XZR, TCG_REG_XZR, TCG_REG_XZR); } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/loongarch64/tcg-target.c.inc +16 -0
@@ -1804,6 +1804,22 @@ static void tcg_out_set_borrow(TCGContext *s) g_assert_not_reached(); } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/ppc64/tcg-target.c.inc +16 -0
@@ -3281,6 +3281,22 @@ static void tcg_out_set_borrow(TCGContext *s) tcg_out32(s, ADDIC | TAI(TCG_REG_R0, TCG_REG_R0, 0)); } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/riscv64/tcg-target.c.inc +16 -0
@@ -2404,6 +2404,22 @@ static void tcg_out_set_borrow(TCGContext *s) g_assert_not_reached(); } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/s390x/tcg-target.c.inc +16 -0
@@ -2950,6 +2950,22 @@ static void tcg_out_set_borrow(TCGContext *s) tcg_out_insn(s, RR, CLR, TCG_REG_R0, TCG_REG_R0); /* cc = 0 */ } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/sparc64/tcg-target.c.inc +16 -0
@@ -1917,6 +1917,22 @@ static void tcg_out_set_borrow(TCGContext *s) tcg_out_set_carry(s); /* borrow == carry */ } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/tci/tcg-target.c.inc +16 -0
@@ -894,6 +894,22 @@ static void tcg_out_set_borrow(TCGContext *s) tcg_out_op_v(s, INDEX_op_tci_setcarry); /* borrow == carry */ } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
tcg/x86_64/tcg-target.c.inc +16 -0
@@ -2977,6 +2977,22 @@ static void tcg_out_set_borrow(TCGContext *s) tcg_out8(s, OPC_STC); } +static const TCGOutOpBinary outop_smax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_smin = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umax = { + .base.static_constraint = C_NotImplemented, +}; + +static const TCGOutOpBinary outop_umin = { + .base.static_constraint = C_NotImplemented, +}; + static void tgen_xor(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) {
Signature · 1 line
2.43.0
Re: [PATCH 1/7] tcg: Add integer min/max opcodes
Quoted 167 lines · Richard Henderson
We already have these for vectors; replicate for integers.
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg-opc.h | 4 +++ tcg/tcg-op.c | 48 ++++++++++++++++++++++++++------ tcg/tcg.c | 4 +++ docs/devel/tcg-ops.rst | 14 +++++++++- tcg/aarch64/tcg-target.c.inc | 16 +++++++++++ tcg/loongarch64/tcg-target.c.inc | 16 +++++++++++ tcg/ppc64/tcg-target.c.inc | 16 +++++++++++ tcg/riscv64/tcg-target.c.inc | 16 +++++++++++ tcg/s390x/tcg-target.c.inc | 16 +++++++++++ tcg/sparc64/tcg-target.c.inc | 16 +++++++++++ tcg/tci/tcg-target.c.inc | 16 +++++++++++ tcg/x86_64/tcg-target.c.inc | 16 +++++++++++ 12 files changed, 189 insertions(+), 9 deletions(-)include/tcg/tcg-opc.h +4
-0@@ -89,11 +89,15 @@ DEF(setcond, 1, 2, 1, TCG_OPF_INT) DEF(sextract, 1, 1, 2, TCG_OPF_INT) DEF(shl, 1, 2, 0, TCG_OPF_INT) DEF(shr, 1, 2, 0, TCG_OPF_INT) +DEF(smax, 1, 2, 0, TCG_OPF_INT) +DEF(smin, 1, 2, 0, TCG_OPF_INT) DEF(st8, 0, 2, 1, TCG_OPF_INT) DEF(st16, 0, 2, 1, TCG_OPF_INT) DEF(st32, 0, 2, 1, TCG_OPF_INT) DEF(st, 0, 2, 1, TCG_OPF_INT) DEF(sub, 1, 2, 0, TCG_OPF_INT) +DEF(umax, 1, 2, 0, TCG_OPF_INT) +DEF(umin, 1, 2, 0, TCG_OPF_INT) DEF(xor, 1, 2, 0, TCG_OPF_INT)DEF (addco,1 ,2 ,0 ,TCG_OPF_INT |TCG_OPF_CARRY_OUT )tcg/tcg-op.c +40
-8@@ -1294,22 +1294,38 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)void tcg_gen_smin_i32 (TCGv_i32 ret,TCGv_i32 a,TCGv_i32 b) { -tcg_gen_movcond_i32 (TCG_COND_LT , ret, a, b, a, b); +if (tcg_op_supported (INDEX_op_smin,TCG_TYPE_I32 ,0 )) { +tcg_gen_op3_i32 (INDEX_op_smin, ret, a, b); + }else { +tcg_gen_movcond_i32 (TCG_COND_LT , ret, a, b, a, b); + } }void tcg_gen_umin_i32 (TCGv_i32 ret,TCGv_i32 a,TCGv_i32 b) { -tcg_gen_movcond_i32 (TCG_COND_LTU , ret, a, b, a, b); +if (tcg_op_supported (INDEX_op_umin,TCG_TYPE_I32 ,0 )) { +tcg_gen_op3_i32 (INDEX_op_umin, ret, a, b); + }else { +tcg_gen_movcond_i32 (TCG_COND_LTU , ret, a, b, a, b); + } }void tcg_gen_smax_i32 (TCGv_i32 ret,TCGv_i32 a,TCGv_i32 b) { -tcg_gen_movcond_i32 (TCG_COND_LT , ret, a, b, b, a); +if (tcg_op_supported (INDEX_op_smax,TCG_TYPE_I32 ,0 )) { +tcg_gen_op3_i32 (INDEX_op_smax, ret, a, b); + }else { +tcg_gen_movcond_i32 (TCG_COND_LT , ret, a, b, b, a); + } }void tcg_gen_umax_i32 (TCGv_i32 ret,TCGv_i32 a,TCGv_i32 b) { -tcg_gen_movcond_i32 (TCG_COND_LTU , ret, a, b, b, a); +if (tcg_op_supported (INDEX_op_umax,TCG_TYPE_I32 ,0 )) { +tcg_gen_op3_i32 (INDEX_op_umax, ret, a, b); + }else { +tcg_gen_movcond_i32 (TCG_COND_LTU , ret, a, b, b, a); + } }void tcg_gen_abs_i32 (TCGv_i32 ret,TCGv_i32 a)@@ -2473,22 +2489,38 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)void tcg_gen_smin_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b) { -tcg_gen_movcond_i64 (TCG_COND_LT , ret, a, b, a, b); +if (tcg_op_supported (INDEX_op_smin,TCG_TYPE_I64 ,0 )) { +tcg_gen_op3_i64 (INDEX_op_smin, ret, a, b); + }else { +tcg_gen_movcond_i64 (TCG_COND_LT , ret, a, b, a, b); + } }void tcg_gen_umin_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b) { -tcg_gen_movcond_i64 (TCG_COND_LTU , ret, a, b, a, b); +if (tcg_op_supported (INDEX_op_umin,TCG_TYPE_I64 ,0 )) { +tcg_gen_op3_i64 (INDEX_op_umin, ret, a, b); + }else { +tcg_gen_movcond_i64 (TCG_COND_LTU , ret, a, b, a, b); + } }void tcg_gen_smax_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b) { -tcg_gen_movcond_i64 (TCG_COND_LT , ret, a, b, b, a); +if (tcg_op_supported (INDEX_op_smax,TCG_TYPE_I64 ,0 )) { +tcg_gen_op3_i64 (INDEX_op_smax, ret, a, b); + }else { +tcg_gen_movcond_i64 (TCG_COND_LT , ret, a, b, b, a); + } }void tcg_gen_umax_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b) { -tcg_gen_movcond_i64 (TCG_COND_LTU , ret, a, b, b, a); +if (tcg_op_supported (INDEX_op_umax,TCG_TYPE_I64 ,0 )) { +tcg_gen_op3_i64 (INDEX_op_umax, ret, a, b); + }else { +tcg_gen_movcond_i64 (TCG_COND_LTU , ret, a, b, b, a); + } }void tcg_gen_abs_i64 (TCGv_i64 ret,TCGv_i64 a)tcg/tcg.c +4
-0@@ -5512,6 +5512,10 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)case INDEX_op_sar:case INDEX_op_shl:case INDEX_op_shr: +case INDEX_op_smax: +case INDEX_op_smin: +case INDEX_op_umax: +case INDEX_op_umin:case INDEX_op_xor: { const TCGOutOpBinary *out =docs/devel/tcg-ops.rst +12
-0@@ -317,6 +317,18 @@ Arithmetic pass 0 to *nh* to make a simple zero-extension of *nl*, so overflow should never occur. + * - smax *t0*, *t1*, *t2* + + umax *t0*, *t1*, *t2* + + - | *t0* = MAX(*t1*, *t2*), for signed and unsigned integers. + + * - smin *t0*, *t1*, *t2* + + umin *t0*, *t1*, *t2* + + - | *t0* = MIN(*t1*, *t2*), for signed and unsigned integers. + Logical -------
docs/devel/tcg-ops.rst Misc · line 528
Quoted 6 lines
docs/devel/tcg-ops.rst +1
-1@@ -512,7 +524,7 @@ Misc - | Reverse the 64 bits of input *t1* with output in *dest*. -Conditional moves +Conditional motes -----------------
A typo snuck in....
Otherwise:
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 2/7 tcg/optimize: Handle min/max opcodes
In reply to Richard Henderson--- tcg/optimize.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
tcg/optimize.c +52 -0
@@ -597,6 +597,30 @@ static uint64_t do_constant_folding_2(TCGOpcode op, TCGType type, }return (uint64_t )x % ((uint64_t )y ? :1 ); +case INDEX_op_smax: +if (type ==TCG_TYPE_I32 ) { +return MAX ((int32_t )x, (int32_t )y); + } +return MAX ((int64_t )x, (int64_t )y); + +case INDEX_op_smin: +if (type ==TCG_TYPE_I32 ) { +return MIN ((int32_t )x, (int32_t )y); + } +return MIN ((int64_t )x, (int64_t )y); + +case INDEX_op_umax: +if (type ==TCG_TYPE_I32 ) { +return MAX ((uint32_t )x, (uint32_t )y); + } +return MAX ((uint64_t )x, (uint64_t )y); + +case INDEX_op_umin: +if (type ==TCG_TYPE_I32 ) { +return MIN ((uint32_t )x, (uint32_t )y); + } +return MIN ((uint64_t )x, (uint64_t )y); +default :g_assert_not_reached (); }
@@ -2101,6 +2125,16 @@ static bool fold_mb(OptContext *ctx, TCGOp *op)return true; } +static bool fold_minmax (OptContext *ctx,TCGOp *op,uint64_t bound) +{ +if (fold_const2_commutative (ctx, op) || +fold_xi_to_i (ctx, op, bound) || +fold_xx_to_x (ctx, op)) { +return true; + } +return finish_folding (ctx, op); +} +static bool fold_mov (OptContext *ctx,TCGOp *op) {return tcg_opt_gen_mov (ctx, op, op->args[0 ], op->args[1 ]);
@@ -3258,6 +3292,14 @@ void tcg_optimize(TCGContext *s)case INDEX_op_sextract: done =fold_sextract (&ctx, op);break ; +case INDEX_op_smax: + done =fold_minmax (&ctx, op, (ctx.type ==TCG_TYPE_I32 + ?INT32_MAX :INT64_MAX )); +break ; +case INDEX_op_smin: + done =fold_minmax (&ctx, op, (ctx.type ==TCG_TYPE_I32 + ?INT32_MIN :INT64_MIN )); +break ;case INDEX_op_sub: done =fold_sub (&ctx, op);break ;
@@ -3273,6 +3315,16 @@ void tcg_optimize(TCGContext *s)case INDEX_op_sub_vec: done =fold_sub_vec (&ctx, op);break ; +case INDEX_op_umax: +/* +* Note that 32-bit constants are stored sign extended, +* so (int32_t)UINT32_MAX == -1. +*/ + done =fold_minmax (&ctx, op,-1 ); +break ; +case INDEX_op_umin: + done =fold_minmax (&ctx, op,0 ); +break ;case INDEX_op_xor:case INDEX_op_xor_vec: done =fold_xor (&ctx, op);
Signature · 1 line
2.43.0
Re: [PATCH 2/7] tcg/optimize: Handle min/max opcodes
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/optimize.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
Re: [PATCH 2/7] tcg/optimize: Handle min/max opcodes
In reply to Richard HendersonQuoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 3/7 util/cpuinfo-aarch64: Detect FEAT_CSSC
In reply to Richard Henderson--- host/include/aarch64/host/cpuinfo.h | 1 + util/cpuinfo-aarch64.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
host/include/aarch64/host/cpuinfo.h +1 -0
@@ -12,6 +12,7 @@#define CPUINFO_AES (1u << 3)#define CPUINFO_PMULL (1u << 4)#define CPUINFO_BTI (1u << 5) +#define CPUINFO_CSSC (1u << 6)/* Initialized with a constructor. */ extern unsigned cpuinfo;
util/cpuinfo-aarch64.c +12 -1
@@ -72,6 +72,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)unsigned long hwcap2 =qemu_getauxval (AT_HWCAP2 ); info |= (hwcap2 &HWCAP2_BTI ?CPUINFO_BTI :0 ); + info |= (hwcap2 &HWCAP2_CSSC ?CPUINFO_CSSC :0 );#endif #ifdef CONFIG_DARWIN info |=sysctl_for_bool ("hw.optional.arm.FEAT_LSE" ) *CPUINFO_LSE ;
@@ -79,10 +80,11 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |=sysctl_for_bool ("hw.optional.arm.FEAT_AES" ) *CPUINFO_AES ; info |=sysctl_for_bool ("hw.optional.arm.FEAT_PMULL" ) *CPUINFO_PMULL ; info |=sysctl_for_bool ("hw.optional.arm.FEAT_BTI" ) *CPUINFO_BTI ; + info |=sysctl_for_bool ("hw.optional.arm.FEAT_CSSC" ) *CPUINFO_CSSC ;#endif #if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO )int mib[2 ]; -uint64_t isar0; +uint64_t isar0, isar2;uint64_t pfr1;size_t len;
@@ -101,6 +103,15 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) } } + mib[0 ] =CTL_MACHDEP ; + mib[1 ] =CPU_ID_AA64ISAR2 ; + len =sizeof (isar2); +if (sysctl (mib,2 , &isar2, &len,NULL ,0 ) !=-1 ) { +if (ID_AA64ISAR2_CSSC (isar2) >=ID_AA64ISAR2_CSSC_IMPL ) { + info |=CPUINFO_CSSC ; + } + } + mib[0 ] =CTL_MACHDEP ; mib[1 ] =CPU_ID_AA64PFR1 ; len =sizeof (pfr1);
Signature · 1 line
2.43.0
Re: [PATCH 3/7] util/cpuinfo-aarch64: Detect FEAT_CSSC
Quoted 49 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- host/include/aarch64/host/cpuinfo.h | 1 + util/cpuinfo-aarch64.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)host/include/aarch64/host/cpuinfo.h +1
-0@@ -12,6 +12,7 @@#define CPUINFO_AES (1u << 3)#define CPUINFO_PMULL (1u << 4)#define CPUINFO_BTI (1u << 5) +#define CPUINFO_CSSC (1u << 6)/* Initialized with a constructor. */ extern unsigned cpuinfo;util/cpuinfo-aarch64.c +5
-1@@ -72,6 +72,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)unsigned long hwcap2 =qemu_getauxval (AT_HWCAP2 ); info |= (hwcap2 &HWCAP2_BTI ?CPUINFO_BTI :0 ); + info |= (hwcap2 &HWCAP2_CSSC ?CPUINFO_CSSC :0 );#endif #ifdef CONFIG_DARWIN info |=sysctl_for_bool ("hw.optional.arm.FEAT_LSE" ) *CPUINFO_LSE ;@@ -79,10 +80,11 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |=sysctl_for_bool ("hw.optional.arm.FEAT_AES" ) *CPUINFO_AES ; info |=sysctl_for_bool ("hw.optional.arm.FEAT_PMULL" ) *CPUINFO_PMULL ; info |=sysctl_for_bool ("hw.optional.arm.FEAT_BTI" ) *CPUINFO_BTI ; + info |=sysctl_for_bool ("hw.optional.arm.FEAT_CSSC" ) *CPUINFO_CSSC ;#endif #if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO )int mib[2 ]; -uint64_t isar0; +uint64_t isar0, isar2;uint64_t pfr1;size_t len;@@ -101,6 +103,15 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) } } + mib[0 ] =CTL_MACHDEP ; + mib[1 ] =CPU_ID_AA64ISAR2 ;
util/cpuinfo-aarch64.c unsigned __attribute__((constructor)) cpuinfo_init(void) · line 117
Quoted 10 lines
util/cpuinfo-aarch64.c +7
-0+ len =sizeof (isar2); +if (sysctl (mib,2 , &isar2, &len,NULL ,0 ) !=-1 ) { +if (ID_AA64ISAR2_CSSC (isar2) >=ID_AA64ISAR2_CSSC_IMPL ) { + info |=CPUINFO_CSSC ; + } + } + mib[0 ] =CTL_MACHDEP ; mib[1 ] =CPU_ID_AA64PFR1 ; len =sizeof (pfr1);
You can remove the bottom chunk. Any OpenBSD release that has the ID_AA64ISAR2_CSSC and ID_AA64ISAR2_CSSC_IMPL constants is also covered by elf_aux_info() which is the first chunk.
ID_AA64ISAR2_CSSC_IMPL
Re: [PATCH 3/7] util/cpuinfo-aarch64: Detect FEAT_CSSC
Quoted 11 lines · Brad Smith
Quoted 11 lines
util/cpuinfo-aarch64.c +8
-0@@ -101,6 +103,15 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) } } + mib[0] = CTL_MACHDEP; + mib[1] = CPU_ID_AA64ISAR2; + len = sizeof(isar2); + if (sysctl(mib, 2, &isar2, &len, NULL, 0) != -1) { + if (ID_AA64ISAR2_CSSC(isar2) >= ID_AA64ISAR2_CSSC_IMPL) { + info |= CPUINFO_CSSC; + } + }
Quoted 8 lines
util/cpuinfo-aarch64.c unsigned __attribute__((constructor)) cpuinfo_init(void) · line 117
Quoted 4 lines
util/cpuinfo-aarch64.c +1
-0+ mib[0] = CTL_MACHDEP; mib[1] = CPU_ID_AA64PFR1; len = sizeof(pfr1);You can remove the bottom chunk. Any OpenBSD release that has the
ID_AA64ISAR2_CSSCandID_AA64ISAR2_CSSC_IMPLconstants is also covered byelf_aux_info()which is the first chunk.
Right-o. Thanks!
r~
PATCH 4/7 tcg/aarch64: Implement min/max with FEAT_CSSC
In reply to Richard Henderson--- tcg/aarch64/tcg-target-con-set.h | 2 + tcg/aarch64/tcg-target-con-str.h | 2 + tcg/aarch64/tcg-target.c.inc | 103 +++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 4 deletions(-)
tcg/aarch64/tcg-target-con-set.h +2 -0
@@ -24,6 +24,8 @@ C_O1_I2(r, r, rAL) C_O1_I2(r, r, rC) C_O1_I2(r, r, ri) C_O1_I2(r, r, rL) +C_O1_I2(r, r, rS) +C_O1_I2(r, r, rU) C_O1_I2(r, rZ, rA) C_O1_I2(r, rz, rMZ)C_O1_I2 (r, rz, rz)
tcg/aarch64/tcg-target-con-str.h +2 -0
@@ -21,4 +21,6 @@ CONST('L', TCG_CT_CONST_LIMM) CONST('M', TCG_CT_CONST_MONE) CONST('O', TCG_CT_CONST_ORRI) CONST('N', TCG_CT_CONST_ANDI) +CONST('S', TCG_CT_CONST_S8) +CONST('U', TCG_CT_CONST_U8)CONST ('Z' ,TCG_CT_CONST_ZERO )
tcg/aarch64/tcg-target.c.inc +99 -4
149 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 4/7] tcg/aarch64: Implement min/max with FEAT_CSSC
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target-con-set.h | 2 + tcg/aarch64/tcg-target-con-str.h | 2 + tcg/aarch64/tcg-target.c.inc | 103 +++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 4 deletions(-)
PATCH 5/7 target/riscv64: Implement min/max with Zbb
In reply to Richard Henderson--- tcg/riscv64/tcg-target.c.inc | 44 ++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-)
tcg/riscv64/tcg-target.c.inc +40 -4
@@ -233,6 +233,10 @@ typedef enum { OPC_CPOPW = 0x6020101b, OPC_CTZ = 0x60101013, OPC_CTZW = 0x6010101b, + OPC_MAX = 0x0a006033, + OPC_MAXU = 0x0a007033, + OPC_MIN = 0x0a004033, + OPC_MINU = 0x0a005033, OPC_ORN = 0x40006033, OPC_REV8 = 0x6b805013, OPC_ROL = 0x60001033,
@@ -2404,20 +2408,52 @@ static void tcg_out_set_borrow(TCGContext *s) g_assert_not_reached(); } +static void tgen_smax(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, TCGReg a2) +{ + tcg_out_opc_reg(s, OPC_MAX, a0, a1, a2); +} + static const TCGOutOpBinary outop_smax = { - .base.static_constraint = C_NotImplemented, + .base.static_constraint = C_Dynamic, + .base.dynamic_constraint = cset_zbb_rrr, + .out_rrr = tgen_smax, }; +static void tgen_smin(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, TCGReg a2) +{ + tcg_out_opc_reg(s, OPC_MIN, a0, a1, a2); +} + static const TCGOutOpBinary outop_smin = { - .base.static_constraint = C_NotImplemented, + .base.static_constraint = C_Dynamic, + .base.dynamic_constraint = cset_zbb_rrr, + .out_rrr = tgen_smin, }; +static void tgen_umax(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, TCGReg a2) +{ + tcg_out_opc_reg(s, OPC_MAXU, a0, a1, a2); +} + static const TCGOutOpBinary outop_umax = { - .base.static_constraint = C_NotImplemented, + .base.static_constraint = C_Dynamic, + .base.dynamic_constraint = cset_zbb_rrr, + .out_rrr = tgen_umax, }; +static void tgen_umin(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, TCGReg a2) +{ + tcg_out_opc_reg(s, OPC_MINU, a0, a1, a2); +} + static const TCGOutOpBinary outop_umin = { - .base.static_constraint = C_NotImplemented, + .base.static_constraint = C_Dynamic, + .base.dynamic_constraint = cset_zbb_rrr, + .out_rrr = tgen_umin, }; static void tgen_xor(TCGContext *s, TCGType type,
Signature · 1 line
2.43.0
PATCH 6/7 tcg/aarch64: Implement ctpop with FEAT_CSSC
In reply to Richard Henderson--- tcg/aarch64/tcg-target.c.inc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
tcg/aarch64/tcg-target.c.inc +14 -1
@@ -535,6 +535,7 @@ typedef enum { /* Data-processing (1 source) instructions. */ Irr_sf_CLZ = 0x5ac01000, + Irr_sf_CNT = 0x5ac01c00, Irr_sf_RBIT = 0x5ac00000, Irr_sf_REV = 0x5ac00000, /* + size << 10 */
@@ -2251,8 +2252,20 @@ static const TCGOutOpBinary outop_clz = { .out_rri = tgen_clzi, }; +static TCGConstraintSetIndex cset_ctpop(TCGType type, unsigned flags) +{ + return cpuinfo & CPUINFO_CSSC ? C_O1_I1(r, r) : C_NotImplemented; +} + +static void tgen_ctpop(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1) +{ + tcg_out_insn(s, rr_sf, CNT, type, a0, a1); +} + static const TCGOutOpUnary outop_ctpop = { - .base.static_constraint = C_NotImplemented, + .base.static_constraint = C_Dynamic, + .base.dynamic_constraint = cset_ctpop, + .out_rr = tgen_ctpop, }; static void tgen_ctz(TCGContext *s, TCGType type,
Signature · 1 line
2.43.0
Re: [PATCH 6/7] tcg/aarch64: Implement ctpop with FEAT_CSSC
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.c.inc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
PATCH 7/7 tcg/aarch64: Use CTZ from FEAT_CSSC
In reply to Richard HendersonWe already have an expansion of CTZ using RBIT+CLZ, but use the new insn with FEAT_CSSC is present.
--- tcg/aarch64/tcg-target.c.inc | 43 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-)
tcg/aarch64/tcg-target.c.inc +32 -11
@@ -535,6 +535,7 @@ typedef enum { /* Data-processing (1 source) instructions. */ Irr_sf_CLZ = 0x5ac01000, + Irr_sf_CTZ = 0x5ac01800, Irr_sf_CNT = 0x5ac01c00, Irr_sf_RBIT = 0x5ac00000, Irr_sf_REV = 0x5ac00000, /* + size << 10 */
@@ -2213,24 +2214,30 @@ static const TCGOutOpBinary outop_andc = { .out_rrr = tgen_andc, }; -static void tgen_clz(TCGContext *s, TCGType type, - TCGReg a0, TCGReg a1, TCGReg a2) +static void tgen_clzctz(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, + TCGReg a2, AArch64Insn insn) { tcg_out_cmp(s, type, TCG_COND_NE, a1, 0, true); - tcg_out_insn(s, rr_sf, CLZ, type, TCG_REG_TMP0, a1); + tcg_out_insn_rr_sf(s, insn, type, TCG_REG_TMP0, a1); tcg_out_insn(s, csel, CSEL, type, a0, TCG_REG_TMP0, a2, TCG_COND_NE); } -static void tgen_clzi(TCGContext *s, TCGType type, - TCGReg a0, TCGReg a1, tcg_target_long a2) +static void tgen_clz(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, TCGReg a2) +{ + tgen_clzctz(s, type, a0, a1, a2, Irr_sf_CLZ); +} + +static void tgen_clzctzi(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, + tcg_target_long a2, AArch64Insn insn) { if (a2 == (type == TCG_TYPE_I32 ? 32 : 64)) { - tcg_out_insn(s, rr_sf, CLZ, type, a0, a1); + tcg_out_insn_rr_sf(s, insn, type, a0, a1); return; } tcg_out_cmp(s, type, TCG_COND_NE, a1, 0, true); - tcg_out_insn(s, rr_sf, CLZ, type, a0, a1); + tcg_out_insn_rr_sf(s, insn, type, a0, a1); switch (a2) { case -1:
@@ -2246,6 +2253,12 @@ static void tgen_clzi(TCGContext *s, TCGType type, } } +static void tgen_clzi(TCGContext *s, TCGType type, + TCGReg a0, TCGReg a1, tcg_target_long a2) +{ + tgen_clzctzi(s, type, a0, a1, a2, Irr_sf_CLZ); +} + static const TCGOutOpBinary outop_clz = { .base.static_constraint = C_O1_I2(r, r, rAL), .out_rrr = tgen_clz,
@@ -2271,15 +2284,23 @@ static const TCGOutOpUnary outop_ctpop = { static void tgen_ctz(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) { - tcg_out_insn(s, rr_sf, RBIT, type, TCG_REG_TMP0, a1); - tgen_clz(s, type, a0, TCG_REG_TMP0, a2); + if (cpuinfo & CPUINFO_CSSC) { + tgen_clzctz(s, type, a0, a1, a2, Irr_sf_CTZ); + } else { + tcg_out_insn(s, rr_sf, RBIT, type, TCG_REG_TMP0, a1); + tgen_clzctz(s, type, a0, TCG_REG_TMP0, a2, Irr_sf_CLZ); + } } static void tgen_ctzi(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, tcg_target_long a2) { - tcg_out_insn(s, rr_sf, RBIT, type, TCG_REG_TMP0, a1); - tgen_clzi(s, type, a0, TCG_REG_TMP0, a2); + if (cpuinfo & CPUINFO_CSSC) { + tgen_clzctzi(s, type, a0, a1, a2, Irr_sf_CTZ); + } else { + tcg_out_insn(s, rr_sf, RBIT, type, TCG_REG_TMP0, a1); + tgen_clzctzi(s, type, a0, a1, a2, Irr_sf_CLZ); + } } static const TCGOutOpBinary outop_ctz = {
Signature · 1 line
2.43.0
Re: [PATCH 7/7] tcg/aarch64: Use CTZ from FEAT_CSSC
Quoted 7 lines · Richard Henderson
We already have an expansion of CTZ using RBIT+CLZ, but use the new insn with
FEAT_CSSCis present.Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.c.inc | 43 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-)