[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/22] host-utils: introduce uabs64()
From: |
Luis Pires |
Subject: |
[PATCH v3 03/22] host-utils: introduce uabs64() |
Date: |
Fri, 10 Sep 2021 08:26:05 -0300 |
Introduce uabs64(), a function that returns the absolute value of
a 64-bit int as an unsigned value. This avoids the undefined behavior
for common abs implementations, where abs of the most negative value is
undefined.
Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/qemu/host-utils.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 753b9fb89f..ca9f3f021b 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -357,6 +357,14 @@ static inline uint64_t revbit64(uint64_t x)
#endif
}
+/**
+ * Return the absolute value of a 64-bit integer as an unsigned 64-bit value
+ */
+static inline uint64_t uabs64(int64_t v)
+{
+ return v < 0 ? -v : v;
+}
+
/**
* sadd32_overflow - addition with overflow indication
* @x, @y: addends
--
2.25.1
- [PATCH v3 00/22] target/ppc: DFP instructions using decodetree, Luis Pires, 2021/09/10
- [PATCH v3 01/22] host-utils: Fix overflow detection in divu128(), Luis Pires, 2021/09/10
- [PATCH v3 02/22] host-utils: fix missing zero-extension in divs128, Luis Pires, 2021/09/10
- [PATCH v3 03/22] host-utils: introduce uabs64(),
Luis Pires <=
- [PATCH v3 04/22] i386/kvm: Replace abs64() with uabs64() from host-utils, Luis Pires, 2021/09/10
- [PATCH v3 05/22] host-utils: move checks out of divu128/divs128, Luis Pires, 2021/09/10
- [PATCH v3 06/22] host-utils: move udiv_qrnnd() to host-utils, Luis Pires, 2021/09/10
- [PATCH v3 07/22] host-utils: add 128-bit quotient support to divu128/divs128, Luis Pires, 2021/09/10
- [PATCH v3 08/22] host-utils: add unit tests for divu128/divs128, Luis Pires, 2021/09/10
- [PATCH v3 09/22] libdecnumber: introduce decNumberFrom[U]Int128, Luis Pires, 2021/09/10
- [PATCH v3 10/22] target/ppc: Move REQUIRE_ALTIVEC/VECTOR to translate.c, Luis Pires, 2021/09/10
- [PATCH v3 11/22] target/ppc: Introduce REQUIRE_FPU, Luis Pires, 2021/09/10
- [PATCH v3 12/22] target/ppc: Implement DCFFIXQQ, Luis Pires, 2021/09/10
- [PATCH v3 13/22] host-utils: Introduce mulu128, Luis Pires, 2021/09/10