target-arm/helper.c: For float-int conversion helpers pass ints as ints
PATCH 1/1 target-arm/helper.c: For float-int conversion helpers pass ints as ints
Correct the argument and return types for the float<->int conversion helper functions so that integer arguments and return values are declared as uint32_t/uint64_t, not float32/float64. This allows us to remove the hand-rolled functions which were doing bitwise copies between the types via unions.
---
This patch is in some ways doing for helper.c what the patch
http://patchwork.ozlabs.org/patch/86441/ did for neon_helper.c, although in this case I opted to fix the prototypes not to pass integer arguments in and out in float32/float64 rather than simply replacing the helper functions with make_float*/float*_val calls.
There should be no behaviour change here, it's just a code cleanup. Tested with the usual random-instruction-set stuff.
target-arm/helper.c | 155 ++++++++++++++++++-------------------------------- target-arm/helpers.h | 60 ++++++++++---------- 2 files changed, 85 insertions(+), 130 deletions(-)
target-arm/helper.c +55 -100
@@ -2486,135 +2486,90 @@ DO_VFP_cmp(s, float32) DO_VFP_cmp(d, float64)#undef DO_VFP_cmp -/* Helper routines to perform bitwise copies between float and int. */ -static inline float32 vfp_itos (uint32_t i) -{ -union { -uint32_t i; -float32 s; - } v; - - v.i = i; -return v.s; -} - -static inline uint32_t vfp_stoi (float32 s) -{ -union { -uint32_t i; -float32 s; - } v; - - v.s = s; -return v.i; -} - -static inline float64 vfp_itod (uint64_t i) -{ -union { -uint64_t i; -float64 d; - } v; - - v.i = i; -return v.d; -} - -static inline uint64_t vfp_dtoi (float64 d) -{ -union { -uint64_t i; -float64 d; - } v; - - v.d = d; -return v.i; -} -/* Integer to float conversion. */ -float32 VFP_HELPER (uito ,s )(float32 x,CPUState *env) +float32 VFP_HELPER (uito ,s )(uint32_t x,CPUState *env) { -return uint32_to_float32 (vfp_stoi (x), &env->vfp.fp_status); +return uint32_to_float32 (x, &env->vfp.fp_status); } -float64 VFP_HELPER (uito ,d )(float32 x,CPUState *env) +float64 VFP_HELPER (uito ,d )(uint32_t x,CPUState *env) { -return uint32_to_float64 (vfp_stoi (x), &env->vfp.fp_status); +return uint32_to_float64 (x, &env->vfp.fp_status); } -float32 VFP_HELPER (sito ,s )(float32 x,CPUState *env) +float32 VFP_HELPER (sito ,s )(uint32_t x,CPUState *env) { -return int32_to_float32 (vfp_stoi (x), &env->vfp.fp_status); +return int32_to_float32 (x, &env->vfp.fp_status); } -float64 VFP_HELPER (sito ,d )(float32 x,CPUState *env) +float64 VFP_HELPER (sito ,d )(uint32_t x,CPUState *env) { -return int32_to_float64 (vfp_stoi (x), &env->vfp.fp_status); +return int32_to_float64 (x, &env->vfp.fp_status); }/* Float to integer conversion. */ -float32 VFP_HELPER (toui ,s )(float32 x,CPUState *env) +uint32_t VFP_HELPER (toui ,s )(float32 x,CPUState *env) {if (float32_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float32_to_uint32 (x, &env->vfp.fp_status)); +return float32_to_uint32 (x, &env->vfp.fp_status); } -float32 VFP_HELPER (toui ,d )(float64 x,CPUState *env) +uint32_t VFP_HELPER (toui ,d )(float64 x,CPUState *env) {if (float64_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float64_to_uint32 (x, &env->vfp.fp_status)); +return float64_to_uint32 (x, &env->vfp.fp_status); } -float32 VFP_HELPER (tosi ,s )(float32 x,CPUState *env) +uint32_t VFP_HELPER (tosi ,s )(float32 x,CPUState *env) {if (float32_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float32_to_int32 (x, &env->vfp.fp_status)); +return float32_to_int32 (x, &env->vfp.fp_status); } -float32 VFP_HELPER (tosi ,d )(float64 x,CPUState *env) +uint32_t VFP_HELPER (tosi ,d )(float64 x,CPUState *env) {if (float64_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float64_to_int32 (x, &env->vfp.fp_status)); +return float64_to_int32 (x, &env->vfp.fp_status); } -float32 VFP_HELPER (touiz ,s )(float32 x,CPUState *env) +uint32_t VFP_HELPER (touiz ,s )(float32 x,CPUState *env) {if (float32_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float32_to_uint32_round_to_zero (x, &env->vfp.fp_status)); +return float32_to_uint32_round_to_zero (x, &env->vfp.fp_status); } -float32 VFP_HELPER (touiz ,d )(float64 x,CPUState *env) +uint32_t VFP_HELPER (touiz ,d )(float64 x,CPUState *env) {if (float64_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float64_to_uint32_round_to_zero (x, &env->vfp.fp_status)); +return float64_to_uint32_round_to_zero (x, &env->vfp.fp_status); } -float32 VFP_HELPER (tosiz ,s )(float32 x,CPUState *env) +uint32_t VFP_HELPER (tosiz ,s )(float32 x,CPUState *env) {if (float32_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float32_to_int32_round_to_zero (x, &env->vfp.fp_status)); +return float32_to_int32_round_to_zero (x, &env->vfp.fp_status); } -float32 VFP_HELPER (tosiz ,d )(float64 x,CPUState *env) +uint32_t VFP_HELPER (tosiz ,d )(float64 x,CPUState *env) {if (float64_is_any_nan (x)) { -return float32_zero; +return 0 ; } -return vfp_itos (float64_to_int32_round_to_zero (x, &env->vfp.fp_status)); +return float64_to_int32_round_to_zero (x, &env->vfp.fp_status); }/* floating point conversion */
@@ -2637,33 +2592,33 @@ float32 VFP_HELPER(fcvts, d)(float64 x, CPUState *env) } /* VFP3 fixed point conversion. */ -#define VFP_CONV_FIX(name, p, ftype, itype, sign) \ -ftype VFP_HELPER(name##to, p)(ftype x, uint32_t shift, CPUState *env) \ +#define VFP_CONV_FIX(name, p, fsz, itype, sign) \ +float##fsz VFP_HELPER(name##to, p)(uint##fsz##_t x, uint32_t shift, \ + CPUState *env) \ { \ - ftype tmp; \ - tmp = sign##int32_to_##ftype ((itype##_t)vfp_##p##toi(x), \ - &env->vfp.fp_status); \ - return ftype##_scalbn(tmp, -(int)shift, &env->vfp.fp_status); \ + float##fsz tmp; \ + tmp = sign##int32_to_##float##fsz ((itype##_t)x, &env->vfp.fp_status); \ + return float##fsz##_scalbn(tmp, -(int)shift, &env->vfp.fp_status); \ } \ -ftype VFP_HELPER(to##name, p)(ftype x, uint32_t shift, CPUState *env) \ +uint##fsz##_t VFP_HELPER(to##name, p)(float##fsz x, uint32_t shift, \ + CPUState *env) \ { \ - ftype tmp; \ - if (ftype##_is_any_nan(x)) { \ - return ftype##_zero; \ + float##fsz tmp; \ + if (float##fsz##_is_any_nan(x)) { \ + return 0; \ } \ - tmp = ftype##_scalbn(x, shift, &env->vfp.fp_status); \ - return vfp_ito##p(ftype##_to_##itype##_round_to_zero(tmp, \ - &env->vfp.fp_status)); \ -} - -VFP_CONV_FIX(sh, d, float64, int16, ) -VFP_CONV_FIX(sl, d, float64, int32, ) -VFP_CONV_FIX(uh, d, float64, uint16, u) -VFP_CONV_FIX(ul, d, float64, uint32, u) -VFP_CONV_FIX(sh, s, float32, int16, ) -VFP_CONV_FIX(sl, s, float32, int32, ) -VFP_CONV_FIX(uh, s, float32, uint16, u) -VFP_CONV_FIX(ul, s, float32, uint32, u) + tmp = float##fsz##_scalbn(x, shift, &env->vfp.fp_status); \ + return float##fsz##_to_##itype##_round_to_zero(tmp, &env->vfp.fp_status); \ +} + +VFP_CONV_FIX(sh, d, 64, int16, ) +VFP_CONV_FIX(sl, d, 64, int32, ) +VFP_CONV_FIX(uh, d, 64, uint16, u) +VFP_CONV_FIX(ul, d, 64, uint32, u) +VFP_CONV_FIX(sh, s, 32, int16, ) +VFP_CONV_FIX(sl, s, 32, int32, ) +VFP_CONV_FIX(uh, s, 32, uint16, u) +VFP_CONV_FIX(ul, s, 32, uint32, u) #undef VFP_CONV_FIX /* Half precision conversions. */
target-arm/helpers.h +30 -30
66 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 5 lines · Peter Maydell
Correct the argument and return types for the float<->int conversion helper functions so that integer arguments and return values are declared as uint32_t/uint64_t, not float32/float64. This allows us to remove the hand-rolled functions which were doing bitwise copies between the types via unions.
I like the direction this patch goes; you aren't by any chance going to convert the passing/returning of float* to their appropriate int* types too, are you?
-Nathan
Quoted 8 lines · Nathan Froyd
Quoted 3 lines · Peter Maydell
Correct the argument and return types for the float<->int conversion helper functions so that integer arguments and return values are declared as uint32_t/uint64_t, not float32/float64.
I like the direction this patch goes; you aren't by any chance going to convert the passing/returning of float* to their appropriate int* types too, are you?
Nope -- I think that where we're passing or returning an actual IEEE single/double to a helper function "float*" is a better type than uint32_t: it gives information about what the helper's argument semantically is, and it means we don't have every helper that takes or returns a float have to include ugly calls to the boxing/unboxing macros.
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Nathan Froyd
I like the direction this patch goes; you aren't by any chance going to convert the passing/returning of float* to their appropriate int* types too, are you?
Nope -- I think that where we're passing or returning an actual IEEE single/double to a helper function "float*" is a better type than
uint32_t: it gives information about what the helper's argument semantically is, and it means we don't have every helper that takes or returns a float have to include ugly calls to the boxing/unboxing macros.
I'm just concerned about what would happen if we turned on softfloat's "float types are structure types" bit; I'm pretty sure everything would break horribly on targets that don't pass small structures in registers. Admittedly, several targets would be broken by doing so, so it's not particularly urgent.
-Nathan
Quoted 5 lines · Nathan Froyd
I'm just concerned about what would happen if we turned on softfloat's "float types are structure types" bit; I'm pretty sure everything would break horribly on targets that don't pass small structures in registers. Admittedly, several targets would be broken by doing so, so it's not particularly urgent.
Last time I turned that flag on half the targets didn't compile :-) I view it as more of a debugging aid and wouldn't expect anybody to ever actually run with it enabled.
-- PMM