target-arm: Add support for VSEL and VMIN/MAXNM.
v8 cover target-arm: Add support for VSEL and VMIN/MAXNM.
This series adds support for three new instructions added in ARMv8 - VSEL, VMINNM and VMAXNM.
Will Newton (6):
target-arm: Move call to disas_vfp_insn out of disas_coproc_insn.
target-arm: Implement ARMv8 VSEL instruction.
softfloat: Remove unused argument from MINMAX macro.
softfloat: Add minNum() and maxNum() functions to softfloat.
target-arm: Implement ARMv8 FP VMAXNM and VMINNM instructions.
target-arm: Implement ARMv8 SIMD VMAXNM and VMINNM instructions.
fpu/softfloat.c | 38 ++++++-- include/fpu/softfloat.h | 4 + target-arm/helper.c | 25 +++++ target-arm/helper.h | 5 + target-arm/translate.c | 246 +++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 298 insertions(+), 20 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v8 1/6 target-arm: Move call to disas_vfp_insn out of disas_coproc_insn.
Floating point is an extension to the instruction set rather than a coprocessor, so call it directly from the ARM and Thumb decode functions.
--- target-arm/translate.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
target-arm/translate.c +27 -5
@@ -2636,6 +2636,14 @@ static int disas_vfp_insn(CPUARMState * env, DisasContext *s, uint32_t insn) && rn != ARM_VFP_MVFR1 && rn != ARM_VFP_MVFR0)return 1 ; } + +if (extract32 (insn,28 ,4 ) ==0xf ) { +/* Encodings with T=1 (Thumb) or unconditional (ARM): +* only used in v8 and above. +*/ +return 1 ; + } + dp = ((insn &0xf00 ) ==0xb00 );switch ((insn >>24 ) &0xf ) {case 0xe :
@@ -6296,9 +6304,6 @@ static int disas_coproc_insn(CPUARMState * env, DisasContext *s, uint32_t insn)return disas_dsp_insn (env, s, insn); }return 1 ; -case 10 : -case 11 : -return disas_vfp_insn (env, s, insn);default :break ; }
@@ -6753,6 +6758,13 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) goto illegal_op;return ; } +if ((insn &0x0f000e10 ) ==0x0e000a00 ) { +/* VFP. */ +if (disas_vfp_insn (env, s, insn)) { + goto illegal_op; + } +return ; + }if (((insn &0x0f30f000 ) ==0x0510f000 ) || ((insn &0x0f30f010 ) ==0x0710f000 )) {if ((insn & (1 <<22 )) ==0 ) {
@@ -8033,9 +8045,15 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s)case 0xc :case 0xd :case 0xe : -/* Coprocessor. */ -if (disas_coproc_insn (env, s, insn)) +if (((insn >>8 ) &0xe ) ==10 ) { +/* VFP. */ +if (disas_vfp_insn (env, s, insn)) { + goto illegal_op; + } + }else if (disas_coproc_insn (env, s, insn)) { +/* Coprocessor. */ goto illegal_op; + }break ;case 0xf :/* swi */
@@ -8765,6 +8783,10 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw insn = (insn &0xe2ffffff ) | ((insn & (1 <<28 )) >>4 ) | (1 <<28 );if (disas_neon_data_insn (env, s, insn)) goto illegal_op; + }else if (((insn >>8 ) &0xe ) ==10 ) { +if (disas_vfp_insn (env, s, insn)) { + goto illegal_op; + } }else {if (insn & (1 <<28 )) goto illegal_op;
Signature · 1 line
1.8.1.4
PATCH v8 2/6 target-arm: Implement ARMv8 VSEL instruction.
In reply to Will NewtonThis adds support for the VSEL floating point selection instruction which was added in ARMv8.
--- target-arm/translate.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-)
target-arm/translate.c +134 -1
@@ -2614,6 +2614,139 @@ static TCGv_i32 gen_load_and_replicate(DisasContext *s, TCGv_i32 addr, int size)return tmp; } +static int handle_vsel (uint32_t insn,uint32_t rd,uint32_t rn,uint32_t rm, +uint32_t dp) +{ +uint32_t cc =extract32 (insn,20 ,2 ); + +if (dp) { +TCGv_i64 frn, frm, dest; +TCGv_i64 tmp, zero, zf, nf, vf; + + zero =tcg_const_i64 (0 ); + + frn =tcg_temp_new_i64 (); + frm =tcg_temp_new_i64 (); + dest =tcg_temp_new_i64 (); + + zf =tcg_temp_new_i64 (); + nf =tcg_temp_new_i64 (); + vf =tcg_temp_new_i64 (); + +tcg_gen_extu_i32_i64 (zf, cpu_ZF); +tcg_gen_ext_i32_i64 (nf, cpu_NF); +tcg_gen_ext_i32_i64 (vf, cpu_VF); + +tcg_gen_ld_f64 (frn, cpu_env,vfp_reg_offset (dp, rn)); +tcg_gen_ld_f64 (frm, cpu_env,vfp_reg_offset (dp, rm)); +switch (cc) { +case 0 :/* eq: Z */ +tcg_gen_movcond_i64 (TCG_COND_EQ , dest, zf, zero, + frn, frm); +break ; +case 1 :/* vs: V */ +tcg_gen_movcond_i64 (TCG_COND_LT , dest, vf, zero, + frn, frm); +break ; +case 2 :/* ge: N == V -> N ^ V == 0 */ + tmp =tcg_temp_new_i64 (); +tcg_gen_xor_i64 (tmp, vf, nf); +tcg_gen_movcond_i64 (TCG_COND_GE , dest, tmp, zero, + frn, frm); +tcg_temp_free_i64 (tmp); +break ; +case 3 :/* gt: !Z && N == V */ +tcg_gen_movcond_i64 (TCG_COND_NE , dest, zf, zero, + frn, frm); + tmp =tcg_temp_new_i64 (); +tcg_gen_xor_i64 (tmp, vf, nf); +tcg_gen_movcond_i64 (TCG_COND_GE , dest, tmp, zero, + dest, frm); +tcg_temp_free_i64 (tmp); +break ; + } +tcg_gen_st_f64 (dest, cpu_env,vfp_reg_offset (dp, rd)); +tcg_temp_free_i64 (frn); +tcg_temp_free_i64 (frm); +tcg_temp_free_i64 (dest); + +tcg_temp_free_i64 (zf); +tcg_temp_free_i64 (nf); +tcg_temp_free_i64 (vf); + +tcg_temp_free_i64 (zero); + }else { +TCGv_i32 frn, frm, dest; +TCGv_i32 tmp, zero; + + zero =tcg_const_i32 (0 ); + + frn =tcg_temp_new_i32 (); + frm =tcg_temp_new_i32 (); + dest =tcg_temp_new_i32 (); +tcg_gen_ld_f32 (frn, cpu_env,vfp_reg_offset (dp, rn)); +tcg_gen_ld_f32 (frm, cpu_env,vfp_reg_offset (dp, rm)); +switch (cc) { +case 0 :/* eq: Z */ +tcg_gen_movcond_i32 (TCG_COND_EQ , dest, cpu_ZF, zero, + frn, frm); +break ; +case 1 :/* vs: V */ +tcg_gen_movcond_i32 (TCG_COND_LT , dest, cpu_VF, zero, + frn, frm); +break ; +case 2 :/* ge: N == V -> N ^ V == 0 */ + tmp =tcg_temp_new_i32 (); +tcg_gen_xor_i32 (tmp, cpu_VF, cpu_NF); +tcg_gen_movcond_i32 (TCG_COND_GE , dest, tmp, zero, + frn, frm); +tcg_temp_free_i32 (tmp); +break ; +case 3 :/* gt: !Z && N == V */ +tcg_gen_movcond_i32 (TCG_COND_NE , dest, cpu_ZF, zero, + frn, frm); + tmp =tcg_temp_new_i32 (); +tcg_gen_xor_i32 (tmp, cpu_VF, cpu_NF); +tcg_gen_movcond_i32 (TCG_COND_GE , dest, tmp, zero, + dest, frm); +tcg_temp_free_i32 (tmp); +break ; + } +tcg_gen_st_f32 (dest, cpu_env,vfp_reg_offset (dp, rd)); +tcg_temp_free_i32 (frn); +tcg_temp_free_i32 (frm); +tcg_temp_free_i32 (dest); + +tcg_temp_free_i32 (zero); + } + +return 0 ; +} + +static int disas_vfp_v8_insn (CPUARMState *env,DisasContext *s,uint32_t insn) +{ +uint32_t rd, rn, rm, dp =extract32 (insn,8 ,1 ); + +if (!arm_feature (env,ARM_FEATURE_V8 )) { +return 1 ; + } + +if (dp) { +VFP_DREG_D (rd, insn); +VFP_DREG_N (rn, insn); +VFP_DREG_M (rm, insn); + }else { + rd =VFP_SREG_D (insn); + rn =VFP_SREG_N (insn); + rm =VFP_SREG_M (insn); + } + +if ((insn &0x0f800e50 ) ==0x0e000a00 ) { +return handle_vsel (insn, rd, rn, rm, dp); + } +return 1 ; +} +/* Disassemble a VFP instruction. Returns nonzero if an error occurred (ie. an undefined instruction). */ static int disas_vfp_insn (CPUARMState * env,DisasContext *s,uint32_t insn)
@@ -2641,7 +2774,7 @@ static int disas_vfp_insn(CPUARMState * env, DisasContext *s, uint32_t insn)/* Encodings with T=1 (Thumb) or unconditional (ARM): * only used in v8 and above. */ -return 1 ; +return disas_vfp_v8_insn (env, s, insn); } dp = ((insn &0xf00 ) ==0xb00 );
Signature · 1 line
1.8.1.4
PATCH v8 3/6 softfloat: Remove unused argument from MINMAX macro.
In reply to Will NewtonThe nan_exp argument is not used, so remove it.
--- fpu/softfloat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fpu/softfloat.c +3 -3
@@ -6706,7 +6706,7 @@ int float128_compare_quiet( float128 a, float128 b STATUS_PARAM )* 'compare and pick one input' because that would mishandle * NaNs and +0 vs -0. */ -#define MINMAX (s, nan_exp) \ +#define MINMAX (s) \ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ int ismin STATUS_PARAM ) \ { \
@@ -6747,8 +6747,8 @@ float ## s float ## s ## _max(float ## s a, float ## s b STATUS_PARAM) \ return float ## s ## _minmax(a, b, 0 STATUS_VAR); \ } -MINMAX(32, 0xff) -MINMAX (64 ,0x7ff ) +MINMAX(32) +MINMAX (64 )/* Multiply A by 2 raised to the power N. */
Signature · 1 line
1.8.1.4
PATCH v8 4/6 softfloat: Add minNum() and maxNum() functions to softfloat.
In reply to Will NewtonAdd floatnn_minnum() and floatnn_maxnum() functions which are equivalent to the minNum() and maxNum() functions from IEEE 754-2008. They are similar to min() and max() but differ in the handling of QNaN arguments.
--- fpu/softfloat.c | 32 +++++++++++++++++++++++++++++--- include/fpu/softfloat.h | 4 ++++ 2 files changed, 33 insertions(+), 3 deletions(-)
Changes in v8:
- Use existing MINMAX macro to implement minnum and maxnum
- Improve comment
fpu/softfloat.c +29 -3
@@ -6705,10 +6705,17 @@ int float128_compare_quiet( float128 a, float128 b STATUS_PARAM )/* min() and max() functions. These can't be implemented as * 'compare and pick one input' because that would mishandle * NaNs and +0 vs -0. +* +* minnum() and maxnum() functions. These are similar to the min() +* and max() functions but if one of the arguments is a QNaN and +* the other is numerical then the numerical argument is returned. +* minnum() and maxnum correspond to the IEEE 754-2008 minNum() +* and maxNum() operations. min() and max() are the typical min/max +* semantics provided by many CPUs which predate that specification. */ #define MINMAX (s) \ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ - int ismin STATUS_PARAM ) \ + int ismin, int isieee STATUS_PARAM) \ { \ flag aSign, bSign; \ uint ## s ## _t av, bv; \
@@ -6716,6 +6723,15 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ b = float ## s ## _squash_input_denormal(b STATUS_VAR); \ if (float ## s ## _is_any_nan(a) || \ float ## s ## _is_any_nan(b)) { \ + if (isieee) { \ + if (float ## s ## _is_quiet_nan(a) && \ + !float ## s ##_is_any_nan(b)) { \ + return b; \ + } else if (float ## s ## _is_quiet_nan(b) && \ + !float ## s ## _is_any_nan(a)) { \ + return a; \ + } \ + } \ return propagateFloat ## s ## NaN(a, b STATUS_VAR); \ } \ aSign = extractFloat ## s ## Sign(a); \
@@ -6739,12 +6755,22 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ \ float ## s float ## s ## _min(float ## s a, float ## s b STATUS_PARAM) \ { \ - return float ## s ## _minmax(a, b, 1 STATUS_VAR); \ + return float ## s ## _minmax(a, b, 1, 0 STATUS_VAR); \ } \ \ float ## s float ## s ## _max(float ## s a, float ## s b STATUS_PARAM) \ { \ - return float ## s ## _minmax(a, b, 0 STATUS_VAR); \ + return float ## s ## _minmax(a, b, 0, 0 STATUS_VAR); \ +} \ + \ +float ## s float ## s ## _minnum(float ## s a, float ## s b STATUS_PARAM) \ +{ \ + return float ## s ## _minmax(a, b, 1, 1 STATUS_VAR); \ +} \ + \ +float ## s float ## s ## _maxnum(float ## s a, float ## s b STATUS_PARAM) \ +{ \ + return float ## s ## _minmax(a, b, 0, 1 STATUS_VAR); \ }MINMAX (32 )
include/fpu/softfloat.h +4 -0
@@ -302,6 +302,8 @@ int float32_compare( float32, float32 STATUS_PARAM );int float32_compare_quiet (float32 ,float32 STATUS_PARAM );float32 float32_min (float32 ,float32 STATUS_PARAM );float32 float32_max (float32 ,float32 STATUS_PARAM ); +float32 float32_minnum (float32 ,float32 STATUS_PARAM ); +float32 float32_maxnum (float32 ,float32 STATUS_PARAM );int float32_is_quiet_nan (float32 );int float32_is_signaling_nan (float32 );float32 float32_maybe_silence_nan (float32 );
@@ -408,6 +410,8 @@ int float64_compare( float64, float64 STATUS_PARAM );int float64_compare_quiet (float64 ,float64 STATUS_PARAM );float64 float64_min (float64 ,float64 STATUS_PARAM );float64 float64_max (float64 ,float64 STATUS_PARAM ); +float64 float64_minnum (float64 ,float64 STATUS_PARAM ); +float64 float64_maxnum (float64 ,float64 STATUS_PARAM );int float64_is_quiet_nan (float64 a );int float64_is_signaling_nan (float64 );float64 float64_maybe_silence_nan (float64 );
Signature · 1 line
1.8.1.4
PATCH v8 5/6 target-arm: Implement ARMv8 FP VMAXNM and VMINNM instructions.
In reply to Will NewtonThis adds support for the ARMv8 floating point VMAXNM and VMINNM instructions.
--- target-arm/helper.c | 25 +++++++++++++++++++++++++ target-arm/helper.h | 5 +++++ target-arm/translate.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+)
target-arm/helper.c +25 -0
@@ -4079,3 +4079,28 @@ float64 VFP_HELPER(muladd, d)(float64 a, float64 b, float64 c, void *fpstp)float_status *fpst = fpstp;return float64_muladd (a, b, c,0 , fpst); } + +/* ARMv8 VMAXNM/VMINNM */ +float32 VFP_HELPER (maxnm ,s )(float32 a,float32 b,void *fpstp) +{ +float_status *fpst = fpstp; +return float32_maxnum (a, b, fpst); +} + +float64 VFP_HELPER (maxnm ,d )(float64 a,float64 b,void *fpstp) +{ +float_status *fpst = fpstp; +return float64_maxnum (a, b, fpst); +} + +float32 VFP_HELPER (minnm ,s )(float32 a,float32 b,void *fpstp) +{ +float_status *fpst = fpstp; +return float32_minnum (a, b, fpst); +} + +float64 VFP_HELPER (minnm ,d )(float64 a,float64 b,void *fpstp) +{ +float_status *fpst = fpstp; +return float64_minnum (a, b, fpst); +}
target-arm/helper.h +5 -0
@@ -132,6 +132,11 @@ DEF_HELPER_2(neon_fcvt_f32_to_f16, i32, f32, env) DEF_HELPER_4(vfp_muladdd, f64, f64, f64, f64, ptr) DEF_HELPER_4(vfp_muladds, f32, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_maxnmd, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_maxnms, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_minnmd, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_minnms, f32, f32, f32, ptr) + DEF_HELPER_3(recps_f32, f32, f32, f32, env) DEF_HELPER_3(rsqrts_f32, f32, f32, f32, env)DEF_HELPER_2 (recpe_f32, f32, f32, env)
target-arm/translate.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v8 6/6 target-arm: Implement ARMv8 SIMD VMAXNM and VMINNM instructions.
In reply to Will NewtonThis adds support for the ARMv8 Advanced SIMD VMAXNM and VMINNM instructions.
--- target-arm/translate.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
Changes in v8:
- Use VFP helper instead of adding a NEON specific one
- Drop size check
target-arm/translate.c +22 -9
@@ -4553,7 +4553,7 @@ static void gen_neon_narrow_op(int op, int u, int size,#define NEON_3R_FLOAT_CMP 28/* float VCEQ, VCGE, VCGT */ #define NEON_3R_FLOAT_ACMP 29/* float VACGE, VACGT, VACLE, VACLT */ #define NEON_3R_FLOAT_MINMAX 30/* float VMIN, VMAX */ -#define NEON_3R_VRECPS_VRSQRTS 31/* float VRECPS, VRSQRTS */ +#define NEON_3R_FLOAT_MISC 31/* float VRECPS, VRSQRTS, VMAXNM/MINNM */ static const uint8_t neon_3r_sizes[] = { [NEON_3R_VHADD ] =0x7 ,
@@ -4586,7 +4586,7 @@ static const uint8_t neon_3r_sizes[] = { [NEON_3R_FLOAT_CMP] = 0x5, /* size bit 1 encodes op */ [NEON_3R_FLOAT_ACMP] = 0x5, /* size bit 1 encodes op */ [NEON_3R_FLOAT_MINMAX] = 0x5, /* size bit 1 encodes op */ - [NEON_3R_VRECPS_VRSQRTS] = 0x5, /* size bit 1 encodes op */ + [NEON_3R_FLOAT_MISC] = 0x5, /* size bit 1 encodes op */ };/* Symbolic constants for op fields for Neon 2-register miscellaneous.
@@ -4847,8 +4847,9 @@ static int disas_neon_data_insn(CPUARMState * env, DisasContext *s, uint32_t insreturn 1 ; }break ; -case NEON_3R_VRECPS_VRSQRTS : -if (u) { +case NEON_3R_FLOAT_MISC : +/* VMAXNM/VMINNM in ARMv8 */ +if (u && !arm_feature (env,ARM_FEATURE_V8 )) {return 1 ; }break ;
@@ -5137,11 +5138,23 @@ static int disas_neon_data_insn(CPUARMState * env, DisasContext *s, uint32_t instcg_temp_free_ptr (fpstatus);break ; } -case NEON_3R_VRECPS_VRSQRTS : -if (size ==0 ) -gen_helper_recps_f32 (tmp, tmp, tmp2, cpu_env); -else -gen_helper_rsqrts_f32 (tmp, tmp, tmp2, cpu_env); +case NEON_3R_FLOAT_MISC : +if (u) { +/* VMAXNM/VMINNM */ +TCGv_ptr fpstatus =get_fpstatus_ptr (1 ); +if (size ==0 ) { +gen_helper_vfp_maxnms (tmp, tmp, tmp2, fpstatus); + }else { +gen_helper_vfp_minnms (tmp, tmp, tmp2, fpstatus); + } +tcg_temp_free_ptr (fpstatus); + }else { +if (size ==0 ) { +gen_helper_recps_f32 (tmp, tmp, tmp2, cpu_env); + }else { +gen_helper_rsqrts_f32 (tmp, tmp, tmp2, cpu_env); + } + }break ;case NEON_3R_VFM : {
Signature · 1 line
1.8.1.4
Quoted 10 lines · Will Newton
This series adds support for three new instructions added in ARMv8 - VSEL, VMINNM and VMAXNM.
Will Newton (6):
target-arm: Move call todisas_vfp_insnout ofdisas_coproc_insn.
target-arm: Implement ARMv8 VSEL instruction.
softfloat: Remove unused argument from MINMAX macro.
softfloat: AddminNum()andmaxNum()functions to softfloat.
target-arm: Implement ARMv8 FP VMAXNM and VMINNM instructions.
target-arm: Implement ARMv8 SIMD VMAXNM and VMINNM instructions.
Thanks. These patches all pass my random instruction tests and look good. All patches
and added to target-arm.next.
NB: since these are all Linaro copyright changes, the softfloat patches are provided under either the softfloat 2a or 2b license.
[we're currently halfway through attempting a relicense on the softfloat code, hence the necessity for that remark.]
-- PMM