Skip to content

Commit 35e6c55

Browse files
pz9115yulong18
authored andcommitted
RISC-V: Update Xsfvfnrclip implementation.
gcc/ChangeLog: * config/riscv/genrvv-type-indexer.cc (expand_floattype): New func. (main): * config/riscv/riscv-vector-builtins-types.def (DEF_RVV_XFQF_OPS): (vint8mf8_t): (vint8mf4_t): (vint8mf2_t): (vint8m1_t): (vint8m2_t): * config/riscv/riscv-vector-builtins.cc (DEF_RVV_XFQF_OPS): (rvv_arg_type_info::get_xfqf_float_type): * config/riscv/riscv-vector-builtins.def (xfqf_vector): (xfqf_float): * config/riscv/riscv-vector-builtins.h (struct rvv_arg_type_info): * config/riscv/sifive-vector.md: * config/riscv/vector-iterators.md:
1 parent 9684e70 commit 35e6c55

File tree

7 files changed

+78
-25
lines changed

7 files changed

+78
-25
lines changed

gcc/config/riscv/genrvv-type-indexer.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ floattype (unsigned sew, int lmul_log2)
164164
return mode.str ();
165165
}
166166

167+
std::string
168+
expand_floattype (unsigned sew, int lmul_log2, unsigned nf)
169+
{
170+
if (sew != 8 || nf!= 1
171+
|| (!valid_type (sew * 4, lmul_log2 + 2, /*float_t*/ true)))
172+
return "INVALID";
173+
174+
std::stringstream mode;
175+
mode << "vfloat" << sew * 4 << to_lmul (lmul_log2 + 2) << "_t";
176+
return mode.str ();
177+
}
178+
167179
std::string
168180
floattype (unsigned sew, int lmul_log2, unsigned nf)
169181
{
@@ -276,6 +288,7 @@ main (int argc, const char **argv)
276288
fprintf (fp, " /*QLMUL1*/ INVALID,\n");
277289
fprintf (fp, " /*QLMUL1_SIGNED*/ INVALID,\n");
278290
fprintf (fp, " /*QLMUL1_UNSIGNED*/ INVALID,\n");
291+
fprintf (fp, " /*XFQF*/ INVALID,\n");
279292
for (unsigned eew : {8, 16, 32, 64})
280293
fprintf (fp, " /*EEW%d_INTERPRET*/ INVALID,\n", eew);
281294

@@ -384,6 +397,8 @@ main (int argc, const char **argv)
384397
inttype (8, /*lmul_log2*/ 0, false).c_str ());
385398
fprintf (fp, " /*QLMUL1_UNSIGNED*/ %s,\n",
386399
inttype (8, /*lmul_log2*/ 0, true).c_str ());
400+
fprintf (fp, " /*XFQF*/ %s,\n",
401+
expand_floattype (sew, lmul_log2, nf).c_str ());
387402
for (unsigned eew : {8, 16, 32, 64})
388403
{
389404
if (eew == sew)
@@ -473,6 +488,7 @@ main (int argc, const char **argv)
473488
bfloat16_wide_type (/*lmul_log2*/ 0).c_str ());
474489
fprintf (fp, " /*QLMUL1_SIGNED*/ INVALID,\n");
475490
fprintf (fp, " /*QLMUL1_UNSIGNED*/ INVALID,\n");
491+
fprintf (fp, " /*XFQF*/ INVALID,\n");
476492
for (unsigned eew : {8, 16, 32, 64})
477493
fprintf (fp, " /*EEW%d_INTERPRET*/ INVALID,\n", eew);
478494

@@ -558,6 +574,7 @@ main (int argc, const char **argv)
558574
floattype (sew / 4, /*lmul_log2*/ 0).c_str ());
559575
fprintf (fp, " /*QLMUL1_SIGNED*/ INVALID,\n");
560576
fprintf (fp, " /*QLMUL1_UNSIGNED*/ INVALID,\n");
577+
fprintf (fp, " /*XFQF*/ INVALID,\n");
561578
for (unsigned eew : {8, 16, 32, 64})
562579
fprintf (fp, " /*EEW%d_INTERPRET*/ INVALID,\n", eew);
563580

gcc/config/riscv/riscv-vector-builtins-types.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ along with GCC; see the file COPYING3. If not see
363363
#define DEF_RVV_QMACC_OPS(TYPE, REQUIRE)
364364
#endif
365365

366+
/* Use "DEF_RVV_XFQF_OPS" macro include signed integer which will
367+
be iterated and registered as intrinsic functions. */
368+
#ifndef DEF_RVV_XFQF_OPS
369+
#define DEF_RVV_XFQF_OPS(TYPE, REQUIRE)
370+
#endif
371+
366372
DEF_RVV_I_OPS (vint8mf8_t, RVV_REQUIRE_MIN_VLEN_64)
367373
DEF_RVV_I_OPS (vint8mf4_t, 0)
368374
DEF_RVV_I_OPS (vint8mf2_t, 0)
@@ -1451,6 +1457,12 @@ DEF_RVV_QMACC_OPS (vint32m2_t, 0)
14511457
DEF_RVV_QMACC_OPS (vint32m4_t, 0)
14521458
DEF_RVV_QMACC_OPS (vint32m8_t, 0)
14531459

1460+
DEF_RVV_XFQF_OPS (vint8mf8_t, 0)
1461+
DEF_RVV_XFQF_OPS (vint8mf4_t, 0)
1462+
DEF_RVV_XFQF_OPS (vint8mf2_t, 0)
1463+
DEF_RVV_XFQF_OPS (vint8m1_t, 0)
1464+
DEF_RVV_XFQF_OPS (vint8m2_t, 0)
1465+
14541466
#undef DEF_RVV_I_OPS
14551467
#undef DEF_RVV_U_OPS
14561468
#undef DEF_RVV_F_OPS
@@ -1506,3 +1518,4 @@ DEF_RVV_QMACC_OPS (vint32m8_t, 0)
15061518
#undef DEF_RVV_CRYPTO_SEW64_OPS
15071519
#undef DEF_RVV_F32_OPS
15081520
#undef DEF_RVV_QMACC_OPS
1521+
#undef DEF_RVV_XFQF_OPS

gcc/config/riscv/riscv-vector-builtins.cc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,12 @@ static const rvv_type_info qmacc_ops[] = {
551551
#include "riscv-vector-builtins-types.def"
552552
{NUM_VECTOR_TYPES, 0}};
553553

554+
/* A list of signed integer will be registered for intrinsic functions. */
555+
static const rvv_type_info xfqf_ops[] = {
556+
#define DEF_RVV_XFQF_OPS(TYPE, REQUIRE) {VECTOR_TYPE_##TYPE, REQUIRE},
557+
#include "riscv-vector-builtins-types.def"
558+
{NUM_VECTOR_TYPES, 0}};
559+
554560
static CONSTEXPR const rvv_arg_type_info rvv_arg_type_info_end
555561
= rvv_arg_type_info (NUM_BASE_TYPES);
556562

@@ -720,7 +726,8 @@ static CONSTEXPR const rvv_arg_type_info shift_wv_args[]
720726
rvv_arg_type_info_end};
721727

722728
static CONSTEXPR const rvv_arg_type_info clip_args[]
723-
= {rvv_arg_type_info (RVV_BASE_vector), rvv_arg_type_info (RVV_BASE_scalar),
729+
= {rvv_arg_type_info (RVV_BASE_xfqf_vector),
730+
rvv_arg_type_info (RVV_BASE_xfqf_float),
724731
rvv_arg_type_info_end};
725732

726733
/* A list of args for vector_type func (vector_type) function. */
@@ -2549,17 +2556,17 @@ static CONSTEXPR const rvv_op_info i_narrow_shift_vwx_ops
25492556
/* A static operand information for double demote type func (vector_type,
25502557
* shift_type) function registration. */
25512558
static CONSTEXPR const rvv_op_info u_clip_qf_ops
2552-
= {f32_ops, /* Types */
2559+
= {xfqf_ops, /* Types */
25532560
OP_TYPE_none, /* Suffix */
2554-
rvv_arg_type_info (RVV_BASE_eew8_index), /* Return type */
2561+
rvv_arg_type_info (RVV_BASE_unsigned_vector), /* Return type */
25552562
clip_args /* Args */};
25562563

25572564
/* A static operand information for double demote type func (vector_type,
25582565
* shift_type) function registration. */
25592566
static CONSTEXPR const rvv_op_info i_clip_qf_ops
2560-
= {f32_ops, /* Types */
2567+
= {xfqf_ops, /* Types */
25612568
OP_TYPE_none, /* Suffix */
2562-
rvv_arg_type_info (RVV_BASE_signed_eew8_index), /* Return type */
2569+
rvv_arg_type_info (RVV_BASE_vector), /* Return type */
25632570
clip_args /* Args */};
25642571

25652572
/* A static operand information for double demote type func (vector_type,
@@ -3008,7 +3015,7 @@ static CONSTEXPR const function_type_info function_types[] = {
30083015
QUAD_FIX_UNSIGNED, OCT_TRUNC, DOUBLE_TRUNC_SCALAR, DOUBLE_TRUNC_SIGNED, \
30093016
DOUBLE_TRUNC_UNSIGNED, DOUBLE_TRUNC_UNSIGNED_SCALAR, \
30103017
DOUBLE_TRUNC_BFLOAT_SCALAR, DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \
3011-
LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, EEW8_INTERPRET, \
3018+
LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, XFQF, EEW8_INTERPRET, \
30123019
EEW16_INTERPRET, EEW32_INTERPRET, EEW64_INTERPRET, BOOL1_INTERPRET, \
30133020
BOOL2_INTERPRET, BOOL4_INTERPRET, BOOL8_INTERPRET, BOOL16_INTERPRET, \
30143021
BOOL32_INTERPRET, BOOL64_INTERPRET, SIGNED_EEW8_LMUL1_INTERPRET, \
@@ -3060,6 +3067,7 @@ static CONSTEXPR const function_type_info function_types[] = {
30603067
VECTOR_TYPE_##QLMUL1, \
30613068
VECTOR_TYPE_##QLMUL1_SIGNED, \
30623069
VECTOR_TYPE_##QLMUL1_UNSIGNED, \
3070+
VECTOR_TYPE_##XFQF, \
30633071
VECTOR_TYPE_##EEW8_INTERPRET, \
30643072
VECTOR_TYPE_##EEW16_INTERPRET, \
30653073
VECTOR_TYPE_##EEW32_INTERPRET, \
@@ -3579,6 +3587,19 @@ rvv_arg_type_info::get_scalar_const_ptr_type (vector_type_index type_idx) const
35793587
return builtin_types[type_idx].scalar_const_ptr;
35803588
}
35813589

3590+
tree
3591+
rvv_arg_type_info::get_xfqf_float_type (vector_type_index type_idx) const
3592+
{
3593+
/* Convert vint8 types into float types.
3594+
Note:
3595+
- According to riscv-vector-builtins-types.def, the index of an unsigned
3596+
type is always one greater than its corresponding signed type. */
3597+
if (type_idx >= VECTOR_TYPE_vint8mf8_t && type_idx <= VECTOR_TYPE_vuint8m2_t)
3598+
return builtin_types[VECTOR_TYPE_vfloat32m1_t].scalar;
3599+
else
3600+
return NULL_TREE;
3601+
}
3602+
35823603
vector_type_index
35833604
rvv_arg_type_info::get_function_type_index (vector_type_index type_idx) const
35843605
{

gcc/config/riscv/riscv-vector-builtins.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ along with GCC; see the file COPYING3. If not see
7575
QUAD_FIX_UNSIGNED, OCT_TRUNC, DOUBLE_TRUNC_SCALAR, DOUBLE_TRUNC_SIGNED, \
7676
DOUBLE_TRUNC_UNSIGNED, DOUBLE_TRUNC_UNSIGNED_SCALAR, \
7777
DOUBLE_TRUNC_BFLOAT_SCALAR, DOUBLE_TRUNC_BFLOAT, DOUBLE_TRUNC_FLOAT, FLOAT, \
78-
LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, EEW8_INTERPRET, \
78+
LMUL1, WLMUL1, QLMUL1, QLMUL1_SIGNED, QLMUL1_UNSIGNED, XFQF, EEW8_INTERPRET, \
7979
EEW16_INTERPRET, EEW32_INTERPRET, EEW64_INTERPRET, BOOL1_INTERPRET, \
8080
BOOL2_INTERPRET, BOOL4_INTERPRET, BOOL8_INTERPRET, BOOL16_INTERPRET, \
8181
BOOL32_INTERPRET, BOOL64_INTERPRET, SIGNED_EEW8_LMUL1_INTERPRET, \
@@ -700,6 +700,7 @@ DEF_RVV_BASE_TYPE (widen_lmul1_vector, get_vector_type (type_idx))
700700
DEF_RVV_BASE_TYPE (quad_lmul1_vector, get_vector_type (type_idx))
701701
DEF_RVV_BASE_TYPE (quad_lmul1_signed_vector, get_vector_type (type_idx))
702702
DEF_RVV_BASE_TYPE (quad_lmul1_unsigned_vector, get_vector_type (type_idx))
703+
DEF_RVV_BASE_TYPE (xfqf_vector, get_vector_type (type_idx))
703704
DEF_RVV_BASE_TYPE (eew8_interpret, get_vector_type (type_idx))
704705
DEF_RVV_BASE_TYPE (eew16_interpret, get_vector_type (type_idx))
705706
DEF_RVV_BASE_TYPE (eew32_interpret, get_vector_type (type_idx))
@@ -727,6 +728,7 @@ DEF_RVV_BASE_TYPE (vlmul_ext_x32, get_vector_type (type_idx))
727728
DEF_RVV_BASE_TYPE (vlmul_ext_x64, get_vector_type (type_idx))
728729
DEF_RVV_BASE_TYPE (size_ptr, build_pointer_type (size_type_node))
729730
DEF_RVV_BASE_TYPE (tuple_subpart, get_tuple_subpart_type (type_idx))
731+
DEF_RVV_BASE_TYPE (xfqf_float, get_xfqf_float_type (type_idx))
730732

731733
DEF_RVV_VXRM_ENUM (RNU, VXRM_RNU)
732734
DEF_RVV_VXRM_ENUM (RNE, VXRM_RNE)

gcc/config/riscv/riscv-vector-builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ struct rvv_arg_type_info
296296
tree get_vector_type (vector_type_index) const;
297297
tree get_tree_type (vector_type_index) const;
298298
tree get_tuple_subpart_type (vector_type_index) const;
299+
tree get_xfqf_float_type (vector_type_index) const;
299300
};
300301

301302
/* Static information for each operand. */

gcc/config/riscv/sifive-vector.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
(set_attr "mode" "<MODE>")])
165165

166166
(define_insn "@pred_sf_vfnrclip<v_su><mode>_x_f_qf"
167-
[(set (match_operand:<SF_XFQF> 0 "register_operand" "=vd, vd, vr, vr")
168-
(if_then_else:<SF_XFQF>
167+
[(set (match_operand:SF_XF 0 "register_operand" "=vd, vd, vr, vr")
168+
(if_then_else:SF_XF
169169
(unspec:<VM>
170170
[(match_operand:<VM> 1 "vector_mask_operand" " vm, vm,Wc1,Wc1")
171171
(match_operand 5 "vector_length_operand" " rK, rK, rK, rK")
@@ -174,10 +174,10 @@
174174
(match_operand 8 "const_int_operand" " i, i, i, i")
175175
(reg:SI VL_REGNUM)
176176
(reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE)
177-
(unspec:<SF_XFQF>
177+
(unspec:SF_XF
178178
[(match_operand:SF 4 "register_operand" " f, f, f, f")
179-
(match_operand:SF_VF 3 "register_operand" " vr, vr, vr, vr")] SF_VFNRCLIP)
180-
(match_operand:<SF_XFQF> 2 "vector_merge_operand" " vu, 0, vu, 0")))]
179+
(match_operand:<SF_XFQF> 3 "register_operand" " vr, vr, vr, vr")] SF_VFNRCLIP)
180+
(match_operand:SF_XF 2 "vector_merge_operand" " vu, 0, vu, 0")))]
181181
"TARGET_VECTOR && TARGET_XSFVFNRCLIPXFQF"
182182
"sf.vfnrclip.x<v_su>.f.qf\t%0,%3,%4%p1"
183183
[(set_attr "type" "sf_vfnrclip")

gcc/config/riscv/vector-iterators.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,24 +4794,23 @@
47944794
(RVVM1SI "rvvm1qi")
47954795
])
47964796

4797-
(define_mode_iterator SF_VF [
4798-
(RVVM8SF "TARGET_VECTOR_ELEN_FP_32") (RVVM4SF "TARGET_VECTOR_ELEN_FP_32") (RVVM2SF "TARGET_VECTOR_ELEN_FP_32")
4799-
(RVVM1SF "TARGET_VECTOR_ELEN_FP_32") (RVVMF2SF "TARGET_VECTOR_ELEN_FP_32 && TARGET_MIN_VLEN > 32")
4797+
(define_mode_iterator SF_XF [
4798+
RVVM2QI RVVM1QI RVVMF2QI RVVMF4QI (RVVMF8QI "TARGET_MIN_VLEN > 32")
48004799
])
48014800

48024801

48034802
(define_mode_attr SF_XFQF [
4804-
(RVVMF2SF "RVVMF8QI")
4805-
(RVVM1SF "RVVMF4QI")
4806-
(RVVM2SF "RVVMF2QI")
4807-
(RVVM4SF "RVVM1QI")
4808-
(RVVM8SF "RVVM2QI")
4803+
(RVVMF8QI "RVVMF2SF")
4804+
(RVVMF4QI "RVVM1SF")
4805+
(RVVMF2QI "RVVM2SF")
4806+
(RVVM1QI "RVVM4SF")
4807+
(RVVM2QI "RVVM8SF")
48094808
])
48104809

48114810
(define_mode_attr sf_xfqf [
4812-
(RVVMF2SF "rvvmf8qi")
4813-
(RVVM1SF "rvvmf4qi")
4814-
(RVVM2SF "rvvmf2qi")
4815-
(RVVM4SF "rvvm1qi")
4816-
(RVVM8SF "rvvm2qi")
4811+
(RVVMF8QI "rvvmf2sf")
4812+
(RVVMF4QI "rvvm1sf")
4813+
(RVVMF2QI "rvvm2sf")
4814+
(RVVM1QI "rvvm4sf")
4815+
(RVVM2QI "rvvm8sf")
48174816
])

0 commit comments

Comments
 (0)