diff options
author | Matheus Ferst <matheus.ferst@eldorado.org.br> | 2022-03-30 14:59:28 -0300 |
---|---|---|
committer | Daniel Henrique Barboza <danielhb413@gmail.com> | 2022-04-20 18:00:30 -0300 |
commit | 95c1b71e25a9bafb64e4dd69f8834716332a7542 (patch) | |
tree | 44f7528b5138571bb04355e378c0e352f1c3bacf /fpu | |
parent | f279852b89bd42289c421714221c860e71fb4639 (diff) | |
download | qemu-95c1b71e25a9bafb64e4dd69f8834716332a7542.zip qemu-95c1b71e25a9bafb64e4dd69f8834716332a7542.tar.gz qemu-95c1b71e25a9bafb64e4dd69f8834716332a7542.tar.bz2 |
softfloat: add int128_to_float128
Based on parts_sint_to_float, implements int128_to_float128 to convert a
signed 128-bit value received through an Int128 argument.
Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
Message-Id: <20220330175932.6995-5-matheus.ferst@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Diffstat (limited to 'fpu')
-rw-r--r-- | fpu/softfloat.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 57445b3..60b4702 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3780,6 +3780,35 @@ bfloat16 int16_to_bfloat16(int16_t a, float_status *status) return int64_to_bfloat16_scalbn(a, 0, status); } +float128 int128_to_float128(Int128 a, float_status *status) +{ + FloatParts128 p = { }; + int shift; + + if (int128_nz(a)) { + p.cls = float_class_normal; + if (!int128_nonneg(a)) { + p.sign = true; + a = int128_neg(a); + } + + shift = clz64(int128_gethi(a)); + if (shift == 64) { + shift += clz64(int128_getlo(a)); + } + + p.exp = 127 - shift; + a = int128_lshift(a, shift); + + p.frac_hi = int128_gethi(a); + p.frac_lo = int128_getlo(a); + } else { + p.cls = float_class_zero; + } + + return float128_round_pack_canonical(&p, status); +} + float128 int64_to_float128(int64_t a, float_status *status) { FloatParts128 p; |