On 30.12.2025 14:50, Andrew Cooper wrote:
> --- a/xen/common/bitops.c
> +++ b/xen/common/bitops.c
> @@ -247,3 +247,15 @@ static void __init __constructor test_bitops(void)
>      test_multiple_bits_set();
>      test_hweight();
>  }
> +
> +#include <xen/muldiv.h>
> +
> +/* Not a bitop, but here in lieu of any any better location */
> +static void __init __constructor test_muldiv64(void)
> +{
> +    uint64_t res = muldiv64(0xffffffffffffffffULL,
> +                            HIDE(0xffffffffU),
> +                            HIDE(0xffffffffU));
> +    if ( res != 0xffffffffffffffffULL )
> +        panic("muldiv64(), expecting -1ULL, got 0x%"PRIx64"\n", res);

Nit: Better %#"PRIX64".

> --- /dev/null
> +++ b/xen/include/xen/muldiv.h
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef XEN_MULDIV_H
> +#define XEN_MULDIV_H
> +
> +#include <xen/stdint.h>
> +
> +uint64_t attr_const generic_muldiv64(uint64_t a, uint32_t b, uint32_t c);
> +
> +/*
> + * Calculate a * b / c using at least 96-bit internal precision.  The
> + * behaviour is undefined if the end result does not fit in a uint64_t.
> + */
> +static inline uint64_t attr_const muldiv64(uint64_t a, uint32_t b, uint32_t 
> c)
> +{
> +    return generic_muldiv64(a, b, c);
> +}

As to the file name: Are you expecting any other forms to appear here? Else
why not make it muldiv64.h, matching the .c file's base name? I'm not going
to insist though, so even with just the earlier nit addressed:
Acked-by: Jan Beulich <[email protected]>

Jan

Reply via email to