target/arm: Improve arm_rmode_to_sf
Use proper enumeration types for input and output. Use a const array to perform the mapping, with an assert that the input is valid. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
ab9ced73fa
commit
6ce21abd40
|
@ -193,16 +193,22 @@ void arm_restore_state_to_opc(CPUState *cs,
|
||||||
void arm_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb);
|
void arm_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb);
|
||||||
#endif /* CONFIG_TCG */
|
#endif /* CONFIG_TCG */
|
||||||
|
|
||||||
enum arm_fprounding {
|
typedef enum ARMFPRounding {
|
||||||
FPROUNDING_TIEEVEN,
|
FPROUNDING_TIEEVEN,
|
||||||
FPROUNDING_POSINF,
|
FPROUNDING_POSINF,
|
||||||
FPROUNDING_NEGINF,
|
FPROUNDING_NEGINF,
|
||||||
FPROUNDING_ZERO,
|
FPROUNDING_ZERO,
|
||||||
FPROUNDING_TIEAWAY,
|
FPROUNDING_TIEAWAY,
|
||||||
FPROUNDING_ODD
|
FPROUNDING_ODD
|
||||||
};
|
} ARMFPRounding;
|
||||||
|
|
||||||
int arm_rmode_to_sf(int rmode);
|
extern const FloatRoundMode arm_rmode_to_sf_map[6];
|
||||||
|
|
||||||
|
static inline FloatRoundMode arm_rmode_to_sf(ARMFPRounding rmode)
|
||||||
|
{
|
||||||
|
assert((unsigned)rmode < ARRAY_SIZE(arm_rmode_to_sf_map));
|
||||||
|
return arm_rmode_to_sf_map[rmode];
|
||||||
|
}
|
||||||
|
|
||||||
static inline void aarch64_save_sp(CPUARMState *env, int el)
|
static inline void aarch64_save_sp(CPUARMState *env, int el)
|
||||||
{
|
{
|
||||||
|
|
|
@ -588,7 +588,7 @@ DO_VCVT(VCVT_FS, vcvt_hs, vcvt_fs)
|
||||||
DO_VCVT(VCVT_FU, vcvt_hu, vcvt_fu)
|
DO_VCVT(VCVT_FU, vcvt_hu, vcvt_fu)
|
||||||
|
|
||||||
static bool do_vcvt_rmode(DisasContext *s, arg_1op *a,
|
static bool do_vcvt_rmode(DisasContext *s, arg_1op *a,
|
||||||
enum arm_fprounding rmode, bool u)
|
ARMFPRounding rmode, bool u)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Handle VCVT fp to int with specified rounding mode.
|
* Handle VCVT fp to int with specified rounding mode.
|
||||||
|
|
|
@ -1104,31 +1104,14 @@ float64 HELPER(rintd)(float64 x, void *fp_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert ARM rounding mode to softfloat */
|
/* Convert ARM rounding mode to softfloat */
|
||||||
int arm_rmode_to_sf(int rmode)
|
const FloatRoundMode arm_rmode_to_sf_map[] = {
|
||||||
{
|
[FPROUNDING_TIEEVEN] = float_round_nearest_even,
|
||||||
switch (rmode) {
|
[FPROUNDING_POSINF] = float_round_up,
|
||||||
case FPROUNDING_TIEAWAY:
|
[FPROUNDING_NEGINF] = float_round_down,
|
||||||
rmode = float_round_ties_away;
|
[FPROUNDING_ZERO] = float_round_to_zero,
|
||||||
break;
|
[FPROUNDING_TIEAWAY] = float_round_ties_away,
|
||||||
case FPROUNDING_ODD:
|
[FPROUNDING_ODD] = float_round_to_odd,
|
||||||
rmode = float_round_to_odd;
|
};
|
||||||
break;
|
|
||||||
case FPROUNDING_TIEEVEN:
|
|
||||||
default:
|
|
||||||
rmode = float_round_nearest_even;
|
|
||||||
break;
|
|
||||||
case FPROUNDING_POSINF:
|
|
||||||
rmode = float_round_up;
|
|
||||||
break;
|
|
||||||
case FPROUNDING_NEGINF:
|
|
||||||
rmode = float_round_down;
|
|
||||||
break;
|
|
||||||
case FPROUNDING_ZERO:
|
|
||||||
rmode = float_round_to_zero;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return rmode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Implement float64 to int32_t conversion without saturation;
|
* Implement float64 to int32_t conversion without saturation;
|
||||||
|
|
Loading…
Reference in New Issue