Skip to content

Commit e5ff754

Browse files
committed
Add intrinsic support for XSFVFNRCLIPXFQF extension
1 parent d6230d5 commit e5ff754

10 files changed

+165
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,31 @@ class vnclip : public function_base
705705
}
706706
};
707707

708+
/* Implements vfnrclip. */
709+
class vfnrclip : public function_base
710+
{
711+
public:
712+
bool has_merge_operand_p () const override { return false; }
713+
bool may_require_qfrm_p () const override { return true; }
714+
bool can_be_overloaded_p (enum predication_type_index pred) const override
715+
{
716+
if (pred == PRED_TYPE_mu || pred == PRED_TYPE_tu || pred == PRED_TYPE_tumu)
717+
{
718+
return true;
719+
}
720+
}
721+
722+
rtx expand (function_expander &e) const override
723+
{
724+
if (e.op_info->op == OP_TYPE_f_qf)
725+
{
726+
return e.use_exact_insn (
727+
code_for_pred_fnr_clip (ZERO_EXTEND, e.vector_mode ()));
728+
gcc_unreachable ();
729+
}
730+
}
731+
};
732+
708733
/* Implements vmseq/vmsne/vmslt/vmsgt/vmsle/vmsge. */
709734
template<rtx_code CODE>
710735
class icmp : public function_base
@@ -2657,6 +2682,8 @@ static CONSTEXPR const sat_op<UNSPEC_VSSRL> vssrl_obj;
26572682
static CONSTEXPR const sat_op<UNSPEC_VSSRA> vssra_obj;
26582683
static CONSTEXPR const vnclip<UNSPEC_VNCLIP> vnclip_obj;
26592684
static CONSTEXPR const vnclip<UNSPEC_VNCLIPU> vnclipu_obj;
2685+
static CONSTEXPR const vfnrclip x_obj;
2686+
static CONSTEXPR const vfnrclip xu_obj;
26602687
static CONSTEXPR const mask_logic<AND> vmand_obj;
26612688
static CONSTEXPR const mask_nlogic<AND> vmnand_obj;
26622689
static CONSTEXPR const mask_notlogic<AND> vmandn_obj;
@@ -2991,6 +3018,8 @@ BASE (vssra)
29913018
BASE (vssrl)
29923019
BASE (vnclip)
29933020
BASE (vnclipu)
3021+
BASE (x)
3022+
BASE (xu)
29943023
BASE (vmand)
29953024
BASE (vmnand)
29963025
BASE (vmandn)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ extern const function_base *const vssra;
122122
extern const function_base *const vssrl;
123123
extern const function_base *const vnclip;
124124
extern const function_base *const vnclipu;
125+
extern const function_base *const x;
126+
extern const function_base *const xu;
125127
extern const function_base *const vmand;
126128
extern const function_base *const vmnand;
127129
extern const function_base *const vmandn;

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,43 @@ struct sf_vqmacc_def : public build_base
13201320
}
13211321
};
13221322

1323+
/* sf_vfnrclip_def class. Handle instructions like vfnrclip. */
1324+
struct sf_vfnrclip_def : public build_base
1325+
{
1326+
char *get_name (function_builder &b, const function_instance &instance,
1327+
bool overloaded_p) const override
1328+
{
1329+
/* Return nullptr if it can not be overloaded. */
1330+
if (overloaded_p && !instance.base->can_be_overloaded_p (instance.pred))
1331+
return nullptr;
1332+
1333+
b.append_name ("__riscv_sf_vfnrclip_");
1334+
printf("aaaaaa %s\n", instance.base_name);
1335+
b.append_name (instance.base_name);
1336+
1337+
if (!overloaded_p)
1338+
{
1339+
/* vop --> vop_<op>. */
1340+
b.append_name (operand_suffixes[instance.op_info->op]);
1341+
/* vop_v --> vop_v_<type>. */
1342+
b.append_name (type_suffixes[instance.type.index].vector);
1343+
/* vop_<op> --> vop_<op>_<type>.
1344+
vector_type_index ret_type_idx
1345+
= instance.op_info->ret.get_function_type_index (instance.type.index);
1346+
b.append_name (type_suffixes[ret_type_idx].vector); */
1347+
}
1348+
1349+
/* According to rvv-intrinsic-doc, it does not add "_m" suffix
1350+
for vop_m C++ overloaded API.*/
1351+
if (overloaded_p && (instance.pred == PRED_TYPE_tu || instance.pred == PRED_TYPE_mu ||
1352+
instance.pred == PRED_TYPE_tumu))
1353+
{
1354+
b.append_name (predication_suffixes[instance.pred]);
1355+
}
1356+
return b.finish_name ();
1357+
}
1358+
};
1359+
13231360
SHAPE(vsetvl, vsetvl)
13241361
SHAPE(vsetvl, vsetvlmax)
13251362
SHAPE(loadstore, loadstore)
@@ -1355,4 +1392,5 @@ SHAPE(crypto_vv, crypto_vv)
13551392
SHAPE(crypto_vi, crypto_vi)
13561393
SHAPE(crypto_vv_no_op_type, crypto_vv_no_op_type)
13571394
SHAPE(sf_vqmacc, sf_vqmacc)
1395+
SHAPE(sf_vfnrclip, sf_vfnrclip)
13581396
} // end namespace riscv_vector

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern const function_shape *const crypto_vv;
6060
extern const function_shape *const crypto_vi;
6161
extern const function_shape *const crypto_vv_no_op_type;
6262
extern const function_shape *const sf_vqmacc;
63+
extern const function_shape *const sf_vfnrclip;
6364
}
6465

6566
} // end namespace riscv_vector

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ static CONSTEXPR const rvv_arg_type_info shift_wv_args[]
711711
rvv_arg_type_info (RVV_BASE_double_trunc_unsigned_vector),
712712
rvv_arg_type_info_end};
713713

714+
static CONSTEXPR const rvv_arg_type_info clip_args[]
715+
= {rvv_arg_type_info (RVV_BASE_vector),
716+
rvv_arg_type_info (RVV_BASE_double_trunc_unsigned_vector),
717+
rvv_arg_type_info_end};
718+
714719
/* A list of args for vector_type func (vector_type) function. */
715720
static CONSTEXPR const rvv_arg_type_info v_args[]
716721
= {rvv_arg_type_info (RVV_BASE_vector), rvv_arg_type_info_end};
@@ -2521,6 +2526,22 @@ static CONSTEXPR const rvv_op_info i_narrow_shift_vwx_ops
25212526
rvv_arg_type_info (RVV_BASE_double_trunc_vector), /* Return type */
25222527
v_size_args /* Args */};
25232528

2529+
/* A static operand information for double demote type func (vector_type,
2530+
* shift_type) function registration. */
2531+
static CONSTEXPR const rvv_op_info u_clip_qf_ops
2532+
= {wextu_ops, /* Types */
2533+
OP_TYPE_f_qf, /* Suffix */
2534+
rvv_arg_type_info (RVV_BASE_double_trunc_unsigned_vector), /* Return type */
2535+
clip_args /* Args */};
2536+
2537+
/* A static operand information for double demote type func (vector_type,
2538+
* shift_type) function registration. */
2539+
static CONSTEXPR const rvv_op_info i_clip_qf_ops
2540+
= {wexti_ops, /* Types */
2541+
OP_TYPE_f_qf, /* Suffix */
2542+
rvv_arg_type_info (RVV_BASE_double_trunc_signed_vector), /* Return type */
2543+
clip_args /* Args */};
2544+
25242545
/* A static operand information for double demote type func (vector_type,
25252546
* size_t) function registration. */
25262547
static CONSTEXPR const rvv_op_info u_narrow_shift_vwx_ops

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ DEF_RVV_OP_TYPE (xu_w)
636636
DEF_RVV_OP_TYPE (s)
637637
DEF_RVV_OP_TYPE (4x8x4)
638638
DEF_RVV_OP_TYPE (2x8x2)
639+
DEF_RVV_OP_TYPE (f_qf)
639640

640641
DEF_RVV_PRED_TYPE (ta)
641642
DEF_RVV_PRED_TYPE (tu)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ enum required_ext
129129
ZVFBFWMA_EXT, /* Zvfbfwma extension */
130130
XSFVQMACCQOQ_EXT, /* XSFVQMACCQOQ extension */
131131
XSFVQMACCDOD_EXT, /* XSFVQMACCDOD extension */
132+
XSFVFNRCLIPXFQF_EXT, /* XSFVFNRCLIPXFQF extension*/
132133
/* Please update below to isa_name func when add or remove enum type(s). */
133134
};
134135

@@ -166,6 +167,8 @@ static inline const char * required_ext_to_isa_name (enum required_ext required)
166167
return "xsfvqmaccqoq";
167168
case XSFVQMACCDOD_EXT:
168169
return "xsfvqmaccdod";
170+
case XSFVFNRCLIPXFQF_EXT:
171+
return "xsfvfnrclipxfqf";
169172
default:
170173
gcc_unreachable ();
171174
}
@@ -207,6 +210,8 @@ static inline bool required_extensions_specified (enum required_ext required)
207210
return TARGET_XSFVQMACCQOQ;
208211
case XSFVQMACCDOD_EXT:
209212
return TARGET_XSFVQMACCDOD;
213+
case XSFVFNRCLIPXFQF_EXT:
214+
return TARGET_XSFVFNRCLIPXFQF;
210215
default:
211216
gcc_unreachable ();
212217
}
@@ -351,6 +356,8 @@ struct function_group_info
351356
return TARGET_XSFVQMACCQOQ;
352357
case XSFVQMACCDOD_EXT:
353358
return TARGET_XSFVQMACCDOD;
359+
case XSFVFNRCLIPXFQF_EXT:
360+
return TARGET_XSFVFNRCLIPXFQF;
354361
default:
355362
gcc_unreachable ();
356363
}
@@ -570,6 +577,9 @@ class function_base
570577
/* Return true if intrinsics maybe require vxrm operand. */
571578
virtual bool may_require_vxrm_p () const;
572579

580+
/* Return true if intrinsics maybe require qfrm operand. */
581+
virtual bool may_require_qfrm_p () const;
582+
573583
/* Return true if intrinsics maybe require frm operand. */
574584
virtual bool may_require_frm_p () const;
575585

@@ -846,6 +856,14 @@ function_base::may_require_vxrm_p () const
846856
return false;
847857
}
848858

859+
/* We choose to return false by default since most of the intrinsics does
860+
not need qfrm operand. */
861+
inline bool
862+
function_base::may_require_qfrm_p () const
863+
{
864+
return false;
865+
}
866+
849867
/* Since most of intrinsics can be overloaded, we set it true by default. */
850868
inline bool
851869
function_base::can_be_overloaded_p (enum predication_type_index) const

gcc/config/riscv/riscv.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
;; vsmul vector single-width fractional multiply with rounding and saturation instructions
392392
;; vsshift vector single-width scaling shift instructions
393393
;; vnclip vector narrowing fixed-point clip instructions
394+
;; vsfclip vector fp32 to int8 ranged clip instructions
394395
;; 13. Vector floating-point instructions
395396
;; vfalu vector single-width floating-point add/subtract instructions
396397
;; vfwalu vector widening floating-point add/subtract instructions
@@ -487,7 +488,7 @@
487488
vlsegde,vssegte,vlsegds,vssegts,vlsegdux,vlsegdox,vssegtux,vssegtox,vlsegdff,
488489
vialu,viwalu,vext,vicalu,vshift,vnshift,vicmp,viminmax,
489490
vimul,vidiv,viwmul,vimuladd,vsfmuladd,viwmuladd,vimerge,vimov,
490-
vsalu,vaalu,vsmul,vsshift,vnclip,
491+
vsalu,vaalu,vsmul,vsshift,vnclip,vsfclip,
491492
vfalu,vfwalu,vfmul,vfdiv,vfwmul,vfmuladd,vfwmuladd,vfsqrt,vfrecp,
492493
vfcmp,vfminmax,vfsgnj,vfclass,vfmerge,vfmov,
493494
vfcvtitof,vfcvtftoi,vfwcvtitof,vfwcvtftoi,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ DEF_RVV_FUNCTION (vqmaccsu, sf_vqmacc, none_tu_preds, i_su_qdvv_ops)
1616
DEF_RVV_FUNCTION (vqmaccus, sf_vqmacc, none_tu_preds, i_us_qdvv_ops)
1717
#undef REQUIRED_EXTENSIONS
1818

19+
#define REQUIRED_EXTENSIONS XSFVFNRCLIPXFQF_EXT
20+
DEF_RVV_FUNCTION (xu, sf_vfnrclip, full_preds, u_clip_qf_ops)
21+
DEF_RVV_FUNCTION (x, sf_vfnrclip, full_preds, i_clip_qf_ops)
22+
23+
#undef REQUIRED_EXTENSIONS
24+
1925
#undef DEF_RVV_FUNCTION

gcc/config/riscv/sifive-vector.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,50 @@
141141
"sf.vqmaccus.4x8x4\t%0,%3,%4"
142142
[(set_attr "type" "vsfmuladd")
143143
(set_attr "mode" "<MODE>")])
144+
145+
;; CLIP
146+
(define_insn "@pred_fnr_clip<v_su><mode>"
147+
[(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand" "=vd,vd, vr, vr,vd, vr, &vr, &vr, vd, vr, &vr, &vr")
148+
(if_then_else:<V_DOUBLE_TRUNC>
149+
(unspec:<VM>
150+
[(match_operand:<VM> 1 "vector_mask_operand" " vm,vm,Wc1,Wc1,vm,Wc1,vmWc1,vmWc1, vm,Wc1,vmWc1,vmWc1")
151+
(match_operand 5 "vector_length_operand" " rK,rK, rK, rK,rK, rK, rK, rK, rK, rK, rK, rK")
152+
(match_operand 6 "const_int_operand" " i, i, i, i, i, i, i, i, i, i, i, i")
153+
(match_operand 7 "const_int_operand" " i, i, i, i, i, i, i, i, i, i, i, i")
154+
(match_operand 8 "const_int_operand" " i, i, i, i, i, i, i, i, i, i, i, i")
155+
(match_operand 9 "const_int_operand" " i, i, i, i, i, i, i, i, i, i, i, i")
156+
(reg:SI VL_REGNUM)
157+
(reg:SI VTYPE_REGNUM)
158+
(reg:SI VXRM_REGNUM)] UNSPEC_VPREDICATE)
159+
(unspec:<V_DOUBLE_TRUNC>
160+
[(match_operand:VWEXTI 3 "register_operand" " vr,vr, vr, vr, 0, 0, vr, vr, 0, 0, vr, vr")
161+
(match_operand:<V_DOUBLE_TRUNC> 4 "vector_shift_operand" " 0, 0, 0, 0,vr, vr, vr, vr, vk, vk, vk, vk")] VNCLIP)
162+
(match_operand:<V_DOUBLE_TRUNC> 2 "vector_merge_operand" " 0,vu, 0, vu,vu, vu, vu, 0, vu, vu, vu, 0")))]
163+
"TARGET_VECTOR && TARGET_XSFVFNRCLIPXFQF"
164+
"sf.vfnrclip.x.f.qf%o4\t%0,%3,%v4%p1"
165+
[(set_attr "type" "vsfclip")
166+
(set_attr "mode" "<V_DOUBLE_TRUNC>")
167+
(set_attr "spec_restriction" "thv,thv,thv,thv,thv,thv,none,none,thv,thv,none,none")])
168+
169+
(define_insn "@pred_fnr_clip<v_su><mode>_scalar"
170+
[(set (match_operand:<V_DOUBLE_TRUNC> 0 "register_operand" "=vd, vd, vr, vr, &vr, &vr")
171+
(if_then_else:<V_DOUBLE_TRUNC>
172+
(unspec:<VM>
173+
[(match_operand:<VM> 1 "vector_mask_operand" " vm, vm,Wc1,Wc1,vmWc1,vmWc1")
174+
(match_operand 5 "vector_length_operand" " rK, rK, rK, rK, rK, rK")
175+
(match_operand 6 "const_int_operand" " i, i, i, i, i, i")
176+
(match_operand 7 "const_int_operand" " i, i, i, i, i, i")
177+
(match_operand 8 "const_int_operand" " i, i, i, i, i, i")
178+
(match_operand 9 "const_int_operand" " i, i, i, i, i, i")
179+
(reg:SI VL_REGNUM)
180+
(reg:SI VTYPE_REGNUM)
181+
(reg:SI VXRM_REGNUM)] UNSPEC_VPREDICATE)
182+
(unspec:<V_DOUBLE_TRUNC>
183+
[(match_operand:VWEXTI 3 "register_operand" " 0, 0, 0, 0, vr, vr")
184+
(match_operand 4 "pmode_reg_or_uimm5_operand" " rK, rK, rK, rK, rK, rK")] VNCLIP)
185+
(match_operand:<V_DOUBLE_TRUNC> 2 "vector_merge_operand" " vu, 0, vu, 0, vu, 0")))]
186+
"TARGET_VECTOR && TARGET_XSFVFNRCLIPXFQF"
187+
"sf.vfnrclip.xu.f.qf%o4\t%0,%3,%4%p1"
188+
[(set_attr "type" "vsfclip")
189+
(set_attr "mode" "<V_DOUBLE_TRUNC>")
190+
(set_attr "spec_restriction" "thv,thv,thv,thv,none,none")])

0 commit comments

Comments
 (0)