qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 04/19] host-utils: add 128-bit quotient support to divu128


From: Richard Henderson
Subject: Re: [PATCH v2 04/19] host-utils: add 128-bit quotient support to divu128/divs128
Date: Fri, 3 Sep 2021 23:09:22 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 9/2/21 11:07 PM, Luis Fernando Fujita Pires wrote:
From: Richard Henderson <richard.henderson@linaro.org>
Hmm.  I'll note that we have a better divmod primitive in tree, but we aren't
using it
here: udiv_qrnnd in include/fpu/softfloat-macros.h.

Good to know! I'll change to a (much simpler) implementation using udiv_qrnnd.
Any pointers on what would be a good place to put udiv_qrnnd, so it can be used 
by softloat.c and host-utils.c? Would host-utils.h be ok?

Yeah, that should be fine.

Note that udiv_qrnnd requires that the divisor be normalization, i.e. the msb of the denominator must be set. So:

    int sh = clz64(den);
    uint64_t q, r;

    q = udiv_qrnnd(&r, num_hi, num_lo, den << sh);
    q <<= sh;
    r >>= sh;

IIRC. You'll probably want to have a look at gmp source, from which this comes for best practice in implementing a larger division.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]