ARM: Fix VQSHL/VQSHLU immediate forms
cover ARM: Fix VQSHL/VQSHLU immediate forms
This patchset fixes errors in the decoding and implementation of the immediate forms of the VQSHL/VQSHLU ARM instructions. Tested in the usual random-instruction-set way. This is the final part of the maemo-qemu tree commit 03a2445a fixes (the first part being the already-committed VQSHL-reg patchset); the patch down as authored by me is a minor tweaking of changes in the maemo-qemu commit.
Juha Riihimäki (1):
ARM: Fix decoding of VQSHL/VQSHLU immediate forms
Peter Maydell (1):
ARM: add neon helpers for VQSHLU
target-arm/helpers.h | 4 +++ target-arm/neon_helper.c | 47 ++++++++++++++++++++++++++++++++++++++++++ target-arm/translate.c | 51 ++++++++++++++++++++++++++++++++------------- 3 files changed, 87 insertions(+), 15 deletions(-)
PATCH 1/2 ARM: add neon helpers for VQSHLU
Add neon helper functions to implement VQSHLU, which is a signed-to-unsigned version of VQSHL available only as an immediate form.
--- target-arm/helpers.h | 4 +++ target-arm/neon_helper.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 0 deletions(-)
target-arm/helpers.h +4 -0
@@ -249,6 +249,10 @@ DEF_HELPER_3(neon_qshl_u32, i32, env, i32, i32) DEF_HELPER_3(neon_qshl_s32, i32, env, i32, i32) DEF_HELPER_3(neon_qshl_u64, i64, env, i64, i64) DEF_HELPER_3(neon_qshl_s64, i64, env, i64, i64) +DEF_HELPER_3 (neon_qshlu_s8, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s16, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s32, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s64, i64, env, i64, i64); DEF_HELPER_3(neon_qrshl_u8, i32, env, i32, i32) DEF_HELPER_3(neon_qrshl_s8, i32, env, i32, i32)DEF_HELPER_3 (neon_qrshl_u16, i32, env, i32, i32)
target-arm/neon_helper.c +47 -0
53 lines not on this page · raw message
Signature · 1 line
1.6.3.3
Re: [Qemu-devel] [PATCH 1/2] ARM: add neon helpers for VQSHLU
Quoted 62 lines · Peter Maydell
Add neon helper functions to implement VQSHLU, which is a signed-to-unsigned version of VQSHL available only as an immediate form.
Signed-off-by Juha Riihimäki <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- target-arm/helpers.h | 4 +++ target-arm/neon_helper.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 0 deletions(-)target-arm/helpers.h +4
-0@@ -249,6 +249,10 @@ DEF_HELPER_3(neon_qshl_u32, i32, env, i32, i32) DEF_HELPER_3(neon_qshl_s32, i32, env, i32, i32) DEF_HELPER_3(neon_qshl_u64, i64, env, i64, i64) DEF_HELPER_3(neon_qshl_s64, i64, env, i64, i64) +DEF_HELPER_3 (neon_qshlu_s8, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s16, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s32, i32, env, i32, i32); +DEF_HELPER_3 (neon_qshlu_s64, i64, env, i64, i64); DEF_HELPER_3(neon_qrshl_u8, i32, env, i32, i32) DEF_HELPER_3(neon_qrshl_s8, i32, env, i32, i32)DEF_HELPER_3 (neon_qrshl_u16, i32, env, i32, i32)target-arm/neon_helper.c +28
-0@@ -632,6 +632,53 @@ uint64_t HELPER(neon_qshl_s64)(CPUState *env, uint64_t valop, uint64_t shiftop)return val; } +#define NEON_FN (dest, src1, src2) do { \ + if (src1 & (1 << (sizeof(src1) * 8 - 1))) { \ + SET_QC(); \ + dest = 0; \ + } else { \ + int8_t tmp; \ + tmp = (int8_t)src2; \ + if (tmp >= (ssize_t)sizeof(src1) * 8) { \ + if (src1) { \ + SET_QC(); \ + dest = ~0; \ + } else { \ + dest = 0; \ + } \ + } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \ + dest = 0; \ + } else if (tmp < 0) { \ + dest = src1 >> -tmp; \ + } else { \ + dest = src1 << tmp; \ + if ((dest >> tmp) != src1) { \ + SET_QC(); \ + dest = ~0; \ + } \ + } \ + }} while (0) +NEON_VOP_ENV(qshlu_s8, neon_u8, 4) +NEON_VOP_ENV (qshlu_s16, neon_u16,2 )
target-arm/neon_helper.c uint64_t HELPER(neon_qshl_s64)(CPUState *env, uint64_t valop, uint64_t shiftop) · line 672
Quoted 10 lines
target-arm/neon_helper.c +10
-0+#undef NEON_FN + +uint32_t HELPER (neon_qshlu_s32 )(CPUState *env,uint32_t valop,uint32_t shiftop) +{ +if ((int32_t )valop <0 ) { +SET_QC (); +return 0 ; + } +return helper_neon_qshl_u32 (env, valop, shiftop); +}
I guess defining this function using helper_neon_qshl_u32() instead of using NEON_VOP_ENV(qshlu_s32, neon_u32, 1) is to optimize the generated code. Note that it only make 48 bytes difference, with one jump.
target-arm/neon_helper.c uint64_t HELPER(neon_qshl_s64)(CPUState *env, uint64_t valop, uint64_t shiftop) · line 684
Quoted 11 lines
target-arm/neon_helper.c +8
-0+uint64_t HELPER (neon_qshlu_s64 )(CPUState *env,uint64_t valop,uint64_t shiftop) +{ +if ((int64_t )valop <0 ) { +SET_QC (); +return 0 ; + } +return helper_neon_qshl_u64 (env, valop, shiftop); +}/* FIXME: This is wrong. */ #define NEON_FN (dest, src1, src2) do { \
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
PATCH 2/2 ARM: Fix decoding of VQSHL/VQSHLU immediate forms
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Fix errors in the decoding of ARM VQSHL/VQSHLU immediate forms, including using the new VQSHLU helper functions where appropriate.
--- target-arm/translate.c | 51 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 36 insertions(+), 15 deletions(-)
target-arm/translate.c +36 -15
@@ -4647,14 +4647,22 @@ static int disas_neon_data_insn(CPUState * env, DisasContext *s, uint32_t insn)case 5 :/* VSHL, VSLI */ gen_helper_neon_shl_u64 (cpu_V0, cpu_V0, cpu_V1);break ; -case 6 :/* VQSHL */ -if (u) -gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); -else -gen_helper_neon_qshl_s64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); +case 6 :/* VQSHLU */ +if (u) { +gen_helper_neon_qshlu_s64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }else { +return 1 ; + }break ; -case 7 :/* VQSHLU */ -gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); +case 7 :/* VQSHL */ +if (u) { +gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }else { +gen_helper_neon_qshl_s64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }break ; }if (op ==1 || op ==3 ) {
@@ -4693,17 +4701,30 @@ static int disas_neon_data_insn(CPUState * env, DisasContext *s, uint32_t insn)default :return 1 ; }break ; -case 6 :/* VQSHL */ -GEN_NEON_INTEGER_OP_ENV (qshl); -break ; -case 7 :/* VQSHLU */ +case 6 :/* VQSHLU */ +if (!u) { +return 1 ; + }switch (size) { -case 0 :gen_helper_neon_qshl_u8 (tmp, cpu_env, tmp, tmp2);break ; -case 1 :gen_helper_neon_qshl_u16 (tmp, cpu_env, tmp, tmp2);break ; -case 2 :gen_helper_neon_qshl_u32 (tmp, cpu_env, tmp, tmp2);break ; -default :return 1 ; +case 0 : +gen_helper_neon_qshlu_s8 (tmp, cpu_env, + tmp, tmp2); +break ; +case 1 : +gen_helper_neon_qshlu_s16 (tmp, cpu_env, + tmp, tmp2); +break ; +case 2 : +gen_helper_neon_qshlu_s32 (tmp, cpu_env, + tmp, tmp2); +break ; +default : +return 1 ; }break ; +case 7 :/* VQSHL */ +GEN_NEON_INTEGER_OP_ENV (qshl); +break ; }dead_tmp (tmp2);
Signature · 1 line
1.6.3.3
Re: [Qemu-devel] [PATCH 2/2] ARM: Fix decoding of VQSHL/VQSHLU immediate forms
Quoted 6 lines · Peter Maydell
From: Juha Riihimäki <[email protected]>
Fix errors in the decoding of ARM VQSHL/VQSHLU immediate forms, including using the new VQSHLU helper functions where appropriate.
Signed-off-by Peter Maydell <[email protected]>
Quoted 82 lines
--- target-arm/translate.c | 51 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 36 insertions(+), 15 deletions(-)target-arm/translate.c +36
-15@@ -4647,14 +4647,22 @@ static int disas_neon_data_insn(CPUState * env, DisasContext *s, uint32_t insn)case 5 :/* VSHL, VSLI */ gen_helper_neon_shl_u64 (cpu_V0, cpu_V0, cpu_V1);break ; -case 6 :/* VQSHL */ -if (u) -gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); -else -gen_helper_neon_qshl_s64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); +case 6 :/* VQSHLU */ +if (u) { +gen_helper_neon_qshlu_s64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }else { +return 1 ; + }break ; -case 7 :/* VQSHLU */ -gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, cpu_V0, cpu_V1); +case 7 :/* VQSHL */ +if (u) { +gen_helper_neon_qshl_u64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }else { +gen_helper_neon_qshl_s64 (cpu_V0, cpu_env, + cpu_V0, cpu_V1); + }break ; }if (op ==1 || op ==3 ) {@@ -4693,17 +4701,30 @@ static int disas_neon_data_insn(CPUState * env, DisasContext *s, uint32_t insn)default :return 1 ; }break ; -case 6 :/* VQSHL */ -GEN_NEON_INTEGER_OP_ENV (qshl); -break ; -case 7 :/* VQSHLU */ +case 6 :/* VQSHLU */ +if (!u) { +return 1 ; + }switch (size) { -case 0 :gen_helper_neon_qshl_u8 (tmp, cpu_env, tmp, tmp2);break ; -case 1 :gen_helper_neon_qshl_u16 (tmp, cpu_env, tmp, tmp2);break ; -case 2 :gen_helper_neon_qshl_u32 (tmp, cpu_env, tmp, tmp2);break ; -default :return 1 ; +case 0 : +gen_helper_neon_qshlu_s8 (tmp, cpu_env, + tmp, tmp2); +break ; +case 1 : +gen_helper_neon_qshlu_s16 (tmp, cpu_env, + tmp, tmp2); +break ; +case 2 : +gen_helper_neon_qshlu_s32 (tmp, cpu_env, + tmp, tmp2); +break ; +default : +return 1 ; }break ; +case 7 :/* VQSHL */ +GEN_NEON_INTEGER_OP_ENV (qshl); +break ; }dead_tmp (tmp2);Signature · 1 line
1.6.3.3
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 7 lines · Peter Maydell
This patchset fixes errors in the decoding and implementation of the immediate forms of the VQSHL/VQSHLU ARM instructions. Tested in the usual random-instruction-set way. This is the final part of the maemo-qemu tree commit
03a2445afixes (the first part being the already-committed VQSHL-reg patchset); the patch down as authored by me is a minor tweaking of changes in the maemo-qemu commit.
Quoted 5 lines
Juha Riihimäki (1):
ARM: Fix decoding of VQSHL/VQSHLU immediate formsPeter Maydell (1):
ARM: add neon helpers for VQSHLU
Whoops, I changed the wrong patch when I was adjusting the authors for this patchset -- the authors should be the other way round. I'll fix this in a v2 but since it's not a code change I'll see if there's any review commentary first.
-- PMM