A64 decoder patchset 5: most floating point
v2 cover A64 decoder patchset 5: most floating point
FP support patchset. Changes v1->v2:
patch 1: correct format string, argument order issues patch 2: simplify do_fp_st by always loading 64 bits from the
vfp regs entry
patches 3-10 unchanged; all have been reviewed.
This patchset sits on top of the previous one (now almost entirely codereviewed); you can find a git tree at
git://git.linaro.org/people/peter.maydell/qemu-arm.git a64-fifth-set
web UI:
https://git.linaro.org/people/peter.maydell/qemu-arm.git/shortlog/refs/heads/a64-fifth-set
thanks
-- PMM
*** BLURB HERE ***
Alexander Graf (5):
target-arm: A64: Add support for dumping AArch64 VFP register state
target-arm: A64: Add "Floating-point data-processing (2 source)" insns
target-arm: A64: Add "Floating-point data-processing (3 source)" insns
target-arm: A64: Add fmov (scalar, immediate) instruction
target-arm: Give the FPSCR rounding modes names
Claudio Fontana (3):
target-arm: A64: Add support for floating point compare
target-arm: A64: Add support for floating point conditional compare
target-arm: A64: Add support for floating point cond select
Peter Maydell (2):
target-arm: A64: Fix vector register access on bigendian hosts
target-arm: Use VFP_BINOP macro for min, max, minnum, maxnum
target-arm/cpu.h | 9 + target-arm/helper-a64.c | 45 ++++ target-arm/helper-a64.h | 4 + target-arm/helper.c | 37 +--- target-arm/helper.h | 15 +- target-arm/neon_helper.c | 12 - target-arm/translate-a64.c | 539 +++++++++++++++++++++++++++++++++++++++++---- target-arm/translate.c | 16 +- 8 files changed, 581 insertions(+), 96 deletions(-)
Signature · 1 line
1.8.5
PATCH v2 1/10 target-arm: A64: Add support for dumping AArch64 VFP register state
From: Alexander Graf <[email protected]>
When dumping the current CPU state, we can also get a request to dump the FPU state along with the CPU's integer state.
Add support to dump the VFP state when that flag is set, so that we can properly debug code that modifies floating point registers.
--- target-arm/translate-a64.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
target-arm/translate-a64.c +16 -0
@@ -119,6 +119,22 @@ void aarch64_cpu_dump_state(CPUState *cs, FILE *f, psr &PSTATE_C ?'C' :'-' , psr & PSTATE_V ? 'V' : '-');cpu_fprintf (f,"\n" ); + +if (flags &CPU_DUMP_FPU ) { +int numvfpregs =32 ; +for (i =0 ; i < numvfpregs; i +=2 ) { +uint64_t vlo =float64_val (env->vfp.regs[i *2 ]); +uint64_t vhi =float64_val (env->vfp.regs[(i *2 ) +1 ]); +cpu_fprintf (f,"q%02d=%016" PRIx64":%016" PRIx64" " , + i, vhi, vlo); + vlo =float64_val (env->vfp.regs[(i +1 ) *2 ]); + vhi =float64_val (env->vfp.regs[((i +1 ) *2 ) +1 ]); +cpu_fprintf (f,"q%02d=%016" PRIx64":%016" PRIx64"\n" , + i +1 , vhi, vlo); + } +cpu_fprintf (f,"FPCR: %08x FPSR: %08x\n" , +vfp_get_fpcr (env),vfp_get_fpsr (env)); + } }static int get_mem_index (DisasContext *s)
Signature · 1 line
1.8.5
Re: [Qemu-devel] [PATCH v2 01/10] target-arm: A64: Add support for dumping AArch64 VFP register state
Quoted 8 lines · Peter Maydell
From: Alexander Graf <[email protected]>
When dumping the current CPU state, we can also get a request to dump the FPU state along with the CPU's integer state.
Add support to dump the VFP state when that flag is set, so that we can properly debug code that modifies floating point registers.
Quoted 8 lines
Signed-off-by Alexander Graf <[email protected]>[WN: Commit message tweak, rebased. Output all registers, two per-line.]Signed-off-by Will Newton <[email protected]>Reviewed-by Peter Maydell <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- target-arm/translate-a64.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
r~
PATCH v2 2/10 target-arm: A64: Fix vector register access on bigendian hosts
In reply to Peter MaydellThe A64 128 bit vector registers are stored as a pair of uint64_t values in the register array. This means that if we're directly loading or storing a value of size less than 64 bits we must adjust the offset appropriately to account for whether the host is bigendian or not. Provide utility functions to abstract away the offsetof() calculations for the FP registers.
For do_fp_st() we can sidestep most of the issues for 64 bit and smaller reg-to-mem transfers by always doing a 64 bit load from the register and writing just the piece we need to memory.
---
Didn't spot this bug until I started reviewing the FP related patches (the code also I think is cleaner without offsetof() scattered everywhere).
--- target-arm/translate-a64.c | 69 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
target-arm/translate-a64.c +35 -34
@@ -308,6 +308,26 @@ static TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)return v; } +/* Return the offset into CPUARMState of a slice (from +* the least significant end) of FP register Qn (ie +* Dn, Sn, Hn or Bn). +* (Note that this is not the same mapping as for A32; see cpu.h) +*/ +static inline int fp_reg_offset (int regno,TCGMemOp size) +{ + int offs = offsetof(CPUARMState, vfp.regs[regno * 2]); +#ifdef HOST_WORDS_BIGENDIAN + offs += (8 - (1 << size)); +#endif +return offs; +} + +/* Offset of the high half of the 128 bit vector Qn */ +static inline int fp_reg_hi_offset (int regno) +{ + return offsetof(CPUARMState, vfp.regs[regno * 2 + 1]); +} +/* Set ZF and NF based on a 64 bit result. This is alas fiddlier * than the 32 bit equivalent. */
@@ -538,31 +558,15 @@ static void do_gpr_ld(DisasContext *s, TCGv_i64 dest, TCGv_i64 tcg_addr,static void do_fp_st (DisasContext *s,int srcidx,TCGv_i64 tcg_addr,int size) {/* This writes the bottom N bits of a 128 bit wide vector to memory */ - int freg_offs = offsetof(CPUARMState, vfp.regs[srcidx * 2]);TCGv_i64 tmp =tcg_temp_new_i64 (); - +tcg_gen_ld_i64 (tmp, cpu_env,fp_reg_offset (srcidx,MO_64 ));if (size <4 ) { -switch (size) { -case 0 : -tcg_gen_ld8u_i64 (tmp, cpu_env, freg_offs); -break ; -case 1 : -tcg_gen_ld16u_i64 (tmp, cpu_env, freg_offs); -break ; -case 2 : -tcg_gen_ld32u_i64 (tmp, cpu_env, freg_offs); -break ; -case 3 : -tcg_gen_ld_i64 (tmp, cpu_env, freg_offs); -break ; - }tcg_gen_qemu_st_i64 (tmp, tcg_addr,get_mem_index (s),MO_TE + size); }else {TCGv_i64 tcg_hiaddr =tcg_temp_new_i64 (); -tcg_gen_ld_i64 (tmp, cpu_env, freg_offs);tcg_gen_qemu_st_i64 (tmp, tcg_addr,get_mem_index (s),MO_TEQ );tcg_gen_qemu_st64 (tmp, tcg_addr,get_mem_index (s)); -tcg_gen_ld_i64 (tmp, cpu_env, freg_offs +sizeof (float64)); +tcg_gen_ld_i64 (tmp, cpu_env,fp_reg_hi_offset (srcidx));tcg_gen_addi_i64 (tcg_hiaddr, tcg_addr,8 );tcg_gen_qemu_st_i64 (tmp, tcg_hiaddr,get_mem_index (s),MO_TEQ );tcg_temp_free_i64 (tcg_hiaddr);
@@ -577,7 +581,6 @@ static void do_fp_st(DisasContext *s, int srcidx, TCGv_i64 tcg_addr, int size)static void do_fp_ld (DisasContext *s,int destidx,TCGv_i64 tcg_addr,int size) {/* This always zero-extends and writes to a full 128 bit wide vector */ - int freg_offs = offsetof(CPUARMState, vfp.regs[destidx * 2]);TCGv_i64 tmplo =tcg_temp_new_i64 ();TCGv_i64 tmphi;
@@ -596,8 +599,8 @@ static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)tcg_temp_free_i64 (tcg_hiaddr); } -tcg_gen_st_i64 (tmplo, cpu_env, freg_offs); -tcg_gen_st_i64 (tmphi, cpu_env, freg_offs +sizeof (float64)); +tcg_gen_st_i64 (tmplo, cpu_env,fp_reg_offset (destidx,MO_64 )); +tcg_gen_st_i64 (tmphi, cpu_env,fp_reg_hi_offset (destidx));tcg_temp_free_i64 (tmplo);tcg_temp_free_i64 (tmphi);
@@ -3224,7 +3227,6 @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)*/ if (itof) { - int freg_offs = offsetof(CPUARMState, vfp.regs[rd * 2]);TCGv_i64 tcg_rn =cpu_reg (s, rn);switch (type) {
@@ -3233,9 +3235,9 @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)/* 32 bit */ TCGv_i64 tmp =tcg_temp_new_i64 ();tcg_gen_ext32u_i64 (tmp, tcg_rn); -tcg_gen_st_i64 (tmp, cpu_env, freg_offs); +tcg_gen_st_i64 (tmp, cpu_env,fp_reg_offset (rd,MO_64 ));tcg_gen_movi_i64 (tmp,0 ); -tcg_gen_st_i64 (tmp, cpu_env, freg_offs +sizeof (float64)); +tcg_gen_st_i64 (tmp, cpu_env,fp_reg_hi_offset (rd));tcg_temp_free_i64 (tmp);break ; }
@@ -3243,32 +3245,31 @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof) {/* 64 bit */ TCGv_i64 tmp =tcg_const_i64 (0 ); -tcg_gen_st_i64 (tcg_rn, cpu_env, freg_offs); -tcg_gen_st_i64 (tmp, cpu_env, freg_offs +sizeof (float64)); +tcg_gen_st_i64 (tcg_rn, cpu_env,fp_reg_offset (rd,MO_64 )); +tcg_gen_st_i64 (tmp, cpu_env,fp_reg_hi_offset (rd));tcg_temp_free_i64 (tmp);break ; }case 2 :/* 64 bit to top half. */ -tcg_gen_st_i64 (tcg_rn, cpu_env, freg_offs +sizeof (float64)); +tcg_gen_st_i64 (tcg_rn, cpu_env,fp_reg_hi_offset (rd));break ; } }else { - int freg_offs = offsetof(CPUARMState, vfp.regs[rn * 2]);TCGv_i64 tcg_rd =cpu_reg (s, rd);switch (type) {case 0 :/* 32 bit */ -tcg_gen_ld32u_i64 (tcg_rd, cpu_env, freg_offs); +tcg_gen_ld32u_i64 (tcg_rd, cpu_env,fp_reg_offset (rn,MO_32 ));break ; -case 2 : -/* 64 bits from top half */ - freg_offs +=sizeof (float64); -/* fall through */ case 1 :/* 64 bit */ -tcg_gen_ld_i64 (tcg_rd, cpu_env, freg_offs); +tcg_gen_ld_i64 (tcg_rd, cpu_env,fp_reg_offset (rn,MO_64 )); +break ; +case 2 : +/* 64 bits from top half */ +tcg_gen_ld_i64 (tcg_rd, cpu_env,fp_reg_hi_offset (rn));break ; } }
Signature · 1 line
1.8.5
Re: [Qemu-devel] [PATCH v2 02/10] target-arm: A64: Fix vector register access on bigendian hosts
Quoted 13 lines · Peter Maydell
The A64 128 bit vector registers are stored as a pair of
uint64_tvalues in the register array. This means that if we're directly loading or storing a value of size less than 64 bits we must adjust the offset appropriately to account for whether the host is bigendian or not. Provide utility functions to abstract away theoffsetof()calculations for the FP registers.For
do_fp_st()we can sidestep most of the issues for 64 bit and smaller reg-to-mem transfers by always doing a 64 bit load from the register and writing just the piece we need to memory.
Quoted 8 lines
Signed-off-by Peter Maydell <[email protected]>---
Didn't spot this bug until I started reviewing the FP related patches (the code also I think is cleaner withoutoffsetof()scattered everywhere).--- target-arm/translate-a64.c | 69 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
r~
PATCH v2 3/10 target-arm: Use VFP_BINOP macro for min, max, minnum, maxnum
In reply to Peter MaydellUse the VFP_BINOP macro to provide helpers for min, max, minnum and maxnum, rather than hand-rolling them. (The float64 max version is not used by A32 but will be needed for A64.)
--- target-arm/helper.c | 29 ++++------------------------- target-arm/helper.h | 15 ++++++++------- target-arm/neon_helper.c | 12 ------------ target-arm/translate.c | 16 ++++++++-------- 4 files changed, 20 insertions(+), 52 deletions(-)
target-arm/helper.c +4 -25
@@ -3864,6 +3864,10 @@ VFP_BINOP(add)VFP_BINOP (sub)VFP_BINOP (mul )VFP_BINOP (div) +VFP_BINOP (min) +VFP_BINOP (max) +VFP_BINOP (minnum) +VFP_BINOP (maxnum) #undef VFP_BINOP float32VFP_HELPER (neg, s)(float32 a)
@@ -4317,28 +4321,3 @@ 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 +8 -7
@@ -79,6 +79,14 @@ DEF_HELPER_3(vfp_muls, f32, f32, f32, ptr) DEF_HELPER_3(vfp_muld, f64, f64, f64, ptr) DEF_HELPER_3(vfp_divs, f32, f32, f32, ptr) DEF_HELPER_3(vfp_divd, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_maxs, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_maxd, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_mins, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_mind, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_maxnums, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_maxnumd, f64, f64, f64, ptr) +DEF_HELPER_3(vfp_minnums, f32, f32, f32, ptr) +DEF_HELPER_3(vfp_minnumd, f64, f64, f64, ptr) DEF_HELPER_1(vfp_negs, f32, f32) DEF_HELPER_1(vfp_negd, f64, f64)DEF_HELPER_1 (vfp_abss, f32, f32)
@@ -132,11 +140,6 @@ 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)
@@ -346,8 +349,6 @@ DEF_HELPER_2(neon_qneg_s8, i32, env, i32) DEF_HELPER_2(neon_qneg_s16, i32, env, i32) DEF_HELPER_2(neon_qneg_s32, i32, env, i32) -DEF_HELPER_3(neon_min_f32, i32, i32, i32, ptr) -DEF_HELPER_3(neon_max_f32, i32, i32, i32, ptr) DEF_HELPER_3(neon_abd_f32, i32, i32, i32, ptr) DEF_HELPER_3(neon_ceq_f32, i32, i32, i32, ptr)DEF_HELPER_3 (neon_cge_f32, i32, i32, i32, ptr)
target-arm/neon_helper.c +0 -12
@@ -1765,18 +1765,6 @@ uint32_t HELPER(neon_qneg_s32)(CPUARMState *env, uint32_t x) }/* NEON Float helpers. */ -uint32_t HELPER (neon_min_f32 )(uint32_t a,uint32_t b,void *fpstp) -{ -float_status *fpst = fpstp; -return float32_val (float32_min (make_float32 (a),make_float32 (b), fpst)); -} - -uint32_t HELPER (neon_max_f32 )(uint32_t a,uint32_t b,void *fpstp) -{ -float_status *fpst = fpstp; -return float32_val (float32_max (make_float32 (a),make_float32 (b), fpst)); -} -uint32_t HELPER (neon_abd_f32 )(uint32_t a,uint32_t b,void *fpstp) {float_status *fpst = fpstp;
target-arm/translate.c +8 -8
@@ -2725,9 +2725,9 @@ static int handle_vminmaxnm(uint32_t insn, uint32_t rd, uint32_t rn,tcg_gen_ld_f64 (frn, cpu_env,vfp_reg_offset (dp, rn));tcg_gen_ld_f64 (frm, cpu_env,vfp_reg_offset (dp, rm));if (vmin) { -gen_helper_vfp_minnmd (dest, frn, frm, fpst); +gen_helper_vfp_minnumd (dest, frn, frm, fpst); }else { -gen_helper_vfp_maxnmd (dest, frn, frm, fpst); +gen_helper_vfp_maxnumd (dest, frn, frm, fpst); }tcg_gen_st_f64 (dest, cpu_env,vfp_reg_offset (dp, rd));tcg_temp_free_i64 (frn);
@@ -2743,9 +2743,9 @@ static int handle_vminmaxnm(uint32_t insn, uint32_t rd, uint32_t rn,tcg_gen_ld_f32 (frn, cpu_env,vfp_reg_offset (dp, rn));tcg_gen_ld_f32 (frm, cpu_env,vfp_reg_offset (dp, rm));if (vmin) { -gen_helper_vfp_minnms (dest, frn, frm, fpst); +gen_helper_vfp_minnums (dest, frn, frm, fpst); }else { -gen_helper_vfp_maxnms (dest, frn, frm, fpst); +gen_helper_vfp_maxnums (dest, frn, frm, fpst); }tcg_gen_st_f32 (dest, cpu_env,vfp_reg_offset (dp, rd));tcg_temp_free_i32 (frn);
@@ -5121,9 +5121,9 @@ static int disas_neon_data_insn(CPUARMState * env, DisasContext *s, uint32_t ins {TCGv_ptr fpstatus =get_fpstatus_ptr (1 );if (size ==0 ) { -gen_helper_neon_max_f32 (tmp, tmp, tmp2, fpstatus); +gen_helper_vfp_maxs (tmp, tmp, tmp2, fpstatus); }else { -gen_helper_neon_min_f32 (tmp, tmp, tmp2, fpstatus); +gen_helper_vfp_mins (tmp, tmp, tmp2, fpstatus); }tcg_temp_free_ptr (fpstatus);break ;
@@ -5133,9 +5133,9 @@ static int disas_neon_data_insn(CPUARMState * env, DisasContext *s, uint32_t ins/* VMAXNM/VMINNM */ TCGv_ptr fpstatus =get_fpstatus_ptr (1 );if (size ==0 ) { -gen_helper_vfp_maxnms (tmp, tmp, tmp2, fpstatus); +gen_helper_vfp_maxnums (tmp, tmp, tmp2, fpstatus); }else { -gen_helper_vfp_minnms (tmp, tmp, tmp2, fpstatus); +gen_helper_vfp_minnums (tmp, tmp, tmp2, fpstatus); }tcg_temp_free_ptr (fpstatus); }else {
Signature · 1 line
1.8.5
PATCH v2 4/10 target-arm: A64: Add "Floating-point data-processing (2 source)" insns
In reply to Peter MaydellFrom: Alexander Graf <[email protected]>
This patch adds emulation for the "Floating-point data-processing (2 source)" group of instructions.
[WN: Commit message tweak, merge single and double precision patches. Rebase
and update to new infrastructure. Incorporate FMIN/FMAX support patch by Michael Matz.]
[PMM:
* added convenience accessors for FP s and d regs
* pulled the field decode and opcode validity check up a level]
--- target-arm/translate-a64.c | 182 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +181 -1
@@ -328,6 +328,60 @@ static inline int fp_reg_hi_offset(int regno) return offsetof(CPUARMState, vfp.regs[regno * 2 + 1]); } +/* Convenience accessors for reading and writing single and double +* FP registers. Writing clears the upper parts of the associated +* 128 bit vector register, as required by the architecture. +* Note that unlike the GP register accessors, the values returned +* by the read functions must be manually freed. +*/ +static TCGv_i64 read_fp_dreg (DisasContext *s,int reg) +{ +TCGv_i64 v =tcg_temp_new_i64 (); + +tcg_gen_ld_i64 (v, cpu_env,fp_reg_offset (reg,MO_64 )); +return v; +} + +static TCGv_i32 read_fp_sreg (DisasContext *s,int reg) +{ +TCGv_i32 v =tcg_temp_new_i32 (); + +tcg_gen_ld_i32 (v, cpu_env,fp_reg_offset (reg,MO_32 )); +return v; +} + +static void write_fp_dreg (DisasContext *s,int reg,TCGv_i64 v) +{ +TCGv_i64 tcg_zero =tcg_const_i64 (0 ); + +tcg_gen_st_i64 (v, cpu_env,fp_reg_offset (reg,MO_64 )); +tcg_gen_st_i64 (tcg_zero, cpu_env,fp_reg_hi_offset (reg)); +tcg_temp_free_i64 (tcg_zero); +} + +static void write_fp_sreg (DisasContext *s,int reg,TCGv_i32 v) +{ +TCGv_i64 tmp =tcg_temp_new_i64 (); + +tcg_gen_extu_i32_i64 (tmp, v); +write_fp_dreg (s, reg, tmp); +tcg_temp_free_i64 (tmp); +} + +static TCGv_ptr get_fpstatus_ptr (void ) +{ +TCGv_ptr statusptr =tcg_temp_new_ptr (); +int offset; + +/* In A64 all instructions (both FP and Neon) use the FPCR; +* there is no equivalent of the A32 Neon "standard FPSCR value" +* and all operations use vfp.fp_status. +*/ + offset = offsetof(CPUARMState, vfp.fp_status); +tcg_gen_addi_ptr (statusptr, cpu_env, offset); +return statusptr; +} +/* Set ZF and NF based on a 64 bit result. This is alas fiddlier * than the 32 bit equivalent. */
@@ -3176,6 +3230,112 @@ static void disas_fp_1src(DisasContext *s, uint32_t insn)unsupported_encoding (s, insn); } +/* C3.6.26 Floating-point data-processing (2 source) - single precision */ +static void handle_fp_2src_single (DisasContext *s,int opcode, +int rd,int rn,int rm) +{ +TCGv_i32 tcg_op1; +TCGv_i32 tcg_op2; +TCGv_i32 tcg_res; +TCGv_ptr fpst; + + tcg_res =tcg_temp_new_i32 (); + fpst =get_fpstatus_ptr (); + tcg_op1 =read_fp_sreg (s, rn); + tcg_op2 =read_fp_sreg (s, rm); + +switch (opcode) { +case 0x0 :/* FMUL */ +gen_helper_vfp_muls (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x1 :/* FDIV */ +gen_helper_vfp_divs (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x2 :/* FADD */ +gen_helper_vfp_adds (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x3 :/* FSUB */ +gen_helper_vfp_subs (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x4 :/* FMAX */ +gen_helper_vfp_maxs (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x5 :/* FMIN */ +gen_helper_vfp_mins (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x6 :/* FMAXNM */ +gen_helper_vfp_maxnums (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x7 :/* FMINNM */ +gen_helper_vfp_minnums (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x8 :/* FNMUL */ +gen_helper_vfp_muls (tcg_res, tcg_op1, tcg_op2, fpst); +gen_helper_vfp_negs (tcg_res, tcg_res); +break ; + } + +write_fp_sreg (s, rd, tcg_res); + +tcg_temp_free_ptr (fpst); +tcg_temp_free_i32 (tcg_op1); +tcg_temp_free_i32 (tcg_op2); +tcg_temp_free_i32 (tcg_res); +} + +/* C3.6.26 Floating-point data-processing (2 source) - double precision */ +static void handle_fp_2src_double (DisasContext *s,int opcode, +int rd,int rn,int rm) +{ +TCGv_i64 tcg_op1; +TCGv_i64 tcg_op2; +TCGv_i64 tcg_res; +TCGv_ptr fpst; + + tcg_res =tcg_temp_new_i64 (); + fpst =get_fpstatus_ptr (); + tcg_op1 =read_fp_dreg (s, rn); + tcg_op2 =read_fp_dreg (s, rm); + +switch (opcode) { +case 0x0 :/* FMUL */ +gen_helper_vfp_muld (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x1 :/* FDIV */ +gen_helper_vfp_divd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x2 :/* FADD */ +gen_helper_vfp_addd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x3 :/* FSUB */ +gen_helper_vfp_subd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x4 :/* FMAX */ +gen_helper_vfp_maxd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x5 :/* FMIN */ +gen_helper_vfp_mind (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x6 :/* FMAXNM */ +gen_helper_vfp_maxnumd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x7 :/* FMINNM */ +gen_helper_vfp_minnumd (tcg_res, tcg_op1, tcg_op2, fpst); +break ; +case 0x8 :/* FNMUL */ +gen_helper_vfp_muld (tcg_res, tcg_op1, tcg_op2, fpst); +gen_helper_vfp_negd (tcg_res, tcg_res); +break ; + } + +write_fp_dreg (s, rd, tcg_res); + +tcg_temp_free_ptr (fpst); +tcg_temp_free_i64 (tcg_op1); +tcg_temp_free_i64 (tcg_op2); +tcg_temp_free_i64 (tcg_res); +} +/* C3.6.26 Floating point data-processing (2 source) * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
@@ -3184,7 +3344,27 @@ static void disas_fp_1src(DisasContext *s, uint32_t insn)*/ static void disas_fp_2src (DisasContext *s,uint32_t insn) { -unsupported_encoding (s, insn); +int type =extract32 (insn,22 ,2 ); +int rd =extract32 (insn,0 ,5 ); +int rn =extract32 (insn,5 ,5 ); +int rm =extract32 (insn,16 ,5 ); +int opcode =extract32 (insn,12 ,4 ); + +if (opcode >8 ) { +unallocated_encoding (s); +return ; + } + +switch (type) { +case 0 : +handle_fp_2src_single (s, opcode, rd, rn, rm); +break ; +case 1 : +handle_fp_2src_double (s, opcode, rd, rn, rm); +break ; +default : +unallocated_encoding (s); + } }/* C3.6.27 Floating point data-processing (3 source)
Signature · 1 line
1.8.5
PATCH v2 5/10 target-arm: A64: Add "Floating-point data-processing (3 source)" insns
In reply to Peter MaydellFrom: Alexander Graf <[email protected]>
This patch adds emulation for the "Floating-point data-processing (3 source)" group of instructions.
[WN: Commit message tweak, merged single and double precision patches.
Implement using muladd as suggested by Richard Henderson.]
--- target-arm/translate-a64.c | 95 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +94 -1
@@ -3367,6 +3367,82 @@ static void disas_fp_2src(DisasContext *s, uint32_t insn) } } +/* C3.6.27 Floating-point data-processing (3 source) - single precision */ +static void handle_fp_3src_single (DisasContext *s,bool o0,bool o1, +int rd,int rn,int rm,int ra) +{ +TCGv_i32 tcg_op1, tcg_op2, tcg_op3; +TCGv_i32 tcg_res =tcg_temp_new_i32 (); +TCGv_ptr fpst =get_fpstatus_ptr (); + + tcg_op1 =read_fp_sreg (s, rn); + tcg_op2 =read_fp_sreg (s, rm); + tcg_op3 =read_fp_sreg (s, ra); + +/* These are fused multiply-add, and must be done as one +* floating point operation with no rounding between the +* multiplication and addition steps. +* NB that doing the negations here as separate steps is +* correct : an input NaN should come out with its sign bit +* flipped if it is a negated-input. +*/ +if (o1 == true) { +gen_helper_vfp_negs (tcg_op3, tcg_op3); + } + +if (o0 != o1) { +gen_helper_vfp_negs (tcg_op1, tcg_op1); + } + +gen_helper_vfp_muladds (tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst); + +write_fp_sreg (s, rd, tcg_res); + +tcg_temp_free_ptr (fpst); +tcg_temp_free_i32 (tcg_op1); +tcg_temp_free_i32 (tcg_op2); +tcg_temp_free_i32 (tcg_op3); +tcg_temp_free_i32 (tcg_res); +} + +/* C3.6.27 Floating-point data-processing (3 source) - double precision */ +static void handle_fp_3src_double (DisasContext *s,bool o0,bool o1, +int rd,int rn,int rm,int ra) +{ +TCGv_i64 tcg_op1, tcg_op2, tcg_op3; +TCGv_i64 tcg_res =tcg_temp_new_i64 (); +TCGv_ptr fpst =get_fpstatus_ptr (); + + tcg_op1 =read_fp_dreg (s, rn); + tcg_op2 =read_fp_dreg (s, rm); + tcg_op3 =read_fp_dreg (s, ra); + +/* These are fused multiply-add, and must be done as one +* floating point operation with no rounding between the +* multiplication and addition steps. +* NB that doing the negations here as separate steps is +* correct : an input NaN should come out with its sign bit +* flipped if it is a negated-input. +*/ +if (o1 == true) { +gen_helper_vfp_negd (tcg_op3, tcg_op3); + } + +if (o0 != o1) { +gen_helper_vfp_negd (tcg_op1, tcg_op1); + } + +gen_helper_vfp_muladdd (tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst); + +write_fp_dreg (s, rd, tcg_res); + +tcg_temp_free_ptr (fpst); +tcg_temp_free_i64 (tcg_op1); +tcg_temp_free_i64 (tcg_op2); +tcg_temp_free_i64 (tcg_op3); +tcg_temp_free_i64 (tcg_res); +} +/* C3.6.27 Floating point data-processing (3 source) * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0 * +---+---+---+-----------+------+----+------+----+------+------+------+
@@ -3375,7 +3451,24 @@ static void disas_fp_2src(DisasContext *s, uint32_t insn)*/ static void disas_fp_3src (DisasContext *s,uint32_t insn) { -unsupported_encoding (s, insn); +int type =extract32 (insn,22 ,2 ); +int rd =extract32 (insn,0 ,5 ); +int rn =extract32 (insn,5 ,5 ); +int ra =extract32 (insn,10 ,5 ); +int rm =extract32 (insn,16 ,5 ); +bool o0 =extract32 (insn,15 ,1 ); +bool o1 =extract32 (insn,21 ,1 ); + +switch (type) { +case 0 : +handle_fp_3src_single (s, o0, o1, rd, rn, rm, ra); +break ; +case 1 : +handle_fp_3src_double (s, o0, o1, rd, rn, rm, ra); +break ; +default : +unallocated_encoding (s); + } }/* C3.6.28 Floating point immediate
Signature · 1 line
1.8.5
PATCH v2 6/10 target-arm: A64: Add fmov (scalar, immediate) instruction
In reply to Peter MaydellFrom: Alexander Graf <[email protected]>
This patch adds emulation for the fmov instruction working on scalars with an immediate payload.
--- target-arm/translate-a64.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +31 -1
@@ -3479,7 +3479,37 @@ static void disas_fp_3src(DisasContext *s, uint32_t insn)*/ static void disas_fp_imm (DisasContext *s,uint32_t insn) { -unsupported_encoding (s, insn); +int rd =extract32 (insn,0 ,5 ); +int imm8 =extract32 (insn,13 ,8 ); +int is_double =extract32 (insn,22 ,2 ); +uint64_t imm; +TCGv_i64 tcg_res; + +if (is_double >1 ) { +unallocated_encoding (s); +return ; + } + +/* The imm8 encodes the sign bit, enough bits to represent +* an exponent in the range 01....1xx to 10....0xx, +* and the most significant 4 bits of the mantissa; see +* VFPExpandImm() in the v8 ARM ARM. +*/ +if (is_double) { + imm = (extract32 (imm8,7 ,1 ) ?0x8000 :0 ) | + (extract32 (imm8,6 ,1 ) ?0x3fc0 :0x4000 ) | +extract32 (imm8,0 ,6 ); + imm <<=48 ; + }else { + imm = (extract32 (imm8,7 ,1 ) ?0x8000 :0 ) | + (extract32 (imm8,6 ,1 ) ?0x3e00 :0x4000 ) | + (extract32 (imm8,0 ,6 ) <<3 ); + imm <<=16 ; + } + + tcg_res =tcg_const_i64 (imm); +write_fp_dreg (s, rd, tcg_res); +tcg_temp_free_i64 (tcg_res); }/* C3.6.29 Floating point <-> fixed point conversions
Signature · 1 line
1.8.5
PATCH v2 7/10 target-arm: A64: Add support for floating point compare
In reply to Peter MaydellFrom: Claudio Fontana <[email protected]>
Add decoding support for C3.6.22 Floating-point compare.
--- target-arm/helper-a64.c | 45 ++++++++++++++++++++++++++++++++ target-arm/helper-a64.h | 4 +++ target-arm/translate-a64.c | 65 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-)
target-arm/helper-a64.c +45 -0
@@ -77,3 +77,48 @@ uint64_t HELPER(rbit64)(uint64_t x)return x; } + +/* Convert a softfloat float_relation_ (as returned by +* the float*_compare functions) to the correct ARM +* NZCV flag state. +*/ +static inline uint32_t float_rel_to_flags (int res) +{ +uint64_t flags; +switch (res) { +case float_relation_equal: + flags =PSTATE_Z |PSTATE_C ; +break ; +case float_relation_less: + flags =PSTATE_N ; +break ; +case float_relation_greater: + flags =PSTATE_C ; +break ; +case float_relation_unordered: +default : + flags =PSTATE_C |PSTATE_V ; +break ; + } +return flags; +} + +uint64_t HELPER (vfp_cmps_a64 )(float32 x,float32 y,void *fp_status) +{ +return float_rel_to_flags (float32_compare_quiet (x, y, fp_status)); +} + +uint64_t HELPER (vfp_cmpes_a64 )(float32 x,float32 y,void *fp_status) +{ +return float_rel_to_flags (float32_compare (x, y, fp_status)); +} + +uint64_t HELPER (vfp_cmpd_a64 )(float64 x,float64 y,void *fp_status) +{ +return float_rel_to_flags (float64_compare_quiet (x, y, fp_status)); +} + +uint64_t HELPER (vfp_cmped_a64 )(float64 x,float64 y,void *fp_status) +{ +return float_rel_to_flags (float64_compare (x, y, fp_status)); +}
target-arm/helper-a64.h +4 -0
@@ -22,3 +22,7 @@ DEF_HELPER_FLAGS_1(clz64, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_FLAGS_1(cls64, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_FLAGS_1(cls32, TCG_CALL_NO_RWG_SE, i32, i32) DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64) +DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr) +DEF_HELPER_3(vfp_cmpes_a64, i64, f32, f32, ptr) +DEF_HELPER_3(vfp_cmpd_a64, i64, f64, f64, ptr) +DEF_HELPER_3 (vfp_cmped_a64, i64, f64, f64, ptr)
target-arm/translate-a64.c +64 -1
77 lines not on this page · raw message
Signature · 1 line
1.8.5
PATCH v2 8/10 target-arm: A64: Add support for floating point conditional compare
In reply to Peter MaydellFrom: Claudio Fontana <[email protected]>
This adds decoding support for C3.6.23 FP Conditional Compare.
--- target-arm/translate-a64.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +34 -1
@@ -3268,7 +3268,40 @@ static void disas_fp_compare(DisasContext *s, uint32_t insn)*/ static void disas_fp_ccomp (DisasContext *s,uint32_t insn) { -unsupported_encoding (s, insn); +unsigned int mos, type, rm, cond, rn, op, nzcv; +TCGv_i64 tcg_flags; +int label_continue =-1 ; + + mos =extract32 (insn,29 ,3 ); + type =extract32 (insn,22 ,2 );/* 0 = single, 1 = double */ + rm =extract32 (insn,16 ,5 ); + cond =extract32 (insn,12 ,4 ); + rn =extract32 (insn,5 ,5 ); + op =extract32 (insn,4 ,1 ); + nzcv =extract32 (insn,0 ,4 ); + +if (mos || type >1 ) { +unallocated_encoding (s); +return ; + } + +if (cond <0x0e ) {/* not always */ +int label_match =gen_new_label (); + label_continue =gen_new_label (); +arm_gen_test_cc (cond, label_match); +/* nomatch: */ + tcg_flags =tcg_const_i64 (nzcv <<28 ); +gen_set_nzcv (tcg_flags); +tcg_temp_free_i64 (tcg_flags); +tcg_gen_br (label_continue); +gen_set_label (label_match); + } + +handle_fp_compare (s, type, rn, rm, false, op); + +if (cond <0x0e ) { +gen_set_label (label_continue); + } }/* C3.6.24 Floating point conditional select
Signature · 1 line
1.8.5
PATCH v2 9/10 target-arm: A64: Add support for floating point cond select
In reply to Peter MaydellFrom: Claudio Fontana <[email protected]>
This adds decoding support for C3.6.24 FP conditional select.
--- target-arm/translate-a64.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +44 -1
@@ -3304,6 +3304,20 @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn) } } +/* copy src FP register to dst FP register; type specifies single or double */ +static void gen_mov_fp2fp (DisasContext *s,int type,int dst,int src) +{ +if (type) { +TCGv_i64 v =read_fp_dreg (s, src); +write_fp_dreg (s, dst, v); +tcg_temp_free_i64 (v); + }else { +TCGv_i32 v =read_fp_sreg (s, src); +write_fp_sreg (s, dst, v); +tcg_temp_free_i32 (v); + } +} +/* C3.6.24 Floating point conditional select * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0 * +---+---+---+-----------+------+---+------+------+-----+------+------+
@@ -3312,7 +3326,36 @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn)*/ static void disas_fp_csel (DisasContext *s,uint32_t insn) { -unsupported_encoding (s, insn); +unsigned int mos, type, rm, cond, rn, rd; +int label_continue =-1 ; + + mos =extract32 (insn,29 ,3 ); + type =extract32 (insn,22 ,2 );/* 0 = single, 1 = double */ + rm =extract32 (insn,16 ,5 ); + cond =extract32 (insn,12 ,4 ); + rn =extract32 (insn,5 ,5 ); + rd =extract32 (insn,0 ,5 ); + +if (mos || type >1 ) { +unallocated_encoding (s); +return ; + } + +if (cond <0x0e ) {/* not always */ +int label_match =gen_new_label (); + label_continue =gen_new_label (); +arm_gen_test_cc (cond, label_match); +/* nomatch: */ +gen_mov_fp2fp (s, type, rd, rm); +tcg_gen_br (label_continue); +gen_set_label (label_match); + } + +gen_mov_fp2fp (s, type, rd, rn); + +if (cond <0x0e ) {/* continue */ +gen_set_label (label_continue); + } }/* C3.6.25 Floating point data-processing (1 source)
Signature · 1 line
1.8.5
PATCH v2 10/10 target-arm: Give the FPSCR rounding modes names
In reply to Peter MaydellFrom: Alexander Graf <[email protected]>
When setting rounding modes we currently just hardcode the numeric values for rounding modes in a big switch statement.
With AArch64 support coming, we will need to refer to these rounding modes at different places throughout the code though, so let's better give them names so we don't get confused by accident.
--- target-arm/cpu.h | 9 +++++++++ target-arm/helper.c | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-)
target-arm/cpu.h +9 -0
@@ -487,6 +487,15 @@ static inline void vfp_set_fpcr(CPUARMState *env, uint32_t val)vfp_set_fpscr (env, new_fpscr); } +enum arm_fprounding { +FPROUNDING_TIEEVEN , +FPROUNDING_POSINF , +FPROUNDING_NEGINF , +FPROUNDING_ZERO , +FPROUNDING_TIEAWAY , +FPROUNDING_ODD +}; +enum arm_cpu_mode {ARM_CPU_MODE_USR =0x10 ,ARM_CPU_MODE_FIQ =0x11 ,
target-arm/helper.c +4 -4
@@ -3815,16 +3815,16 @@ void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)if (changed & (3 <<22 )) { i = (val >>22 ) &3 ;switch (i) { -case 0 : +case FPROUNDING_TIEEVEN : i = float_round_nearest_even;break ; -case 1 : +case FPROUNDING_POSINF : i = float_round_up;break ; -case 2 : +case FPROUNDING_NEGINF : i = float_round_down;break ; -case 3 : +case FPROUNDING_ZERO : i = float_round_to_zero;break ; }
Signature · 1 line
1.8.5