diff mbox series

[24/67] target/arm: Pass fpstatus to vfp_sqrt*

Message ID 20241201150607.12812-25-richard.henderson@linaro.org
State Superseded
Headers show
Series target/arm: AArch64 decodetree conversion, final part | expand

Commit Message

Richard Henderson Dec. 1, 2024, 3:05 p.m. UTC
Pass fpstatus not env, like most other fp helpers.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/helper.h            |  6 +++---
 target/arm/tcg/translate-a64.c | 15 +++++++--------
 target/arm/tcg/translate-vfp.c |  6 +++---
 target/arm/vfp_helper.c        | 12 ++++++------
 4 files changed, 19 insertions(+), 20 deletions(-)

Comments

Peter Maydell Dec. 5, 2024, 8:44 p.m. UTC | #1
On Sun, 1 Dec 2024 at 15:11, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Pass fpstatus not env, like most other fp helpers.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

I have a patch pretty similar to this in my work-in-progress
FEAT_AFP series, because there I wanted it as part of splitting
env->vfp.fp_status into separate A32 and A64 fp_status fields...

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Philippe Mathieu-Daudé Dec. 5, 2024, 9:20 p.m. UTC | #2
On 1/12/24 16:05, Richard Henderson wrote:
> Pass fpstatus not env, like most other fp helpers.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/arm/helper.h            |  6 +++---
>   target/arm/tcg/translate-a64.c | 15 +++++++--------
>   target/arm/tcg/translate-vfp.c |  6 +++---
>   target/arm/vfp_helper.c        | 12 ++++++------
>   4 files changed, 19 insertions(+), 20 deletions(-)


> @@ -10403,6 +10401,7 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
>               handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
>               return;
>           case 0x7f: /* FSQRT */
> +            need_fpstatus = true;

Should this change be in a different patch?

>               if (size == 3 && !is_q) {
>                   unallocated_encoding(s);
>                   return;
>   }
Peter Maydell Dec. 5, 2024, 9:38 p.m. UTC | #3
On Thu, 5 Dec 2024 at 21:21, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> On 1/12/24 16:05, Richard Henderson wrote:
> > Pass fpstatus not env, like most other fp helpers.
> >
> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> > ---
> >   target/arm/helper.h            |  6 +++---
> >   target/arm/tcg/translate-a64.c | 15 +++++++--------
> >   target/arm/tcg/translate-vfp.c |  6 +++---
> >   target/arm/vfp_helper.c        | 12 ++++++------
> >   4 files changed, 19 insertions(+), 20 deletions(-)
>
>
> > @@ -10403,6 +10401,7 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
> >               handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
> >               return;
> >           case 0x7f: /* FSQRT */
> > +            need_fpstatus = true;
>
> Should this change be in a different patch?

No, this is correct. It tells the common code in this function
that it needs to set up tcg_fpstatus, because in the next change
in a later switch() in this function:

                 case 0x7f: /* FSQRT */
-                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_env);
+                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_fpstatus);
                     break;

we will now want to use it.

-- PMM
Philippe Mathieu-Daudé Dec. 5, 2024, 9:40 p.m. UTC | #4
On 5/12/24 22:38, Peter Maydell wrote:
> On Thu, 5 Dec 2024 at 21:21, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> On 1/12/24 16:05, Richard Henderson wrote:
>>> Pass fpstatus not env, like most other fp helpers.
>>>
>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>>    target/arm/helper.h            |  6 +++---
>>>    target/arm/tcg/translate-a64.c | 15 +++++++--------
>>>    target/arm/tcg/translate-vfp.c |  6 +++---
>>>    target/arm/vfp_helper.c        | 12 ++++++------
>>>    4 files changed, 19 insertions(+), 20 deletions(-)
>>
>>
>>> @@ -10403,6 +10401,7 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
>>>                handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
>>>                return;
>>>            case 0x7f: /* FSQRT */
>>> +            need_fpstatus = true;
>>
>> Should this change be in a different patch?
> 
> No, this is correct. It tells the common code in this function
> that it needs to set up tcg_fpstatus, because in the next change
> in a later switch() in this function:
> 
>                   case 0x7f: /* FSQRT */
> -                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_env);
> +                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_fpstatus);
>                       break;
> 
> we will now want to use it.

Oh now I see, not obvious. Thanks for the explanation!

Phil.
Richard Henderson Dec. 6, 2024, 2:01 a.m. UTC | #5
On 12/5/24 14:44, Peter Maydell wrote:
> On Sun, 1 Dec 2024 at 15:11, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Pass fpstatus not env, like most other fp helpers.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> 
> I have a patch pretty similar to this in my work-in-progress
> FEAT_AFP series, because there I wanted it as part of splitting
> env->vfp.fp_status into separate A32 and A64 fp_status fields...

I thought that might be the case. I have additional changes in this area for SME2. I'll 
send those out separately this evening, just so we can compare notes.


r~
diff mbox series

Patch

diff --git a/target/arm/helper.h b/target/arm/helper.h
index 58919b670e..0a697e752b 100644
--- a/target/arm/helper.h
+++ b/target/arm/helper.h
@@ -133,9 +133,9 @@  DEF_HELPER_3(vfp_maxnumd, f64, f64, f64, ptr)
 DEF_HELPER_3(vfp_minnumh, f16, f16, f16, ptr)
 DEF_HELPER_3(vfp_minnums, f32, f32, f32, ptr)
 DEF_HELPER_3(vfp_minnumd, f64, f64, f64, ptr)
-DEF_HELPER_2(vfp_sqrth, f16, f16, env)
-DEF_HELPER_2(vfp_sqrts, f32, f32, env)
-DEF_HELPER_2(vfp_sqrtd, f64, f64, env)
+DEF_HELPER_2(vfp_sqrth, f16, f16, ptr)
+DEF_HELPER_2(vfp_sqrts, f32, f32, ptr)
+DEF_HELPER_2(vfp_sqrtd, f64, f64, ptr)
 DEF_HELPER_3(vfp_cmph, void, f16, f16, env)
 DEF_HELPER_3(vfp_cmps, void, f32, f32, env)
 DEF_HELPER_3(vfp_cmpd, void, f64, f64, env)
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index 87731e0be4..c976c15b08 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -8405,8 +8405,8 @@  static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
 
     switch (opcode) {
     case 0x3: /* FSQRT */
-        gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_env);
-        goto done;
+        gen_fpst = gen_helper_vfp_sqrts;
+        break;
     case 0x6: /* BFCVT */
         gen_fpst = gen_helper_bfcvt;
         break;
@@ -8454,7 +8454,6 @@  static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
         gen_fpst(tcg_res, tcg_op, fpst);
     }
 
- done:
     write_fp_sreg(s, rd, tcg_res);
 }
 
@@ -8471,8 +8470,8 @@  static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
 
     switch (opcode) {
     case 0x3: /* FSQRT */
-        gen_helper_vfp_sqrtd(tcg_res, tcg_op, tcg_env);
-        goto done;
+        gen_fpst = gen_helper_vfp_sqrtd;
+        break;
     case 0x8: /* FRINTN */
     case 0x9: /* FRINTP */
     case 0xa: /* FRINTM */
@@ -8517,7 +8516,6 @@  static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
         gen_fpst(tcg_res, tcg_op, fpst);
     }
 
- done:
     write_fp_dreg(s, rd, tcg_res);
 }
 
@@ -9460,7 +9458,7 @@  static void handle_2misc_64(DisasContext *s, int opcode, bool u,
         gen_vfp_negd(tcg_rd, tcg_rn);
         break;
     case 0x7f: /* FSQRT */
-        gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, tcg_env);
+        gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, tcg_fpstatus);
         break;
     case 0x1a: /* FCVTNS */
     case 0x1b: /* FCVTMS */
@@ -10403,6 +10401,7 @@  static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
             handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
             return;
         case 0x7f: /* FSQRT */
+            need_fpstatus = true;
             if (size == 3 && !is_q) {
                 unallocated_encoding(s);
                 return;
@@ -10632,7 +10631,7 @@  static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
                     gen_vfp_negs(tcg_res, tcg_op);
                     break;
                 case 0x7f: /* FSQRT */
-                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_env);
+                    gen_helper_vfp_sqrts(tcg_res, tcg_op, tcg_fpstatus);
                     break;
                 case 0x1a: /* FCVTNS */
                 case 0x1b: /* FCVTMS */
diff --git a/target/arm/tcg/translate-vfp.c b/target/arm/tcg/translate-vfp.c
index b6fa28a7bf..c160a86e70 100644
--- a/target/arm/tcg/translate-vfp.c
+++ b/target/arm/tcg/translate-vfp.c
@@ -2424,17 +2424,17 @@  DO_VFP_2OP(VNEG, dp, gen_vfp_negd, aa32_fpdp_v2)
 
 static void gen_VSQRT_hp(TCGv_i32 vd, TCGv_i32 vm)
 {
-    gen_helper_vfp_sqrth(vd, vm, tcg_env);
+    gen_helper_vfp_sqrth(vd, vm, fpstatus_ptr(FPST_FPCR_F16));
 }
 
 static void gen_VSQRT_sp(TCGv_i32 vd, TCGv_i32 vm)
 {
-    gen_helper_vfp_sqrts(vd, vm, tcg_env);
+    gen_helper_vfp_sqrts(vd, vm, fpstatus_ptr(FPST_FPCR));
 }
 
 static void gen_VSQRT_dp(TCGv_i64 vd, TCGv_i64 vm)
 {
-    gen_helper_vfp_sqrtd(vd, vm, tcg_env);
+    gen_helper_vfp_sqrtd(vd, vm, fpstatus_ptr(FPST_FPCR));
 }
 
 DO_VFP_2OP(VSQRT, hp, gen_VSQRT_hp, aa32_fp16_arith)
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
index 62638d2b1f..f24992c798 100644
--- a/target/arm/vfp_helper.c
+++ b/target/arm/vfp_helper.c
@@ -314,19 +314,19 @@  VFP_BINOP(minnum)
 VFP_BINOP(maxnum)
 #undef VFP_BINOP
 
-dh_ctype_f16 VFP_HELPER(sqrt, h)(dh_ctype_f16 a, CPUARMState *env)
+dh_ctype_f16 VFP_HELPER(sqrt, h)(dh_ctype_f16 a, void *fpstp)
 {
-    return float16_sqrt(a, &env->vfp.fp_status_f16);
+    return float16_sqrt(a, fpstp);
 }
 
-float32 VFP_HELPER(sqrt, s)(float32 a, CPUARMState *env)
+float32 VFP_HELPER(sqrt, s)(float32 a, void *fpstp)
 {
-    return float32_sqrt(a, &env->vfp.fp_status);
+    return float32_sqrt(a, fpstp);
 }
 
-float64 VFP_HELPER(sqrt, d)(float64 a, CPUARMState *env)
+float64 VFP_HELPER(sqrt, d)(float64 a, void *fpstp)
 {
-    return float64_sqrt(a, &env->vfp.fp_status);
+    return float64_sqrt(a, fpstp);
 }
 
 static void softfloat_to_vfp_compare(CPUARMState *env, FloatRelation cmp)