[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 17/19] fpu/softfloat: re-factor scalbn
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v1 17/19] fpu/softfloat: re-factor scalbn |
Date: |
Mon, 11 Dec 2017 12:57:03 +0000 |
This is one of the simpler manipulations you could make to a floating
point number.
Signed-off-by: Alex Bennée <address@hidden>
---
fpu/softfloat.c | 104 +++++++++++++++---------------------------------
include/fpu/softfloat.h | 1 +
2 files changed, 32 insertions(+), 73 deletions(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 1a7f1cab10..b7ea56dfa5 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -1662,6 +1662,37 @@ float64 uint16_to_float64(uint16_t a, float_status
*status)
return uint64_to_float64((uint64_t) a, status);
}
+/* Multiply A by 2 raised to the power N. */
+static decomposed_parts scalbn_decomposed(decomposed_parts a, int n,
+ float_status *s)
+{
+ if (a.cls == float_class_normal) {
+ a.exp += n;
+ }
+ return a;
+}
+
+float16 float16_scalbn(float16 a, int n, float_status *status)
+{
+ decomposed_parts pa = float16_unpack_canonical(a, status);
+ decomposed_parts pr = scalbn_decomposed(pa, n, status);
+ return float16_round_pack_canonical(pr, status);
+}
+
+float32 float32_scalbn(float32 a, int n, float_status *status)
+{
+ decomposed_parts pa = float32_unpack_canonical(a, status);
+ decomposed_parts pr = scalbn_decomposed(pa, n, status);
+ return float32_round_pack_canonical(pr, status);
+}
+
+float64 float64_scalbn(float64 a, int n, float_status *status)
+{
+ decomposed_parts pa = float64_unpack_canonical(a, status);
+ decomposed_parts pr = scalbn_decomposed(pa, n, status);
+ return float64_round_pack_canonical(pr, status);
+}
+
/*----------------------------------------------------------------------------
| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6
| and 7, and returns the properly rounded 32-bit integer corresponding to the
@@ -6991,79 +7022,6 @@ MINMAX(32)
MINMAX(64)
-/* Multiply A by 2 raised to the power N. */
-float32 float32_scalbn(float32 a, int n, float_status *status)
-{
- flag aSign;
- int16_t aExp;
- uint32_t aSig;
-
- a = float32_squash_input_denormal(a, status);
- aSig = extractFloat32Frac( a );
- aExp = extractFloat32Exp( a );
- aSign = extractFloat32Sign( a );
-
- if ( aExp == 0xFF ) {
- if ( aSig ) {
- return propagateFloat32NaN(a, a, status);
- }
- return a;
- }
- if (aExp != 0) {
- aSig |= 0x00800000;
- } else if (aSig == 0) {
- return a;
- } else {
- aExp++;
- }
-
- if (n > 0x200) {
- n = 0x200;
- } else if (n < -0x200) {
- n = -0x200;
- }
-
- aExp += n - 1;
- aSig <<= 7;
- return normalizeRoundAndPackFloat32(aSign, aExp, aSig, status);
-}
-
-float64 float64_scalbn(float64 a, int n, float_status *status)
-{
- flag aSign;
- int16_t aExp;
- uint64_t aSig;
-
- a = float64_squash_input_denormal(a, status);
- aSig = extractFloat64Frac( a );
- aExp = extractFloat64Exp( a );
- aSign = extractFloat64Sign( a );
-
- if ( aExp == 0x7FF ) {
- if ( aSig ) {
- return propagateFloat64NaN(a, a, status);
- }
- return a;
- }
- if (aExp != 0) {
- aSig |= LIT64( 0x0010000000000000 );
- } else if (aSig == 0) {
- return a;
- } else {
- aExp++;
- }
-
- if (n > 0x1000) {
- n = 0x1000;
- } else if (n < -0x1000) {
- n = -0x1000;
- }
-
- aExp += n - 1;
- aSig <<= 10;
- return normalizeRoundAndPackFloat64(aSign, aExp, aSig, status);
-}
-
floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status)
{
flag aSign;
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 8ebde83251..c1224aab8c 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -353,6 +353,7 @@ float16 float16_sub(float16, float16, float_status *status);
float16 float16_mul(float16, float16, float_status *status);
float16 float16_muladd(float16, float16, float16, int, float_status *status);
float16 float16_div(float16, float16, float_status *status);
+float16 float16_scalbn(float16, int, float_status *status);
int float16_is_quiet_nan(float16, float_status *status);
int float16_is_signaling_nan(float16, float_status *status);
--
2.15.1
- [Qemu-devel] [PATCH v1 08/19] fpu/softfloat: move the extract functions to the top of the file, (continued)
- [Qemu-devel] [PATCH v1 08/19] fpu/softfloat: move the extract functions to the top of the file, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 07/19] fpu/softfloat: improve comments on ARM NaN propagation, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 09/19] fpu/softfloat: define decompose structures, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 14/19] fpu/softfloat: re-factor round_to_int, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 19/19] fpu/softfloat: re-factor compare, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 17/19] fpu/softfloat: re-factor scalbn,
Alex Bennée <=
- [Qemu-devel] [PATCH v1 10/19] fpu/softfloat: re-factor add/sub, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 13/19] fpu/softfloat: re-factor muladd, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 15/19] fpu/softfloat: re-factor float to int/uint, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 11/19] fpu/softfloat: re-factor mul, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 16/19] fpu/softfloat: re-factor int/uint to float, Alex Bennée, 2017/12/11