On 9/2/21 11:07 PM, Luis Fernando Fujita Pires wrote:
From: Richard Henderson <richard.hender...@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~