Patchwork target-arm: Set Invalid flag for NaN in float-to-int conversions

login
register
mail settings
Submitter Peter Maydell
Date April 19, 2011, 4:30 p.m.
Message ID <1303230655-31280-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/92030/
State New
Headers show

Comments

Peter Maydell - April 19, 2011, 4:30 p.m.
When we catch the special case of an input NaN in ARM float to int
helper functions, set the Invalid flag as well as returning the
correct result.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target-arm/helper.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
Aurelien Jarno - April 20, 2011, 11:02 a.m.
On Tue, Apr 19, 2011 at 05:30:55PM +0100, Peter Maydell wrote:
> When we catch the special case of an input NaN in ARM float to int
> helper functions, set the Invalid flag as well as returning the
> correct result.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target-arm/helper.c |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)

Thanks, applied.
 
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index 12127de..d5f2ace 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -2542,6 +2542,7 @@ float64 VFP_HELPER(sito, d)(uint32_t x, CPUState *env)
>  uint32_t VFP_HELPER(toui, s)(float32 x, CPUState *env)
>  {
>      if (float32_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float32_to_uint32(x, &env->vfp.fp_status);
> @@ -2550,6 +2551,7 @@ uint32_t VFP_HELPER(toui, s)(float32 x, CPUState *env)
>  uint32_t VFP_HELPER(toui, d)(float64 x, CPUState *env)
>  {
>      if (float64_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float64_to_uint32(x, &env->vfp.fp_status);
> @@ -2558,6 +2560,7 @@ uint32_t VFP_HELPER(toui, d)(float64 x, CPUState *env)
>  uint32_t VFP_HELPER(tosi, s)(float32 x, CPUState *env)
>  {
>      if (float32_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float32_to_int32(x, &env->vfp.fp_status);
> @@ -2566,6 +2569,7 @@ uint32_t VFP_HELPER(tosi, s)(float32 x, CPUState *env)
>  uint32_t VFP_HELPER(tosi, d)(float64 x, CPUState *env)
>  {
>      if (float64_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float64_to_int32(x, &env->vfp.fp_status);
> @@ -2574,6 +2578,7 @@ uint32_t VFP_HELPER(tosi, d)(float64 x, CPUState *env)
>  uint32_t VFP_HELPER(touiz, s)(float32 x, CPUState *env)
>  {
>      if (float32_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float32_to_uint32_round_to_zero(x, &env->vfp.fp_status);
> @@ -2582,6 +2587,7 @@ uint32_t VFP_HELPER(touiz, s)(float32 x, CPUState *env)
>  uint32_t VFP_HELPER(touiz, d)(float64 x, CPUState *env)
>  {
>      if (float64_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float64_to_uint32_round_to_zero(x, &env->vfp.fp_status);
> @@ -2590,6 +2596,7 @@ uint32_t VFP_HELPER(touiz, d)(float64 x, CPUState *env)
>  uint32_t VFP_HELPER(tosiz, s)(float32 x, CPUState *env)
>  {
>      if (float32_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float32_to_int32_round_to_zero(x, &env->vfp.fp_status);
> @@ -2598,6 +2605,7 @@ uint32_t VFP_HELPER(tosiz, s)(float32 x, CPUState *env)
>  uint32_t VFP_HELPER(tosiz, d)(float64 x, CPUState *env)
>  {
>      if (float64_is_any_nan(x)) {
> +        float_raise(float_flag_invalid, &env->vfp.fp_status);
>          return 0;
>      }
>      return float64_to_int32_round_to_zero(x, &env->vfp.fp_status);
> @@ -2636,6 +2644,7 @@ uint##fsz##_t VFP_HELPER(to##name, p)(float##fsz x, uint32_t shift, \
>  { \
>      float##fsz tmp; \
>      if (float##fsz##_is_any_nan(x)) { \
> +        float_raise(float_flag_invalid, &env->vfp.fp_status); \
>          return 0; \
>      } \
>      tmp = float##fsz##_scalbn(x, shift, &env->vfp.fp_status); \
> -- 
> 1.7.1
> 
> 
>

Patch

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 12127de..d5f2ace 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -2542,6 +2542,7 @@  float64 VFP_HELPER(sito, d)(uint32_t x, CPUState *env)
 uint32_t VFP_HELPER(toui, s)(float32 x, CPUState *env)
 {
     if (float32_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float32_to_uint32(x, &env->vfp.fp_status);
@@ -2550,6 +2551,7 @@  uint32_t VFP_HELPER(toui, s)(float32 x, CPUState *env)
 uint32_t VFP_HELPER(toui, d)(float64 x, CPUState *env)
 {
     if (float64_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float64_to_uint32(x, &env->vfp.fp_status);
@@ -2558,6 +2560,7 @@  uint32_t VFP_HELPER(toui, d)(float64 x, CPUState *env)
 uint32_t VFP_HELPER(tosi, s)(float32 x, CPUState *env)
 {
     if (float32_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float32_to_int32(x, &env->vfp.fp_status);
@@ -2566,6 +2569,7 @@  uint32_t VFP_HELPER(tosi, s)(float32 x, CPUState *env)
 uint32_t VFP_HELPER(tosi, d)(float64 x, CPUState *env)
 {
     if (float64_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float64_to_int32(x, &env->vfp.fp_status);
@@ -2574,6 +2578,7 @@  uint32_t VFP_HELPER(tosi, d)(float64 x, CPUState *env)
 uint32_t VFP_HELPER(touiz, s)(float32 x, CPUState *env)
 {
     if (float32_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float32_to_uint32_round_to_zero(x, &env->vfp.fp_status);
@@ -2582,6 +2587,7 @@  uint32_t VFP_HELPER(touiz, s)(float32 x, CPUState *env)
 uint32_t VFP_HELPER(touiz, d)(float64 x, CPUState *env)
 {
     if (float64_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float64_to_uint32_round_to_zero(x, &env->vfp.fp_status);
@@ -2590,6 +2596,7 @@  uint32_t VFP_HELPER(touiz, d)(float64 x, CPUState *env)
 uint32_t VFP_HELPER(tosiz, s)(float32 x, CPUState *env)
 {
     if (float32_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float32_to_int32_round_to_zero(x, &env->vfp.fp_status);
@@ -2598,6 +2605,7 @@  uint32_t VFP_HELPER(tosiz, s)(float32 x, CPUState *env)
 uint32_t VFP_HELPER(tosiz, d)(float64 x, CPUState *env)
 {
     if (float64_is_any_nan(x)) {
+        float_raise(float_flag_invalid, &env->vfp.fp_status);
         return 0;
     }
     return float64_to_int32_round_to_zero(x, &env->vfp.fp_status);
@@ -2636,6 +2644,7 @@  uint##fsz##_t VFP_HELPER(to##name, p)(float##fsz x, uint32_t shift, \
 { \
     float##fsz tmp; \
     if (float##fsz##_is_any_nan(x)) { \
+        float_raise(float_flag_invalid, &env->vfp.fp_status); \
         return 0; \
     } \
     tmp = float##fsz##_scalbn(x, shift, &env->vfp.fp_status); \