This commit updates Zvabd support to version 0.9[1]. This mainly involves more supported types and the newly added .vx variants. It also serves as a base for the implementation for the later vendor extension patch, so that we make fewer repeated changes.
[1] https://github.com/riscv/integer-vector-absolute-difference/releases/tag/v0.9 gcc/ChangeLog: * config/riscv/autovec.md (<su>abd<mode>3): Support all integer element widths. * config/riscv/genrvv-type-indexer.cc (main): Add DOUBLE_TRUNC_SIGNED_SCALAR case. * config/riscv/riscv-ext.def (zvabd): Update to version 0.9 and depend on Zve32x. * config/riscv/riscv-vector-builtins-bases.cc (vabd::expand): Add vx variant. (vabda::expand): Ditto. * config/riscv/riscv-vector-builtins-functions.def: New variants. * config/riscv/riscv-vector-builtins-types.def: Remove DEF_RVV_QU_HU_OPS. * config/riscv/riscv-vector-builtins.cc (qu_hu_ops): Remove. (DEF_RVV_QU_HU_OPS): Ditto. (sx_args): New. (wwsx_args): Ditto. (wwvx_args): Ditto. (qu_hu_vss_ops): Rename to... (u_vss_ops): ...this with new types. (qu_hu_vvv_ops): Remove. (u_vsx_ops): New. (hu_su_wwsx_ops): New. (hu_su_wwvx_ops): Ditto. (function_types): Add DOUBLE_TRUNC_SIGNED_SCALAR and new base types. * config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE_INDEX): Add DOUBLE_TRUNC_SIGNED_SCALAR. (signed_scalar, double_trunc_signed_scalar): New base types. * config/riscv/vector.md (@pred_vabd<su><mode>): Support all integer element widths. (@pred_vabd<su><mode>_scalar): New pattern. (*pred_vabd<su><mode>_scalar): Ditto. (*pred_vabd<su><mode>_extended_scalar): Ditto. (@pred_widen_abd_plus<su><mode>_scalar): Ditto. * doc/riscv-ext.texi: Regenerate. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/zvabd-1.c: Cover additional element widths and support RV32. * gcc.target/riscv/rvv/base/zvabd-intrinsic.c: Ditto. --- gcc/config/riscv/autovec.md | 8 +- gcc/config/riscv/genrvv-type-indexer.cc | 10 ++ gcc/config/riscv/riscv-ext.def | 4 +- .../riscv/riscv-vector-builtins-bases.cc | 24 +++- .../riscv/riscv-vector-builtins-functions.def | 8 +- .../riscv/riscv-vector-builtins-types.def | 21 --- gcc/config/riscv/riscv-vector-builtins.cc | 67 ++++++--- gcc/config/riscv/riscv-vector-builtins.def | 7 +- gcc/config/riscv/vector.md | 136 +++++++++++++++++- gcc/doc/riscv-ext.texi | 2 +- .../gcc.target/riscv/rvv/autovec/zvabd-1.c | 11 +- .../riscv/rvv/base/zvabd-intrinsic.c | 122 +++++++++++++++- 12 files changed, 354 insertions(+), 66 deletions(-) diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md index 6084027ce6f..484b346db47 100644 --- a/gcc/config/riscv/autovec.md +++ b/gcc/config/riscv/autovec.md @@ -1167,10 +1167,10 @@ (define_expand "abs<mode>2" ;; - [INT] Absolute differences ;; ---------------------------------------------------------------------------- (define_insn_and_split "<su>abd<mode>3" - [(set (match_operand:VI_QH 0 "register_operand" "=vr") - (unspec:VI_QH - [(match_operand:VI_QH 1 "register_operand" "vr") - (match_operand:VI_QH 2 "register_operand" "vr")] + [(set (match_operand:V_VLSI 0 "register_operand" "=vr") + (unspec:V_VLSI + [(match_operand:V_VLSI 1 "register_operand" "vr") + (match_operand:V_VLSI 2 "register_operand" "vr")] UNSPEC_VABD))] "TARGET_ZVABD && can_create_pseudo_p ()" "#" diff --git a/gcc/config/riscv/genrvv-type-indexer.cc b/gcc/config/riscv/genrvv-type-indexer.cc index 413ca19a171..6d97ee04a21 100644 --- a/gcc/config/riscv/genrvv-type-indexer.cc +++ b/gcc/config/riscv/genrvv-type-indexer.cc @@ -282,6 +282,7 @@ main (int argc, const char **argv) fprintf (fp, " /*OCT_TRUNC*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_SCALAR*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_SIGNED*/ INVALID,\n"); + fprintf (fp, " /*DOUBLE_TRUNC_SIGNED_SCALAR*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED_SCALAR*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_BFLOAT_SCALAR*/ INVALID,\n"); @@ -380,6 +381,13 @@ main (int argc, const char **argv) same_ratio_eew_type (sew, lmul_log2, sew / 2, false, false) .c_str ()); + if (!unsigned_p) + fprintf (fp, " /*DOUBLE_TRUNC_SIGNED_SCALAR*/ INVALID,\n"); + else + fprintf (fp, " /*DOUBLE_TRUNC_SIGNED_SCALAR*/ %s,\n", + same_ratio_eew_type (sew, lmul_log2, sew / 2, false, + false) + .c_str ()); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED*/ %s,\n", same_ratio_eew_type (sew, lmul_log2, sew / 2, true, false) .c_str ()); @@ -486,6 +494,7 @@ main (int argc, const char **argv) same_ratio_eew_type (16, lmul_log2, 8, false, true).c_str ()); fprintf (fp, " /*DOUBLE_TRUNC_SIGNED*/ %s,\n", same_ratio_eew_type (16, lmul_log2, 8, false, false).c_str ()); + fprintf (fp, " /*DOUBLE_TRUNC_SIGNED_SCALAR*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED*/ %s,\n", same_ratio_eew_type (16, lmul_log2, 8, true, false).c_str ()); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED_SCALAR*/ INVALID,\n"); @@ -570,6 +579,7 @@ main (int argc, const char **argv) fprintf (fp, " /*DOUBLE_TRUNC_SIGNED*/ %s,\n", same_ratio_eew_type (sew, lmul_log2, sew / 2, false, false) .c_str ()); + fprintf (fp, " /*DOUBLE_TRUNC_SIGNED_SCALAR*/ INVALID,\n"); fprintf (fp, " /*DOUBLE_TRUNC_UNSIGNED*/ %s,\n", same_ratio_eew_type (sew, lmul_log2, sew / 2, true, false) .c_str ()); diff --git a/gcc/config/riscv/riscv-ext.def b/gcc/config/riscv/riscv-ext.def index b4034190ed2..95e6c42e349 100644 --- a/gcc/config/riscv/riscv-ext.def +++ b/gcc/config/riscv/riscv-ext.def @@ -1617,8 +1617,8 @@ DEFINE_RISCV_EXT ( /* FULL_NAME. */ "Vector absolute difference extension.", /* DESC. */ "", /* URL. */ , - /* DEP_EXTS. */ ({"v"}), - /* SUPPORTED_VERSIONS. */ ({{0, 7}}), + /* DEP_EXTS. */ ({"zve32x"}), + /* SUPPORTED_VERSIONS. */ ({{0, 9}}), /* FLAG_GROUP. */ zvabd, /* BITMASK_GROUP_ID. */ BITMASK_NOT_YET_ALLOCATED, /* BITMASK_BIT_POSITION. */ BITMASK_NOT_YET_ALLOCATED, diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc b/gcc/config/riscv/riscv-vector-builtins-bases.cc index 3bbec005fac..afe8ebe9815 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc @@ -2469,7 +2469,16 @@ class vabd : public function_base public: rtx expand (function_expander &e) const override { - return e.use_exact_insn (code_for_pred_vabd (UNSPEC, e.vector_mode ())); + switch (e.op_info->op) + { + case OP_TYPE_vv: + return e.use_exact_insn (code_for_pred_vabd (UNSPEC, e.vector_mode ())); + case OP_TYPE_vx: + return e.use_exact_insn ( + code_for_pred_vabd_scalar (UNSPEC, e.vector_mode ())); + default: + gcc_unreachable (); + } } }; @@ -2492,8 +2501,17 @@ public: rtx expand (function_expander &e) const override { - return e.use_widen_ternop_insn ( - code_for_pred_widen_abd_plus (UNSPEC, e.vector_mode ())); + switch (e.op_info->op) + { + case OP_TYPE_vv: + return e.use_widen_ternop_insn ( + code_for_pred_widen_abd_plus (UNSPEC, e.vector_mode ())); + case OP_TYPE_vx: + return e.use_widen_ternop_insn ( + code_for_pred_widen_abd_plus_scalar (UNSPEC, e.vector_mode ())); + default: + gcc_unreachable (); + } } }; diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def index a31e1c4e194..cf3614c4dea 100644 --- a/gcc/config/riscv/riscv-vector-builtins-functions.def +++ b/gcc/config/riscv/riscv-vector-builtins-functions.def @@ -780,9 +780,13 @@ DEF_RVV_FUNCTION (vfwmaccbf16_frm, alu_frm, full_preds, f32_wwfv_ops) /* Zvabd */ #define REQUIRED_EXTENSIONS ZVABD_EXT DEF_RVV_FUNCTION (vabs, alu, full_preds, u_s_ops) -DEF_RVV_FUNCTION (vabd, alu, full_preds, qu_hu_vss_ops) -DEF_RVV_FUNCTION (vabdu, alu, full_preds, qu_hu_vvv_ops) +DEF_RVV_FUNCTION (vabd, alu, full_preds, u_vss_ops) +DEF_RVV_FUNCTION (vabd, alu, full_preds, u_vsx_ops) +DEF_RVV_FUNCTION (vabdu, alu, full_preds, u_vvv_ops) +DEF_RVV_FUNCTION (vabdu, alu, full_preds, u_vvx_ops) DEF_RVV_FUNCTION (vwabda, alu, full_preds, hu_su_wwss_ops) +DEF_RVV_FUNCTION (vwabda, alu, full_preds, hu_su_wwsx_ops) DEF_RVV_FUNCTION (vwabdau, alu, full_preds, hu_su_wwvv_ops) +DEF_RVV_FUNCTION (vwabdau, alu, full_preds, hu_su_wwvx_ops) #undef REQUIRED_EXTENSIONS #undef DEF_RVV_FUNCTION diff --git a/gcc/config/riscv/riscv-vector-builtins-types.def b/gcc/config/riscv/riscv-vector-builtins-types.def index 98c638bfa50..ee128efb742 100644 --- a/gcc/config/riscv/riscv-vector-builtins-types.def +++ b/gcc/config/riscv/riscv-vector-builtins-types.def @@ -405,12 +405,6 @@ along with GCC; see the file COPYING3. If not see #define DEF_RVV_F16_OPS(TYPE, REQUIRE) #endif -/* Use "DEF_RVV_QU_HU_OPS" macro include all types for vuint8 and vuint16 - which will be iterated and registered as intrinsic functions. */ -#ifndef DEF_RVV_QU_HU_OPS -#define DEF_RVV_QU_HU_OPS(TYPE, REQUIRE) -#endif - /* Use "DEF_RVV_HU_SU_OPS" macro include all types for vuint16 and vuint32 which will be iterated and registered as intrinsic functions. */ #ifndef DEF_RVV_HU_SU_OPS @@ -1590,20 +1584,6 @@ DEF_RVV_F16_OPS (vfloat16m2_t, RVV_REQUIRE_ELEN_FP_16) DEF_RVV_F16_OPS (vfloat16m4_t, RVV_REQUIRE_ELEN_FP_16) DEF_RVV_F16_OPS (vfloat16m8_t, RVV_REQUIRE_ELEN_FP_16) -DEF_RVV_QU_HU_OPS (vuint8mf8_t, RVV_REQUIRE_ELEN_64) -DEF_RVV_QU_HU_OPS (vuint8mf4_t, 0) -DEF_RVV_QU_HU_OPS (vuint8mf2_t, 0) -DEF_RVV_QU_HU_OPS (vuint8m1_t, 0) -DEF_RVV_QU_HU_OPS (vuint8m2_t, 0) -DEF_RVV_QU_HU_OPS (vuint8m4_t, 0) -DEF_RVV_QU_HU_OPS (vuint8m8_t, 0) -DEF_RVV_QU_HU_OPS (vuint16mf4_t, RVV_REQUIRE_ELEN_64) -DEF_RVV_QU_HU_OPS (vuint16mf2_t, 0) -DEF_RVV_QU_HU_OPS (vuint16m1_t, 0) -DEF_RVV_QU_HU_OPS (vuint16m2_t, 0) -DEF_RVV_QU_HU_OPS (vuint16m4_t, 0) -DEF_RVV_QU_HU_OPS (vuint16m8_t, 0) - DEF_RVV_HU_SU_OPS (vuint16mf4_t, RVV_REQUIRE_ELEN_64) DEF_RVV_HU_SU_OPS (vuint16mf2_t, 0) DEF_RVV_HU_SU_OPS (vuint16m1_t, 0) @@ -1687,6 +1667,5 @@ DEF_RVV_DIU_OPS (vuint64m8_t, RVV_REQUIRE_ELEN_64) #undef DEF_RVV_Q_OPS #undef DEF_RVV_QU_OPS #undef DEF_RVV_F16_OPS -#undef DEF_RVV_QU_HU_OPS #undef DEF_RVV_HU_SU_OPS #undef DEF_RVV_DIU_OPS diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc index 1f4f3eb86c5..9480d342f3b 100644 --- a/gcc/config/riscv/riscv-vector-builtins.cc +++ b/gcc/config/riscv/riscv-vector-builtins.cc @@ -604,13 +604,6 @@ static const rvv_type_info f16_ops[] = { #include "riscv-vector-builtins-types.def" {NUM_VECTOR_TYPES, 0}}; -/* A list of all vuint8m_t and vuint16m_t will be registered for intrinsic - * functions. */ -static const rvv_type_info qu_hu_ops[] = { -#define DEF_RVV_QU_HU_OPS(TYPE, REQUIRE) {VECTOR_TYPE_##TYPE, REQUIRE}, -#include "riscv-vector-builtins-types.def" - {NUM_VECTOR_TYPES, 0}}; - /* A list of all vuint16m_t and vuint32m_t will be registered for intrinsic * functions. */ static const rvv_type_info hu_su_ops[] = { @@ -1300,6 +1293,12 @@ static constexpr const rvv_arg_type_info ss_args[] = {rvv_arg_type_info (RVV_BASE_signed_vector), rvv_arg_type_info (RVV_BASE_signed_vector), rvv_arg_type_info_end}; +/* A list of args for vector_type func (signed vector_type, signed + scalar_type) function. */ +static constexpr const rvv_arg_type_info sx_args[] + = {rvv_arg_type_info (RVV_BASE_signed_vector), + rvv_arg_type_info (RVV_BASE_signed_scalar), rvv_arg_type_info_end}; + /* A list of args for vector_type func (vector_type, signed double demote type, signed double demote type) function. */ static constexpr const rvv_arg_type_info wwss_args[] @@ -1308,6 +1307,21 @@ static constexpr const rvv_arg_type_info wwss_args[] rvv_arg_type_info (RVV_BASE_double_trunc_signed_vector), rvv_arg_type_info_end}; +/* A list of args for vector_type func (vector_type, signed double demote + vector_type, signed double demote scalar_type) function. */ +static constexpr const rvv_arg_type_info wwsx_args[] + = {rvv_arg_type_info (RVV_BASE_vector), + rvv_arg_type_info (RVV_BASE_double_trunc_signed_vector), + rvv_arg_type_info (RVV_BASE_double_trunc_signed_scalar), + rvv_arg_type_info_end}; + +/* A list of args for vector_type func (vector_type, double demote + vector_type, double demote scalar_type) function. */ +static constexpr const rvv_arg_type_info wwvx_args[] + = {rvv_arg_type_info (RVV_BASE_vector), + rvv_arg_type_info (RVV_BASE_double_trunc_vector), + rvv_arg_type_info (RVV_BASE_double_trunc_scalar), rvv_arg_type_info_end}; + /* A list of none preds that will be registered for intrinsic functions. */ static constexpr const predication_type_index none_preds[] = {PRED_TYPE_none, NUM_PRED_TYPES}; @@ -3485,19 +3499,19 @@ static constexpr const rvv_op_info sf_vc_v_fvw_ops /* A static operand information for vector_type func (signed vector_type, signed vector_type) function registration. */ -static constexpr const rvv_op_info qu_hu_vss_ops - = {qu_hu_ops, /* Types */ +static constexpr const rvv_op_info u_vss_ops + = {u_ops, /* Types */ OP_TYPE_vv, /* Suffix */ rvv_arg_type_info (RVV_BASE_vector), /* Return type */ ss_args /* Args */}; -/* A static operand information for vector_type func (vector_type, vector_type) - * function registration. */ -static constexpr const rvv_op_info qu_hu_vvv_ops - = {qu_hu_ops, /* Types */ - OP_TYPE_vv, /* Suffix */ +/* A static operand information for vector_type func (signed vector_type, + signed scalar_type) function registration. */ +static constexpr const rvv_op_info u_vsx_ops + = {u_ops, /* Types */ + OP_TYPE_vx, /* Suffix */ rvv_arg_type_info (RVV_BASE_vector), /* Return type */ - vv_args /* Args */}; + sx_args /* Args */}; /* A static operand information for vector_type func (vector_type, signed double demote type, signed double demote type) function registration. */ @@ -3515,6 +3529,22 @@ static constexpr const rvv_op_info hu_su_wwvv_ops rvv_arg_type_info (RVV_BASE_vector), /* Return type */ wwvv_args /* Args */}; +/* A static operand information for vector_type func (vector_type, signed + double demote vector_type, signed double demote scalar_type). */ +static constexpr const rvv_op_info hu_su_wwsx_ops + = {hu_su_ops, /* Types */ + OP_TYPE_vx, /* Suffix */ + rvv_arg_type_info (RVV_BASE_vector), /* Return type */ + wwsx_args /* Args */}; + +/* A static operand information for vector_type func (vector_type, + double demote vector_type, double demote scalar_type). */ +static constexpr const rvv_op_info hu_su_wwvx_ops + = {hu_su_ops, /* Types */ + OP_TYPE_vx, /* Suffix */ + rvv_arg_type_info (RVV_BASE_vector), /* Return type */ + wwvx_args /* Args */}; + /* A static operand information for vector_type func (signed vector_type) function registration. */ static constexpr const rvv_op_info u_s_ops @@ -3542,8 +3572,9 @@ static constexpr const function_type_info function_types[] = { EEW32_INDEX, EEW64_INDEX, SHIFT, DOUBLE_TRUNC, QUAD_TRUNC, QUAD_EMUL, \ QUAD_EMUL_SIGNED, QUAD_EMUL_UNSIGNED, QUAD_FIX, QUAD_FIX_SIGNED, \ QUAD_FIX_UNSIGNED, OCT_TRUNC, DOUBLE_TRUNC_SCALAR, DOUBLE_TRUNC_SIGNED, \ - DOUBLE_TRUNC_UNSIGNED, DOUBLE_TRUNC_UNSIGNED_SCALAR, \ - DOUBLE_TRUNC_BFLOAT_SCALAR, DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \ + DOUBLE_TRUNC_SIGNED_SCALAR, DOUBLE_TRUNC_UNSIGNED, \ + DOUBLE_TRUNC_UNSIGNED_SCALAR, DOUBLE_TRUNC_BFLOAT_SCALAR, \ + DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \ LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, XFQF, EEW8_INTERPRET, \ EEW16_INTERPRET, EEW32_INTERPRET, EEW64_INTERPRET, BOOL1_INTERPRET, \ BOOL2_INTERPRET, BOOL4_INTERPRET, BOOL8_INTERPRET, BOOL16_INTERPRET, \ @@ -3558,6 +3589,7 @@ static constexpr const function_type_info function_types[] = { VECTOR_TYPE_INVALID, \ VECTOR_TYPE_##MASK, \ VECTOR_TYPE_##SIGNED, \ + VECTOR_TYPE_INVALID, \ VECTOR_TYPE_##UNSIGNED, \ VECTOR_TYPE_INVALID, \ VECTOR_TYPE_INVALID, \ @@ -3586,6 +3618,7 @@ static constexpr const function_type_info function_types[] = { VECTOR_TYPE_##OCT_TRUNC, \ VECTOR_TYPE_##DOUBLE_TRUNC_SCALAR, \ VECTOR_TYPE_##DOUBLE_TRUNC_SIGNED, \ + VECTOR_TYPE_##DOUBLE_TRUNC_SIGNED_SCALAR, \ VECTOR_TYPE_##DOUBLE_TRUNC_UNSIGNED, \ VECTOR_TYPE_##DOUBLE_TRUNC_UNSIGNED_SCALAR, \ VECTOR_TYPE_##DOUBLE_TRUNC_BFLOAT_SCALAR, \ diff --git a/gcc/config/riscv/riscv-vector-builtins.def b/gcc/config/riscv/riscv-vector-builtins.def index e4e23ce32b2..ce4bf651d18 100644 --- a/gcc/config/riscv/riscv-vector-builtins.def +++ b/gcc/config/riscv/riscv-vector-builtins.def @@ -73,8 +73,9 @@ along with GCC; see the file COPYING3. If not see EEW32_INDEX, EEW64_INDEX, SHIFT, DOUBLE_TRUNC, QUAD_TRUNC, QUAD_EMUL, \ QUAD_EMUL_SIGNED, QUAD_EMUL_UNSIGNED, QUAD_FIX, QUAD_FIX_SIGNED, \ QUAD_FIX_UNSIGNED, OCT_TRUNC, DOUBLE_TRUNC_SCALAR, DOUBLE_TRUNC_SIGNED, \ - DOUBLE_TRUNC_UNSIGNED, DOUBLE_TRUNC_UNSIGNED_SCALAR, \ - DOUBLE_TRUNC_BFLOAT_SCALAR, DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \ + DOUBLE_TRUNC_SIGNED_SCALAR, DOUBLE_TRUNC_UNSIGNED, \ + DOUBLE_TRUNC_UNSIGNED_SCALAR, DOUBLE_TRUNC_BFLOAT_SCALAR, \ + DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \ LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, XFQF, EEW8_INTERPRET, \ EEW16_INTERPRET, EEW32_INTERPRET, EEW64_INTERPRET, BOOL1_INTERPRET, \ BOOL2_INTERPRET, BOOL4_INTERPRET, BOOL8_INTERPRET, BOOL16_INTERPRET, \ @@ -681,6 +682,7 @@ DEF_RVV_BASE_TYPE (vector, builtin_types[type_idx].vector) DEF_RVV_BASE_TYPE (scalar, builtin_types[type_idx].scalar) DEF_RVV_BASE_TYPE (mask, get_vector_type (type_idx)) DEF_RVV_BASE_TYPE (signed_vector, get_vector_type (type_idx)) +DEF_RVV_BASE_TYPE (signed_scalar, builtin_types[type_idx - 1].scalar) DEF_RVV_BASE_TYPE (unsigned_vector, get_vector_type (type_idx)) /* According to riscv-vector-builtins-types.def, the unsigned type is always the signed type + 1 (They have same SEW and LMUL). @@ -717,6 +719,7 @@ DEF_RVV_BASE_TYPE (quad_fixed_unsigned_vector, get_vector_type (type_idx)) DEF_RVV_BASE_TYPE (oct_trunc_vector, get_vector_type (type_idx)) DEF_RVV_BASE_TYPE (double_trunc_scalar, get_scalar_type (type_idx)) DEF_RVV_BASE_TYPE (double_trunc_signed_vector, get_vector_type (type_idx)) +DEF_RVV_BASE_TYPE (double_trunc_signed_scalar, get_scalar_type (type_idx)) DEF_RVV_BASE_TYPE (double_trunc_unsigned_vector, get_vector_type (type_idx)) DEF_RVV_BASE_TYPE (double_trunc_unsigned_scalar, get_scalar_type (type_idx)) DEF_RVV_BASE_TYPE (double_trunc_bfloat_scalar, get_scalar_type (type_idx)) diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 8a97f35967f..26df1010e8d 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -9267,7 +9267,7 @@ (define_expand "@pred_widen_mul_plus_u_vx<mode>" ;; ---------------------------------------------------------------- ;; Includes: ;; - vabs: Vector Single-Width Signed Integer Absolute -;; - vabd/vabdu: Vector Single-Width Signed Integer Absolute Difference +;; - vabd/vabdu: Vector Single-Width Integer Absolute Difference ;; - vwabda/vwabdau: Vector Widening Signed Integer Absolute ;; Difference and Accumulate ;; ------------------------------------ @@ -9296,8 +9296,8 @@ (define_insn "@pred_abs<mode>" (set (attr "avl_type_idx") (const_int 7))]) (define_insn "@pred_vabd<su><mode>" - [(set (match_operand:VI_QH 0 "register_operand" "=vd, vd, vr, vr") - (if_then_else:VI_QH + [(set (match_operand:V_VLSI 0 "register_operand" "=vd, vd, vr, vr") + (if_then_else:V_VLSI (unspec:<VM> [(match_operand:<VM> 1 "vector_mask_operand" " vm, vm, Wc1, Wc1") (match_operand 5 "vector_length_operand" " rK, rK, rK, rK") @@ -9306,16 +9306,115 @@ (define_insn "@pred_vabd<su><mode>" (match_operand 8 "const_int_operand" " i, i, i, i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (unspec:VI_QH - [(match_operand:VI_QH 3 "register_operand" "vr,vr,vr,vr") - (match_operand:VI_QH 4 "register_operand" "vr,vr,vr,vr")] + (unspec:V_VLSI + [(match_operand:V_VLSI 3 "register_operand" "vr,vr,vr,vr") + (match_operand:V_VLSI 4 "register_operand" "vr,vr,vr,vr")] UNSPEC_VABD) - (match_operand:VI_QH 2 "vector_merge_operand" "vu,0,vu,0")))] + (match_operand:V_VLSI 2 "vector_merge_operand" "vu,0,vu,0")))] "TARGET_ZVABD" "vabd<u>.vv\t%0,%3,%4%p1" [(set_attr "type" "vialu") (set_attr "mode" "<MODE>")]) +(define_insn "@pred_vabd<su><mode>_scalar" + [(set (match_operand:V_VLSI_QHS 0 "register_operand" "=vd,vd, vr, vr") + (if_then_else:V_VLSI_QHS + (unspec:<VM> + [(match_operand:<VM> 1 "vector_mask_operand" " vm, vm,Wc1,Wc1") + (match_operand 5 "vector_length_operand" "rvl,rvl,rvl,rvl") + (match_operand 6 "const_int_operand" " i, i, i, i") + (match_operand 7 "const_int_operand" " i, i, i, i") + (match_operand 8 "const_int_operand" " i, i, i, i") + (reg:SI VL_REGNUM) + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) + (unspec:V_VLSI_QHS + [(match_operand:V_VLSI_QHS 3 "register_operand" "vr,vr,vr,vr") + (vec_duplicate:V_VLSI_QHS + (match_operand:<VEL> 4 "reg_or_0_operand" "rJ,rJ,rJ,rJ"))] + UNSPEC_VABD) + (match_operand:V_VLSI_QHS 2 "vector_merge_operand" "vu,0,vu,0")))] + "TARGET_ZVABD" + "vabd<u>.vx\t%0,%3,%z4%p1" + [(set_attr "type" "vialu") + (set_attr "mode" "<MODE>")]) + +;; Zvabd has no immediate form. On RV32, a SEW64 scalar that cannot be +;; supplied by a sign-extended general-purpose register must be broadcast. +(define_expand "@pred_vabd<su><mode>_scalar" + [(set (match_operand:V_VLSI_D 0 "register_operand") + (if_then_else:V_VLSI_D + (unspec:<VM> + [(match_operand:<VM> 1 "vector_mask_operand") + (match_operand 5 "vector_length_operand") + (match_operand 6 "const_int_operand") + (match_operand 7 "const_int_operand") + (match_operand 8 "const_int_operand") + (reg:SI VL_REGNUM) + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) + (unspec:V_VLSI_D + [(match_operand:V_VLSI_D 3 "register_operand") + (vec_duplicate:V_VLSI_D + (match_operand:<VEL> 4 "reg_or_int_operand"))] + UNSPEC_VABD) + (match_operand:V_VLSI_D 2 "vector_merge_operand")))] + "TARGET_ZVABD" +{ + if (riscv_vector::sew64_scalar_helper ( + operands, &operands[4], operands[5], <MODE>mode, false, + [] (rtx *operands, rtx broadcast_scalar) { + emit_insn (gen_pred_vabd<su><mode> ( + operands[0], operands[1], operands[2], operands[3], + broadcast_scalar, operands[5], operands[6], operands[7], + operands[8])); + }, (riscv_vector::avl_type) INTVAL (operands[8]))) + DONE; +}) + +(define_insn "*pred_vabd<su><mode>_scalar" + [(set (match_operand:V_VLSI_D 0 "register_operand" "=vd,vd, vr, vr") + (if_then_else:V_VLSI_D + (unspec:<VM> + [(match_operand:<VM> 1 "vector_mask_operand" " vm, vm,Wc1,Wc1") + (match_operand 5 "vector_length_operand" "rvl,rvl,rvl,rvl") + (match_operand 6 "const_int_operand" " i, i, i, i") + (match_operand 7 "const_int_operand" " i, i, i, i") + (match_operand 8 "const_int_operand" " i, i, i, i") + (reg:SI VL_REGNUM) + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) + (unspec:V_VLSI_D + [(match_operand:V_VLSI_D 3 "register_operand" "vr,vr,vr,vr") + (vec_duplicate:V_VLSI_D + (match_operand:<VEL> 4 "reg_or_0_operand" "rJ,rJ,rJ,rJ"))] + UNSPEC_VABD) + (match_operand:V_VLSI_D 2 "vector_merge_operand" "vu,0,vu,0")))] + "TARGET_ZVABD" + "vabd<u>.vx\t%0,%3,%z4%p1" + [(set_attr "type" "vialu") + (set_attr "mode" "<MODE>")]) + +(define_insn "*pred_vabd<su><mode>_extended_scalar" + [(set (match_operand:V_VLSI_D 0 "register_operand" "=vd,vd, vr, vr") + (if_then_else:V_VLSI_D + (unspec:<VM> + [(match_operand:<VM> 1 "vector_mask_operand" " vm, vm,Wc1,Wc1") + (match_operand 5 "vector_length_operand" "rvl,rvl,rvl,rvl") + (match_operand 6 "const_int_operand" " i, i, i, i") + (match_operand 7 "const_int_operand" " i, i, i, i") + (match_operand 8 "const_int_operand" " i, i, i, i") + (reg:SI VL_REGNUM) + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) + (unspec:V_VLSI_D + [(match_operand:V_VLSI_D 3 "register_operand" "vr,vr,vr,vr") + (vec_duplicate:V_VLSI_D + (sign_extend:<VEL> + (match_operand:<VSUBEL> 4 "reg_or_0_operand" "rJ,rJ,rJ,rJ")))] + UNSPEC_VABD) + (match_operand:V_VLSI_D 2 "vector_merge_operand" "vu,0,vu,0")))] + "TARGET_ZVABD && !TARGET_64BIT" + "vabd<u>.vx\t%0,%3,%z4%p1" + [(set_attr "type" "vialu") + (set_attr "mode" "<MODE>")]) + (define_insn "@pred_widen_abd_plus<su><mode>" [(set (match_operand:VWEXTI_HS 0 "register_operand" "=&vr") (if_then_else:VWEXTI_HS @@ -9338,6 +9437,29 @@ (define_insn "@pred_widen_abd_plus<su><mode>" [(set_attr "type" "viwalu") (set_attr "mode" "<V_DOUBLE_TRUNC>")]) +(define_insn "@pred_widen_abd_plus<su><mode>_scalar" + [(set (match_operand:VWEXTI_HS 0 "register_operand" "=&vd,&vr") + (if_then_else:VWEXTI_HS + (unspec:<VM> + [(match_operand:<VM> 1 "vector_mask_operand" " vm,Wc1") + (match_operand 5 "vector_length_operand" "rvl,rvl") + (match_operand 6 "const_int_operand" " i, i") + (match_operand 7 "const_int_operand" " i, i") + (match_operand 8 "const_int_operand" " i, i") + (reg:SI VL_REGNUM) + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) + (unspec:VWEXTI_HS + [(match_operand:<V_DOUBLE_TRUNC> 3 "register_operand" "vr,vr") + (vec_duplicate:<V_DOUBLE_TRUNC> + (match_operand:<VSUBEL> 4 "reg_or_0_operand" "rJ,rJ")) + (match_operand:VWEXTI_HS 2 "register_operand" "0,0")] + UNSPEC_VABDA) + (match_dup 2)))] + "TARGET_ZVABD" + "vwabda<u>.vx\t%0,%3,%z4%p1" + [(set_attr "type" "viwalu") + (set_attr "mode" "<V_DOUBLE_TRUNC>")]) + (include "autovec.md") (include "autovec-opt.md") (include "sifive-vector.md") diff --git a/gcc/doc/riscv-ext.texi b/gcc/doc/riscv-ext.texi index ece774cfa14..eb6d118c422 100644 --- a/gcc/doc/riscv-ext.texi +++ b/gcc/doc/riscv-ext.texi @@ -475,7 +475,7 @@ @tab Minimal half-precision floating-point in integer registers extension @item @samp{zvabd} -@tab 0.7 +@tab 0.9 @tab Vector absolute difference extension. @item @samp{sdtrig} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zvabd-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zvabd-1.c index e8738f84160..bcff8dd8eea 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zvabd-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zvabd-1.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-additional-options "-march=rv64gcv_zvabd -mabi=lp64d -fno-vect-cost-model" } */ +/* { dg-additional-options "-march=rv32gcv_zvabd -mabi=ilp32d -fno-vect-cost-model" { target { rv32 } } } */ +/* { dg-additional-options "-march=rv64gcv_zvabd -mabi=lp64d -fno-vect-cost-model" { target { rv64 } } } */ #include <stdint-gcc.h> @@ -48,6 +49,8 @@ abs64 (int64_t i) TEST_VABD (int16_t, int16_t) \ TEST_VABD (uint16_t, uint16_t) \ TEST_VABD (int32_t, int32_t) \ + TEST_VABD (uint32_t, uint32_t) \ + TEST_VABD (int64_t, int64_t) \ TEST_VWABDA (int16_t, int8_t) \ TEST_VWABDA (uint16_t, uint8_t) \ TEST_VWABDA (int32_t, int16_t) \ @@ -57,8 +60,8 @@ abs64 (int64_t i) TEST_ALL() -/* { dg-final { scan-assembler-times {\tvabs\.v} 5 } } */ -/* { dg-final { scan-assembler-times {\tvabd\.vv} 2 } } */ -/* { dg-final { scan-assembler-times {\tvabdu\.vv} 2 } } */ +/* { dg-final { scan-assembler-times {\tvabs\.v} 2 } } */ +/* { dg-final { scan-assembler-times {\tvabd\.vv} 5 } } */ +/* { dg-final { scan-assembler-times {\tvabdu\.vv} 4 } } */ /* { dg-final { scan-assembler-times {\tvwabda\.vv} 2 } } */ /* { dg-final { scan-assembler-times {\tvwabdau\.vv} 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/zvabd-intrinsic.c b/gcc/testsuite/gcc.target/riscv/rvv/base/zvabd-intrinsic.c index 37f917498fc..fd66c25bf17 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/zvabd-intrinsic.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/zvabd-intrinsic.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv64gcv_zvabd -mabi=lp64d" } */ +/* { dg-options "-march=rv32gcv_zvabd -mabi=ilp32d" { target { rv32 } } } */ +/* { dg-options "-march=rv64gcv_zvabd -mabi=lp64d" { target { rv64 } } } */ #include <riscv_vector.h> vuint8m1_t @@ -44,6 +45,46 @@ test_vabd_vv_u8m1_m (vbool8_t mask, vint8m1_t vs2, vint8m1_t vs1, size_t vl) return __riscv_vabd_vv_u8m1_m (mask, vs2, vs1, vl); } +vuint32m1_t +test_vabd_vv_u32m1_tu (vuint32m1_t vd, vint32m1_t vs2, vint32m1_t vs1, + size_t vl) +{ + return __riscv_vabd_vv_u32m1_tu (vd, vs2, vs1, vl); +} + +vuint64m1_t +test_vabd_vv_u64m1_tumu (vbool64_t mask, vuint64m1_t vd, vint64m1_t vs2, + vint64m1_t vs1, size_t vl) +{ + return __riscv_vabd_vv_u64m1_tumu (mask, vd, vs2, vs1, vl); +} + +vuint8m1_t +test_vabd_vx_u8m1 (vint8m1_t vs2, int8_t rs1, size_t vl) +{ + return __riscv_vabd_vx_u8m1 (vs2, rs1, vl); +} + +vuint16m1_t +test_vabd_vx_u16m1_tu (vuint16m1_t vd, vint16m1_t vs2, int16_t rs1, size_t vl) +{ + return __riscv_vabd_vx_u16m1_tu (vd, vs2, rs1, vl); +} + +vuint32m1_t +test_vabd_vx_u32m1_mu (vbool32_t mask, vuint32m1_t vd, vint32m1_t vs2, + int32_t rs1, size_t vl) +{ + return __riscv_vabd_vx_u32m1_mu (mask, vd, vs2, rs1, vl); +} + +vuint64m1_t +test_vabd_vx_u64m1_tumu (vbool64_t mask, vuint64m1_t vd, vint64m1_t vs2, + int64_t rs1, size_t vl) +{ + return __riscv_vabd_vx_u64m1_tumu (mask, vd, vs2, rs1, vl); +} + vuint16m1_t test_vabdu_vv_u16m1 (vuint16m1_t vs2, vuint16m1_t vs1, size_t vl) { @@ -57,6 +98,46 @@ test_vabdu_vv_u16m1_tu (vuint16m1_t vd, vuint16m1_t vs2, vuint16m1_t vs1, return __riscv_vabdu_vv_u16m1_tu (vd, vs2, vs1, vl); } +vuint32m1_t +test_vabdu_vv_u32m1_mu (vbool32_t mask, vuint32m1_t vd, vuint32m1_t vs2, + vuint32m1_t vs1, size_t vl) +{ + return __riscv_vabdu_vv_u32m1_mu (mask, vd, vs2, vs1, vl); +} + +vuint64m1_t +test_vabdu_vv_u64m1_m (vbool64_t mask, vuint64m1_t vs2, vuint64m1_t vs1, + size_t vl) +{ + return __riscv_vabdu_vv_u64m1_m (mask, vs2, vs1, vl); +} + +vuint8m1_t +test_vabdu_vx_u8m1_m (vbool8_t mask, vuint8m1_t vs2, uint8_t rs1, size_t vl) +{ + return __riscv_vabdu_vx_u8m1_m (mask, vs2, rs1, vl); +} + +vuint16m1_t +test_vabdu_vx_u16m1 (vuint16m1_t vs2, uint16_t rs1, size_t vl) +{ + return __riscv_vabdu_vx_u16m1 (vs2, rs1, vl); +} + +vuint32m1_t +test_vabdu_vx_u32m1_tum (vbool32_t mask, vuint32m1_t vd, vuint32m1_t vs2, + uint32_t rs1, size_t vl) +{ + return __riscv_vabdu_vx_u32m1_tum (mask, vd, vs2, rs1, vl); +} + +vuint64m1_t +test_vabdu_vx_u64m1_tu (vuint64m1_t vd, vuint64m1_t vs2, uint64_t rs1, + size_t vl) +{ + return __riscv_vabdu_vx_u64m1_tu (vd, vs2, rs1, vl); +} + vuint32m1_t test_vwabda_vv_u32m1 (vuint32m1_t vd, vint16mf2_t vs2, vint16mf2_t vs1, size_t vl) @@ -71,6 +152,19 @@ test_vwabda_vv_u16m1_tu (vuint16m1_t vd, vint8mf2_t vs2, vint8mf2_t vs1, return __riscv_vwabda_vv_u16m1_tu (vd, vs2, vs1, vl); } +vuint16m1_t +test_vwabda_vx_u16m1 (vuint16m1_t vd, vint8mf2_t vs2, int8_t rs1, size_t vl) +{ + return __riscv_vwabda_vx_u16m1 (vd, vs2, rs1, vl); +} + +vuint32m1_t +test_vwabda_vx_u32m1_tumu (vbool32_t mask, vuint32m1_t vd, vint16mf2_t vs2, + int16_t rs1, size_t vl) +{ + return __riscv_vwabda_vx_u32m1_tumu (mask, vd, vs2, rs1, vl); +} + vuint16m1_t test_vwabdau_vv_u16m1 (vuint16m1_t vd, vuint8mf2_t vs2, vuint8mf2_t vs1, size_t vl) @@ -85,8 +179,30 @@ test_vwabdau_vv_u16m1_mu (vbool16_t mask, vuint16m1_t vd, vuint8mf2_t vs2, return __riscv_vwabdau_vv_u16m1_mu (mask, vd, vs2, vs1, vl); } +vuint16m1_t +test_vwabdau_vx_u16m1_mu (vbool16_t mask, vuint16m1_t vd, vuint8mf2_t vs2, + uint8_t rs1, size_t vl) +{ + return __riscv_vwabdau_vx_u16m1_mu (mask, vd, vs2, rs1, vl); +} + +vuint32m1_t +test_vwabdau_vx_u32m1_tum (vbool32_t mask, vuint32m1_t vd, vuint16mf2_t vs2, + uint16_t rs1, size_t vl) +{ + return __riscv_vwabdau_vx_u32m1_tum (mask, vd, vs2, rs1, vl); +} + /* { dg-final { scan-assembler-times {\tvabs\.v} 5 } } */ -/* { dg-final { scan-assembler-times {\tvabd\.vv} 2 } } */ -/* { dg-final { scan-assembler-times {\tvabdu\.vv} 2 } } */ +/* { dg-final { scan-assembler-times {\tvabd\.vv} 4 { target rv64 } } } */ +/* { dg-final { scan-assembler-times {\tvabd\.vv} 5 { target rv32 } } } */ +/* { dg-final { scan-assembler-times {\tvabdu\.vv} 4 { target rv64 } } } */ +/* { dg-final { scan-assembler-times {\tvabdu\.vv} 5 { target rv32 } } } */ +/* { dg-final { scan-assembler-times {\tvabd\.vx} 4 { target rv64 } } } */ +/* { dg-final { scan-assembler-times {\tvabd\.vx} 3 { target rv32 } } } */ +/* { dg-final { scan-assembler-times {\tvabdu\.vx} 4 { target rv64 } } } */ +/* { dg-final { scan-assembler-times {\tvabdu\.vx} 3 { target rv32 } } } */ /* { dg-final { scan-assembler-times {\tvwabda\.vv} 2 } } */ /* { dg-final { scan-assembler-times {\tvwabdau\.vv} 2 } } */ +/* { dg-final { scan-assembler-times {\tvwabda\.vx} 2 } } */ +/* { dg-final { scan-assembler-times {\tvwabdau\.vx} 2 } } */ -- 2.47.1
