aboutsummaryrefslogtreecommitdiff
path: root/fpu/softfloat.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2023-05-27 07:19:07 -0700
committerRichard Henderson <richard.henderson@linaro.org>2023-07-01 08:26:54 +0200
commite2041f4d5de01cb03b52908d36e9602b8c4a2479 (patch)
tree400f8bcf2d1326b8099154fbc07c8dccfea360c6 /fpu/softfloat.c
parente665cf72fe6357945fdbecf747dac58c0c7c7c66 (diff)
downloadqemu-e2041f4d5de01cb03b52908d36e9602b8c4a2479.zip
qemu-e2041f4d5de01cb03b52908d36e9602b8c4a2479.tar.gz
qemu-e2041f4d5de01cb03b52908d36e9602b8c4a2479.tar.bz2
fpu: Add float64_to_int{32,64}_modulo
Add versions of float64_to_int* which do not saturate the result. Reviewed-by: Christoph Muellner <christoph.muellner@vrull.eu> Tested-by: Christoph Muellner <christoph.muellner@vrull.eu> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20230527141910.1885950-2-richard.henderson@linaro.org>
Diffstat (limited to 'fpu/softfloat.c')
-rw-r--r--fpu/softfloat.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 42e6c18..0cc130a 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -852,11 +852,24 @@ static uint64_t parts128_float_to_uint(FloatParts128 *p, FloatRoundMode rmode,
#define parts_float_to_uint(P, R, Z, M, S) \
PARTS_GENERIC_64_128(float_to_uint, P)(P, R, Z, M, S)
+static int64_t parts64_float_to_sint_modulo(FloatParts64 *p,
+ FloatRoundMode rmode,
+ int bitsm1, float_status *s);
+static int64_t parts128_float_to_sint_modulo(FloatParts128 *p,
+ FloatRoundMode rmode,
+ int bitsm1, float_status *s);
+
+#define parts_float_to_sint_modulo(P, R, M, S) \
+ PARTS_GENERIC_64_128(float_to_sint_modulo, P)(P, R, M, S)
+
static void parts64_sint_to_float(FloatParts64 *p, int64_t a,
int scale, float_status *s);
static void parts128_sint_to_float(FloatParts128 *p, int64_t a,
int scale, float_status *s);
+#define parts_float_to_sint(P, R, Z, MN, MX, S) \
+ PARTS_GENERIC_64_128(float_to_sint, P)(P, R, Z, MN, MX, S)
+
#define parts_sint_to_float(P, I, Z, S) \
PARTS_GENERIC_64_128(sint_to_float, P)(P, I, Z, S)
@@ -3409,6 +3422,24 @@ int64_t bfloat16_to_int64_round_to_zero(bfloat16 a, float_status *s)
return bfloat16_to_int64_scalbn(a, float_round_to_zero, 0, s);
}
+int32_t float64_to_int32_modulo(float64 a, FloatRoundMode rmode,
+ float_status *s)
+{
+ FloatParts64 p;
+
+ float64_unpack_canonical(&p, a, s);
+ return parts_float_to_sint_modulo(&p, rmode, 31, s);
+}
+
+int64_t float64_to_int64_modulo(float64 a, FloatRoundMode rmode,
+ float_status *s)
+{
+ FloatParts64 p;
+
+ float64_unpack_canonical(&p, a, s);
+ return parts_float_to_sint_modulo(&p, rmode, 63, s);
+}
+
/*
* Floating-point to unsigned integer conversions
*/