target/arm: Vectorize USHL and SSHL
PATCH v2 1/1 target/arm: Vectorize USHL and SSHL
These instructions shift left or right depending on the sign of the input, and 7 bits are significant to the shift. This requires several masks and selects in addition to the actual shifts to form the complete answer.
That said, the operation is still a small improvement even for two 64-bit elements -- 13 vector operations instead of 2 * 7 integer operations.
---
Changes in v2:
* Clarify some commentary.
* Remove unreachable out-of-line functions.
* Use more comparisons more favorable to x86_64, and does not affect other vector hosts.
Example code generation (x86_64 and aarch64):
USHL:
0x564bc522df1b: c5 e9 ef d2 vpxor %xmm2, %xmm2, %xmm2 0x564bc522df1f: c5 e9 fa d1 vpsubd %xmm1, %xmm2, %xmm2 0x564bc522df23: c5 fa 7e 1d 75 00 00 00 vmovq 0x75(%rip), %xmm3 0x564bc522df2b: c5 f1 db cb vpand %xmm3, %xmm1, %xmm1 0x564bc522df2f: c5 e9 db d3 vpand %xmm3, %xmm2, %xmm2 0x564bc522df33: c4 e2 79 47 d9 vpsllvd %xmm1, %xmm0, %xmm3 0x564bc522df38: c4 e2 79 45 c2 vpsrlvd %xmm2, %xmm0, %xmm0 0x564bc522df3d: c5 fa 7e 25 63 00 00 00 vmovq 0x63(%rip), %xmm4 0x564bc522df45: c5 d9 66 c9 vpcmpgtd %xmm1, %xmm4, %xmm1 0x564bc522df49: c5 d9 66 d2 vpcmpgtd %xmm2, %xmm4, %xmm2 0x564bc522df4d: c5 e1 db c9 vpand %xmm1, %xmm3, %xmm1 0x564bc522df51: c5 f9 db c2 vpand %xmm2, %xmm0, %xmm0 0x564bc522df55: c5 f1 eb c0 vpor %xmm0, %xmm1, %xmm0
0xaaaac8a29414: 6ea0b822 neg v2.4s, v1.4s 0xaaaac8a29418: 6f00e623 movi v3.2d, #0x0000ff000000ff 0xaaaac8a2941c: 4e231c21 and v1.16b, v1.16b, v3.16b 0xaaaac8a29420: 4e231c42 and v2.16b, v2.16b, v3.16b 0xaaaac8a29424: 6ea14403 ushl v3.4s, v0.4s, v1.4s 0xaaaac8a29428: 6ea0b844 neg v4.4s, v2.4s 0xaaaac8a2942c: 6ea44400 ushl v0.4s, v0.4s, v4.4s 0xaaaac8a29430: 4f010404 movi v4.4s, #0x20 0xaaaac8a29434: 4ea13481 cmgt v1.4s, v4.4s, v1.4s 0xaaaac8a29438: 4ea23482 cmgt v2.4s, v4.4s, v2.4s 0xaaaac8a2943c: 4e211c61 and v1.16b, v3.16b, v1.16b 0xaaaac8a29440: 4e221c00 and v0.16b, v0.16b, v2.16b 0xaaaac8a29444: 4ea01c20 orr v0.16b, v1.16b, v0.16b
SSHL:
0x55787414385b: c5 e9 ef d2 vpxor %xmm2, %xmm2, %xmm2 0x55787414385f: c5 e9 fa d1 vpsubd %xmm1, %xmm2, %xmm2 0x557874143863: c4 e2 79 59 1d 7c 00 00 vpbroadcastq 0x7c(%rip), %xmm3 0x55787414386b: 00 0x55787414386c: c5 f1 db cb vpand %xmm3, %xmm1, %xmm1 0x557874143870: c5 e9 db d3 vpand %xmm3, %xmm2, %xmm2 0x557874143874: c4 e2 79 59 1d 7b 00 00 vpbroadcastq 0x7b(%rip), %xmm3 0x55787414387c: 00 0x55787414387d: c4 e2 69 3b d3 vpminud %xmm3, %xmm2, %xmm2 0x557874143882: c5 f1 66 db vpcmpgtd %xmm3, %xmm1, %xmm3 0x557874143886: c4 e2 79 47 e1 vpsllvd %xmm1, %xmm0, %xmm4 0x55787414388b: c4 e2 79 46 c2 vpsravd %xmm2, %xmm0, %xmm0 0x557874143890: c5 e1 df d4 vpandn %xmm4, %xmm3, %xmm2 0x557874143894: c4 e2 79 59 1d 53 00 00 vpbroadcastq 0x53(%rip), %xmm3 0x55787414389c: 00 0x55787414389d: c5 e1 66 c9 vpcmpgtd %xmm1, %xmm3, %xmm1 0x5578741438a1: c4 e3 79 4c c2 10 vpblendvb %xmm1, %xmm2, %xmm0, %xmm0
0xaaaab5996414: 6ea0b822 neg v2.4s, v1.4s 0xaaaab5996418: 6f00e623 movi v3.2d, #0x0000ff000000ff 0xaaaab599641c: 4e231c21 and v1.16b, v1.16b, v3.16b 0xaaaab5996420: 4e231c42 and v2.16b, v2.16b, v3.16b 0xaaaab5996424: 4f0007e3 movi v3.4s, #0x1f 0xaaaab5996428: 6ea36c42 umin v2.4s, v2.4s, v3.4s 0xaaaab599642c: 4ea33423 cmgt v3.4s, v1.4s, v3.4s 0xaaaab5996430: 6ea14404 ushl v4.4s, v0.4s, v1.4s 0xaaaab5996434: 6ea0b842 neg v2.4s, v2.4s 0xaaaab5996438: 4ea24400 sshl v0.4s, v0.4s, v2.4s 0xaaaab599643c: 4e631c82 bic v2.16b, v4.16b, v3.16b 0xaaaab5996440: 4f040403 movi v3.4s, #0x80 0xaaaab5996444: 4ea13461 cmgt v1.4s, v3.4s, v1.4s 0xaaaab5996448: 6ea11c40 bit v0.16b, v2.16b, v1.16b
r~
--- target/arm/helper.h | 11 +- target/arm/translate.h | 6 + target/arm/neon_helper.c | 33 ---- target/arm/translate-a64.c | 18 +-- target/arm/translate.c | 300 +++++++++++++++++++++++++++++++++++-- target/arm/vec_helper.c | 88 +++++++++++ 6 files changed, 390 insertions(+), 66 deletions(-)
target/arm/helper.h +5 -6
@@ -297,14 +297,8 @@ DEF_HELPER_2(neon_abd_s16, i32, i32, i32) DEF_HELPER_2(neon_abd_u32, i32, i32, i32) DEF_HELPER_2(neon_abd_s32, i32, i32, i32) -DEF_HELPER_2(neon_shl_u8, i32, i32, i32) -DEF_HELPER_2(neon_shl_s8, i32, i32, i32) DEF_HELPER_2(neon_shl_u16, i32, i32, i32) DEF_HELPER_2(neon_shl_s16, i32, i32, i32) -DEF_HELPER_2(neon_shl_u32, i32, i32, i32) -DEF_HELPER_2(neon_shl_s32, i32, i32, i32) -DEF_HELPER_2(neon_shl_u64, i64, i64, i64) -DEF_HELPER_2(neon_shl_s64, i64, i64, i64) DEF_HELPER_2(neon_rshl_u8, i32, i32, i32) DEF_HELPER_2(neon_rshl_s8, i32, i32, i32)DEF_HELPER_2 (neon_rshl_u16, i32, i32, i32)
@@ -691,6 +685,11 @@ DEF_HELPER_FLAGS_2(frint64_s, TCG_CALL_NO_RWG, f32, f32, ptr) DEF_HELPER_FLAGS_2(frint32_d, TCG_CALL_NO_RWG, f64, f64, ptr) DEF_HELPER_FLAGS_2(frint64_d, TCG_CALL_NO_RWG, f64, f64, ptr) +DEF_HELPER_FLAGS_4(gvec_sshl_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(gvec_sshl_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(gvec_ushl_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(gvec_ushl_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +#ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h"
target/arm/translate.h +6 -0
@@ -241,6 +241,8 @@ static inline void gen_ss_advance(DisasContext *s)extern const GVecGen3 mla_op[4 ];extern const GVecGen3 mls_op[4 ];extern const GVecGen3 cmtst_op[4 ]; +extern const GVecGen3 sshl_op[4 ]; +extern const GVecGen3 ushl_op[4 ];extern const GVecGen2i ssra_op[4 ];extern const GVecGen2i usra_op[4 ];extern const GVecGen2i sri_op[4 ];
@@ -250,6 +252,10 @@ extern const GVecGen4 sqadd_op[4];extern const GVecGen4 uqsub_op[4 ];extern const GVecGen4 sqsub_op[4 ];void gen_cmtst_i64 (TCGv_i64 d,TCGv_i64 a,TCGv_i64 b); +void gen_ushl_i32 (TCGv_i32 d,TCGv_i32 a,TCGv_i32 b); +void gen_sshl_i32 (TCGv_i32 d,TCGv_i32 a,TCGv_i32 b); +void gen_ushl_i64 (TCGv_i64 d,TCGv_i64 a,TCGv_i64 b); +void gen_sshl_i64 (TCGv_i64 d,TCGv_i64 a,TCGv_i64 b);/* * Forward to the isar_feature_* tests given a DisasContext pointer.
target/arm/neon_helper.c +0 -33
@@ -615,24 +615,9 @@ NEON_VOP(abd_u32, neon_u32, 1) }else { \ dest = src1 << tmp; \ }}while (0 ) -NEON_VOP(shl_u8, neon_u8, 4) NEON_VOP(shl_u16, neon_u16, 2) -NEON_VOP(shl_u32, neon_u32, 1)#undef NEON_FN -uint64_t HELPER (neon_shl_u64 )(uint64_t val,uint64_t shiftop) -{ -int8_t shift = (int8_t )shiftop; -if (shift >=64 || shift <=-64 ) { - val =0 ; - }else if (shift <0 ) { - val >>= -shift; - }else { - val <<= shift; - } -return val; -} -#define NEON_FN (dest, src1, src2) do { \ int8_t tmp; \ tmp = (int8_t)src2; \
@@ -645,27 +630,9 @@ uint64_t HELPER(neon_shl_u64)(uint64_t val, uint64_t shiftop) }else { \ dest = src1 << tmp; \ }}while (0 ) -NEON_VOP(shl_s8, neon_s8, 4) NEON_VOP(shl_s16, neon_s16, 2) -NEON_VOP(shl_s32, neon_s32, 1)#undef NEON_FN -uint64_t HELPER (neon_shl_s64 )(uint64_t valop,uint64_t shiftop) -{ -int8_t shift = (int8_t )shiftop; -int64_t val = valop; -if (shift >=64 ) { - val =0 ; - }else if (shift <=-64 ) { - val >>=63 ; - }else if (shift <0 ) { - val >>= -shift; - }else { - val <<= shift; - } -return val; -} -#define NEON_FN (dest, src1, src2) do { \ int8_t tmp; \ tmp = (int8_t)src2; \
target/arm/translate-a64.c +6 -12
@@ -8856,9 +8856,9 @@ static void handle_3same_64(DisasContext *s, int opcode, bool u,break ;case 0x8 :/* SSHL, USHL */ if (u) { -gen_helper_neon_shl_u64 (tcg_rd, tcg_rn, tcg_rm); +gen_ushl_i64 (tcg_rd, tcg_rn, tcg_rm); }else { -gen_helper_neon_shl_s64 (tcg_rd, tcg_rn, tcg_rm); +gen_sshl_i64 (tcg_rd, tcg_rn, tcg_rm); }break ;case 0x9 :/* SQSHL, UQSHL */
@@ -11253,6 +11253,10 @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) is_q ?16 :8 ,vec_full_reg_size (s), (u ? uqsub_op : sqsub_op) + size);return ; +case 0x08 :/* SSHL, USHL */ +gen_gvec_op3 (s, is_q, rd, rn, rm, + u ? &ushl_op[size] : &sshl_op[size]); +return ;case 0x0c :/* SMAX, UMAX */ if (u) {gen_gvec_fn3 (s, is_q, rd, rn, rm, tcg_gen_gvec_umax, size);
@@ -11368,16 +11372,6 @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) genfn = fns[size][u];break ; } -case 0x8 :/* SSHL, USHL */ - { -static NeonGenTwoOpFn *const fns[3 ][2 ] = { - { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 }, - { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 }, - { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 }, - }; - genfn = fns[size][u]; -break ; - }case 0x9 :/* SQSHL, UQSHL */ {static NeonGenTwoOpEnvFn *const fns[3 ][2 ] = {
target/arm/translate.c +285 -15
348 lines not on this page · raw message
target/arm/vec_helper.c +88 -0
91 lines not on this page · raw message
Signature · 1 line
2.17.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH v2] target/arm: Vectorize USHL and SSHL
Type: series
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'4e81ddf830 target/arm: Vectorize USHL and SSHL
=== OUTPUT BEGIN ===
ERROR: trailing statements should be on next line
#160: FILE: target/arm/translate.c:5377:
+ case 2: gen_ushl_i32(var, var, shift); break;
ERROR: trailing statements should be on next line
#167: FILE: target/arm/translate.c:5383:
+ case 2: gen_sshl_i32(var, var, shift); break;
total: 2 errors, 0 warnings, 570 lines checked
Commit 4e81ddf8304a (target/arm: Vectorize USHL and SSHL) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Peter Maydell
AppliedQuoted 6 lines · Richard Henderson
These instructions shift left or right depending on the sign of the input, and 7 bits are significant to the shift. This requires several masks and selects in addition to the actual shifts to form the complete answer.
Quoted 6 lines
That said, the operation is still a small improvement even for two 64-bit elements -- 13 vector operations instead of 2 * 7 integer operations.
Signed-off-by Richard Henderson <[email protected]>---
Applied to target-arm.next, thanks.
NB: in v1 this series had a second patch. I'm assuming you dropped it deliberately -- if not, let me know.
thanks
-- PMM
Quoted 12 lines · Peter Maydell
Quoted 10 lines · Richard Henderson
These instructions shift left or right depending on the sign of the input, and 7 bits are significant to the shift. This requires several masks and selects in addition to the actual shifts to form the complete answer.
That said, the operation is still a small improvement even for two 64-bit elements -- 13 vector operations instead of 2 * 7 integer operations.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Richard Henderson <[email protected]>---
Applied to target-arm.next, thanks.
NB: in v1 this series had a second patch. I'm assuming you dropped it deliberately -- if not, let me know.
Oops, no. Can you please grab it with your r-b from v1?
r~
Quoted 17 lines · Richard Henderson
Quoted 15 lines · Peter Maydell
Quoted 12 lines · Richard Henderson
These instructions shift left or right depending on the sign of the input, and 7 bits are significant to the shift. This requires several masks and selects in addition to the actual shifts to form the complete answer.
That said, the operation is still a small improvement even for two 64-bit elements -- 13 vector operations instead of 2 * 7 integer operations.
Signed-off-by Richard Henderson <[email protected]>---
Quoted 6 lines
Quoted 4 lines
Applied to target-arm.next, thanks.
NB: in v1 this series had a second patch. I'm assuming you dropped it deliberately -- if not, let me know.
Oops, no. Can you please grab it with your r-b from v1?
Sure.
-- PMM