[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 05/19] libdecnumber: introduce decNumberFrom[U]Int128
From: |
Luis Pires |
Subject: |
[PATCH v4 05/19] libdecnumber: introduce decNumberFrom[U]Int128 |
Date: |
Mon, 25 Oct 2021 16:11:40 -0300 |
This will be used to implement PowerPC's dcffixqq.
Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
include/libdecnumber/decNumber.h | 2 ++
libdecnumber/decNumber.c | 36 ++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/include/libdecnumber/decNumber.h b/include/libdecnumber/decNumber.h
index aa115fed07..0cf69c7db2 100644
--- a/include/libdecnumber/decNumber.h
+++ b/include/libdecnumber/decNumber.h
@@ -116,6 +116,8 @@
decNumber * decNumberFromUInt32(decNumber *, uint32_t);
decNumber *decNumberFromInt64(decNumber *, int64_t);
decNumber *decNumberFromUInt64(decNumber *, uint64_t);
+ decNumber *decNumberFromInt128(decNumber *, uint64_t, int64_t);
+ decNumber *decNumberFromUInt128(decNumber *, uint64_t, uint64_t);
decNumber * decNumberFromString(decNumber *, const char *, decContext *);
char * decNumberToString(const decNumber *, char *);
char * decNumberToEngString(const decNumber *, char *);
diff --git a/libdecnumber/decNumber.c b/libdecnumber/decNumber.c
index 1ffe458ad8..d7716ce175 100644
--- a/libdecnumber/decNumber.c
+++ b/libdecnumber/decNumber.c
@@ -167,6 +167,7 @@
/* ------------------------------------------------------------------ */
#include "qemu/osdep.h"
+#include "qemu/host-utils.h"
#include "libdecnumber/dconfig.h"
#include "libdecnumber/decNumber.h"
#include "libdecnumber/decNumberLocal.h"
@@ -462,6 +463,41 @@ decNumber *decNumberFromUInt64(decNumber *dn, uint64_t uin)
return dn;
} /* decNumberFromUInt64 */
+decNumber *decNumberFromInt128(decNumber *dn, uint64_t lo, int64_t hi)
+{
+ uint64_t unsig_hi = hi;
+ if (hi < 0) {
+ if (lo == 0) {
+ unsig_hi = -unsig_hi;
+ } else {
+ unsig_hi = ~unsig_hi;
+ lo = -lo;
+ }
+ }
+
+ decNumberFromUInt128(dn, lo, unsig_hi);
+ if (hi < 0) {
+ dn->bits = DECNEG; /* sign needed */
+ }
+ return dn;
+} /* decNumberFromInt128 */
+
+decNumber *decNumberFromUInt128(decNumber *dn, uint64_t lo, uint64_t hi)
+{
+ uint64_t rem;
+ Unit *up; /* work pointer */
+ decNumberZero(dn); /* clean */
+ if (lo == 0 && hi == 0) {
+ return dn; /* [or decGetDigits bad call] */
+ }
+ for (up = dn->lsu; hi > 0 || lo > 0; up++) {
+ rem = divu128(&lo, &hi, DECDPUNMAX + 1);
+ *up = (Unit)rem;
+ }
+ dn->digits = decGetDigits(dn->lsu, up - dn->lsu);
+ return dn;
+} /* decNumberFromUInt128 */
+
/* ------------------------------------------------------------------ */
/* to-int64 -- conversion to int64 */
/* */
--
2.25.1
- [PATCH v4 00/19] target/ppc: DFP instructions using decodetree, Luis Pires, 2021/10/25
- [PATCH v4 01/19] host-utils: move checks out of divu128/divs128, Luis Pires, 2021/10/25
- [PATCH v4 02/19] host-utils: move udiv_qrnnd() to host-utils, Luis Pires, 2021/10/25
- [PATCH v4 03/19] host-utils: add 128-bit quotient support to divu128/divs128, Luis Pires, 2021/10/25
- [PATCH v4 04/19] host-utils: add unit tests for divu128/divs128, Luis Pires, 2021/10/25
- [PATCH v4 05/19] libdecnumber: introduce decNumberFrom[U]Int128,
Luis Pires <=
- [PATCH v4 06/19] target/ppc: Move REQUIRE_ALTIVEC/VECTOR to translate.c, Luis Pires, 2021/10/25
- [PATCH v4 07/19] target/ppc: Introduce REQUIRE_FPU, Luis Pires, 2021/10/25
- [PATCH v4 08/19] target/ppc: Implement DCFFIXQQ, Luis Pires, 2021/10/25
- [PATCH v4 09/19] host-utils: Introduce mulu128, Luis Pires, 2021/10/25
- [PATCH v4 10/19] libdecnumber: Introduce decNumberIntegralToInt128, Luis Pires, 2021/10/25
- [PATCH v4 11/19] target/ppc: Implement DCTFIXQQ, Luis Pires, 2021/10/25
- [PATCH v4 12/19] target/ppc: Do not update nip on DFP instructions, Luis Pires, 2021/10/25
- [PATCH v4 13/19] target/ppc: Move dtstdc[q]/dtstdg[q] to decodetree, Luis Pires, 2021/10/25
- [PATCH v4 14/19] target/ppc: Move d{add, sub, mul, div, iex}[q] to decodetree, Luis Pires, 2021/10/25
- [PATCH v4 15/19] target/ppc: Move dcmp{u, o}[q], dts{tex, tsf, tsfi}[q] to decodetree, Luis Pires, 2021/10/25