Skip to content

Commit 4df7856

Browse files
committed
Make the frnd function round according to the C 'round' spec
I don't know if this is correct as I don't have access to the ARC V3 specification, but if GCC is correct and QEMU is wrong, then the fdrnd (and fsrnd) functions are supposed to round with ties rounding away from zero, just like the C round and roundf functions. Signed-off-by: Keith Packard <[email protected]>
1 parent 76e0fa9 commit 4df7856

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

target/arc/fpu-helper-v3.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,35 @@ CONVERSION_HELPERS(fuint2s, uint32_to_float32)
173173
CONVERSION_HELPERS(fs2uint, float32_to_uint32)
174174
CONVERSION_HELPERS(fs2uint_rz, float32_to_uint32_round_to_zero)
175175

176-
CONVERSION_HELPERS(fdrnd, float64_round_to_int)
177-
CONVERSION_HELPERS(fsrnd, float32_round_to_int)
178-
179176
CONVERSION_HELPERS(fdsqrt, float64_sqrt)
180177
CONVERSION_HELPERS(fssqrt, float32_sqrt)
181178
CONVERSION_HELPERS(fhsqrt, float16_sqrt)
182179

180+
/* Soft fpu helper for round_to_int with rounding away mode */
181+
#define CONVERSION_HELPERS_RA(NAME, FLT_HELPER) \
182+
uint64_t helper_##NAME(CPUARCState *env, uint64_t src) \
183+
{ \
184+
FloatRoundMode saved_rounding_mode; \
185+
bool saved_flush_zero; \
186+
\
187+
saved_flush_zero = get_flush_to_zero(&env->fp_status); \
188+
saved_rounding_mode = get_float_rounding_mode(&env->fp_status); \
189+
\
190+
set_flush_to_zero(true, &env->fp_status); \
191+
set_float_rounding_mode(float_round_ties_away, &env->fp_status); \
192+
\
193+
uint64_t ret = FLT_HELPER(src, &env->fp_status); \
194+
\
195+
set_flush_to_zero(saved_flush_zero, &env->fp_status); \
196+
set_float_rounding_mode(saved_rounding_mode, &env->fp_status); \
197+
\
198+
check_fpu_raise_exception(env); \
199+
return ret; \
200+
}
201+
202+
CONVERSION_HELPERS_RA(fdrnd, float64_round_to_int)
203+
CONVERSION_HELPERS_RA(fsrnd, float32_round_to_int)
204+
183205
/* Soft fpu helper for round_to_int with rounding to zero mode */
184206
#define CONVERSION_HELPERS_RZ(NAME, FLT_HELPER) \
185207
uint64_t helper_##NAME(CPUARCState *env, uint64_t src) \

0 commit comments

Comments
 (0)