[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 02/19] host-utils: move abs64() to host-utils
From: |
David Gibson |
Subject: |
Re: [PATCH 02/19] host-utils: move abs64() to host-utils |
Date: |
Wed, 25 Aug 2021 13:43:10 +1000 |
On Tue, Aug 24, 2021 at 11:27:13AM -0300, Luis Pires wrote:
> Move abs64 to host-utils so it can be reused elsewhere.
> Also made it inline.
>
> Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
> ---
> hw/i386/kvm/i8254.c | 5 -----
> include/qemu/host-utils.h | 8 ++++++++
> 2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c
> index fa68669e8a..761034743b 100644
> --- a/hw/i386/kvm/i8254.c
> +++ b/hw/i386/kvm/i8254.c
> @@ -59,11 +59,6 @@ struct KVMPITClass {
> DeviceRealize parent_realize;
> };
>
> -static int64_t abs64(int64_t v)
> -{
> - return v < 0 ? -v : v;
Hrm.. I'm a bit concerned about mkaing this a more widespread
function, because it has a nasty edge case... which is basically
unavoidable in an abs64() implementation. Specifically:
abs64(0x800_0000_0000_00000) == 0x800_0000_0000_0000 < 0
At least in the most likely 2's complement implementation.
> -}
> -
> static void kvm_pit_update_clock_offset(KVMPITState *s)
> {
> int64_t offset, clock_offset;
> diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
> index 711b221704..5fec44a9c4 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
> + */
> +static inline int64_t abs64(int64_t v)
> +{
> + return v < 0 ? -v : v;
> +}
> +
> /**
> * sadd32_overflow - addition with overflow indication
> * @x, @y: addends
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature
- [PATCH 00/19] target/ppc: DFP instructions using decodetree, Luis Pires, 2021/08/24
- [PATCH 01/19] host-utils: Fix overflow detection in divu128(), Luis Pires, 2021/08/24
- [PATCH 02/19] host-utils: move abs64() to host-utils, Luis Pires, 2021/08/24
- Re: [PATCH 02/19] host-utils: move abs64() to host-utils,
David Gibson <=
- RE: [PATCH 02/19] host-utils: move abs64() to host-utils, Luis Fernando Fujita Pires, 2021/08/25
- Re: [PATCH 02/19] host-utils: move abs64() to host-utils, Eduardo Habkost, 2021/08/25
- RE: [PATCH 02/19] host-utils: move abs64() to host-utils, Luis Fernando Fujita Pires, 2021/08/25
- Re: [PATCH 02/19] host-utils: move abs64() to host-utils, Eduardo Habkost, 2021/08/25
- Re: [PATCH 02/19] host-utils: move abs64() to host-utils, Philippe Mathieu-Daudé, 2021/08/25
- RE: [PATCH 02/19] host-utils: move abs64() to host-utils, Luis Fernando Fujita Pires, 2021/08/27
[PATCH 03/19] host-utils: move checks out of divu128/divs128, Luis Pires, 2021/08/24
[PATCH 04/19] host-utils: add 128-bit quotient support to divu128/divs128, Luis Pires, 2021/08/24
[PATCH 05/19] host-utils: add unit tests for divu128/divs128, Luis Pires, 2021/08/24
[PATCH 06/19] libdecnumber: introduce decNumberFrom[U]Int128, Luis Pires, 2021/08/24