target/arm: Implement SVE2 MATCH, NMATCH
RFC PATCH 1/1 target/arm: Implement SVE2 MATCH, NMATCH
---
Submitting this for early review. I'm working with Richard on SVE2 support for qemu. I'll be attempting to tackle the insns in the 'SVE2 integer add/subtract narrow high part' category next [1].
[1] ISA manual: https://static.docs.arm.com/ddi0602/d/ISA_A64_xml_futureA-2019-12_OPT.pdf (page 2950)
target/arm/helper-sve.h | 10 +++++++++ target/arm/sve.decode | 5 +++++ target/arm/sve_helper.c | 29 +++++++++++++++++++++++++ target/arm/translate-sve.c | 43 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+)
target/arm/helper-sve.h +10 -0
@@ -2516,6 +2516,16 @@ DEF_HELPER_FLAGS_3(sve2_uqrshrnt_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) DEF_HELPER_FLAGS_3(sve2_uqrshrnt_s, TCG_CALL_NO_RWG, void, ptr, ptr, i32) DEF_HELPER_FLAGS_3(sve2_uqrshrnt_d, TCG_CALL_NO_RWG, void, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (sve2_match_zpzz_b,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (sve2_match_zpzz_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) + +DEF_HELPER_FLAGS_5 (sve2_nmatch_zpzz_b,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_5 (sve2_nmatch_zpzz_h,TCG_CALL_NO_RWG , + void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_6 (sve2_faddp_zpzz_h,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_6(sve2_faddp_zpzz_s, TCG_CALL_NO_RWG,
target/arm/sve.decode +5 -0
@@ -1305,6 +1305,11 @@ UQSHRNT 01000101 .. 1 ..... 00 1101 ..... ..... @rd_rn_tszimm_shr UQRSHRNB 01000101 .. 1 ..... 00 1110 ..... ..... @rd_rn_tszimm_shr UQRSHRNT 01000101 .. 1 ..... 00 1111 ..... ..... @rd_rn_tszimm_shr +### SVE2 Character Match + +MATCH 01000101 .. 1 ..... 100 ... ..... 0 .... @pd_pg_rn_rm +NMATCH 01000101 .. 1 ..... 100 ... ..... 1 .... @pd_pg_rn_rm + ## SVE2 floating-point pairwise operations FADDP 01100100 .. 010 00 0 100 ... ..... ..... @rdn_pg_rm
target/arm/sve_helper.c +29 -0
@@ -6890,3 +6890,32 @@ DO_ST1_ZPZ_D(dd_be, zd, MO_64)#undef DO_ST1_ZPZ_S#undef DO_ST1_ZPZ_D + +#define DO_ZPZZ_CHAR_MATCH (NAME ,TYPE ,H ,EQUALS ) \ +void HELPER(NAME)(void *vd, void *vn, void *vm, void *vg, uint32_t desc) \ +{ \ + intptr_t i, opr_sz = simd_oprsz(desc); \ + for (i = 0; i < opr_sz; i += sizeof(TYPE)) { \ + uint16_t pg = *(uint16_t *)(vg + H1_2(i >> 3)); \ + uint16_t *pd = (uint16_t *)(vd + H1_2(i >> 3)); \ + *pd = (*pd & ~1) | ((0 & EQUALS) | (1 & !EQUALS)); \ + if (pg & 1) { \ + TYPE nn = *(TYPE *)(vn + H(i)); \ + for (intptr_t j = 0; j < 16; j += sizeof(TYPE)) { \ + TYPE mm = *(TYPE *)(vm + H(i * 16 + j)); \ + bool eq = nn == mm; \ + if ((eq && EQUALS) || (!eq && !EQUALS)) { \ + *pd = (*pd & ~1) | ((1 & EQUALS) | (0 & !EQUALS)); \ + } \ + } \ + } \ + } \ +} + +DO_ZPZZ_CHAR_MATCH(sve2_match_zpzz_b, uint8_t, H1, true) +DO_ZPZZ_CHAR_MATCH(sve2_match_zpzz_h, uint16_t, H1_2, true) + +DO_ZPZZ_CHAR_MATCH(sve2_nmatch_zpzz_b, uint8_t, H1, false) +DO_ZPZZ_CHAR_MATCH(sve2_nmatch_zpzz_h, uint16_t, H1_2, false) + +#undef DO_ZPZZ_CHAR_MATCH
target/arm/translate-sve.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.17.1
target/arm/sve_helper.c DO_ST1_ZPZ_D(dd_be, zd, MO_64) · line 6902
Quoted 9 lines · Stephen Long
target/arm/sve_helper.c +9
-0+#define DO_ZPZZ_CHAR_MATCH (NAME ,TYPE ,H ,EQUALS ) \ +void HELPER(NAME)(void *vd, void *vn, void *vm, void *vg, uint32_t desc) \ +{ \ + intptr_t i, opr_sz = simd_oprsz(desc); \ + for (i = 0; i < opr_sz; i += sizeof(TYPE)) { \ + uint16_t pg = *(uint16_t *)(vg + H1_2(i >> 3)); \ + uint16_t *pd = (uint16_t *)(vd + H1_2(i >> 3)); \ + *pd = (*pd & ~1) | ((0 & EQUALS) | (1 & !EQUALS)); \ + if (pg & 1) { \
The important error here is that the predicate is not always the low bit. When operating on bytes, every bit of the predicate is significant. When operating on halfwords, every even bit of the predicate is significant. In addition, when operating on halfwords, every odd bit of the result predicate must be zero.
Which is why, generally, I have constructed the output predicate as we go. See, for instance, DO_CMP_PPZZ.
target/arm/sve_helper.c DO_ST1_ZPZ_D(dd_be, zd, MO_64) · line 6905
Quoted 3 lines
target/arm/sve_helper.c +3
-0+TYPE nn = *(TYPE *)(vn +H (i)); \ +for (intptr_t j =0 ; j <16 ; j +=sizeof (TYPE )) { \ +TYPE mm = *(TYPE *)(vm +H (i *16 + j)); \
mm needs to start at the beginning of the segment, which in this case is (i & -16). You don't need the elements of mm in any particular order (all of them are significant), so you can drop the use of H() here.
Therefore the indexing for mm should be vm + (i & -16) + j.
target/arm/sve_helper.c DO_ST1_ZPZ_D(dd_be, zd, MO_64) · line 6909
Quoted 4 lines
target/arm/sve_helper.c +4
-0+bool eq = nn == mm; \ +if ((eq &&EQUALS ) || (!eq && !EQUALS )) { \ + *pd = (*pd & ~1 ) | ((1 &EQUALS ) | (0 & !EQUALS )); \ + } \
It might be handy to split out the inner loop to a helper function, as, while the basic loop is ok, there are tricks that can improve it, so that we're comparing 8 bytes at a time.
Quoted 16 lines
target/arm/translate-sve.c +16
-0+static bool do_sve2_zpzz_char_match (DisasContext *s,arg_rprr_esz *a, +gen_helper_gvec_4 *fn) +{ +if (!dc_isar_feature (aa64_sve2, s)) { +return false; + } +if (fn ==NULL ) { +return false; + } +if (sve_access_check (s)) { +unsigned vsz =vec_full_reg_size (s); +unsigned psz =pred_full_reg_size (s); +int dofs =pred_full_reg_offset (s, a->rd); +int nofs =vec_full_reg_offset (s, a->rn); +int mofs =vec_full_reg_offset (s, a->rm); +int gofs =pred_full_reg_offset (s, a->pg);
target/arm/translate-sve.c static bool trans_UQRSHRNT(DisasContext *s, arg_rri_esz *a) · line 7274
Quoted 10 lines
target/arm/translate-sve.c +10
-0+ +/* Save a copy if the destination overwrites the guarding predicate */ +int tofs = gofs; +if (a->rd == a->pg) { + tofs = offsetof(CPUARMState, vfp.preg_tmp); +tcg_gen_gvec_mov (0 , tofs, gofs, psz, psz); + } + +tcg_gen_gvec_4_ool (dofs, nofs, mofs, gofs, vsz, vsz,0 , fn); +do_predtest (s, dofs, tofs, psz /8 );
You can avoid the copy and the predtest by using the iter_predtest_* functions and returning the flags result directly from the helper. Again, see DO_CMP_PPZZ.
r~