fixing divide_unsigned_array2()

This commit is contained in:
hyunghwan.chung 2019-04-08 01:18:00 +00:00
parent 90d665781c
commit 55b18c998c
3 changed files with 27 additions and 28 deletions

View File

@ -383,6 +383,7 @@ extend MyObject
[ self testBigintDiv: 16r000000030000000000008000 divisor: 16r000000010000000000002000 count: 2000 ],
[ self testBigintDiv: 16rfffffffe0000000080000000 divisor: 16r0000ffff0000000080000000 count: 12345 ],
[ self testBigintDiv: 16rfffffffffffffffe divisor: 16rffffffff count: 2000 ],
[ self testBigintDiv: 68651967526299315528548877601614136727014 divisor: 1729382256910270380 count: 1 ],
## =========================

View File

@ -1849,8 +1849,8 @@ static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs
for (i = xs; i >= ys; --i)
{
moo_lidw_t dw;
moo_liw_t quo, b, xhi, xlo, rem;
moo_lidw_t dw, quo, rem;
moo_liw_t b, xhi, xlo;
/* ---------------------------------------------------------- */
/* estimate the quotient.
@ -1859,38 +1859,36 @@ static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs
xhi = q[i];
xlo = q[i - 1];
/*
if (xhi == y1)
{
quo = MOO_TYPE_MAX(moo_liw_t);
rem = 0;
}
else
{
*/
dw = ((moo_lidw_t)xhi << MOO_LIW_BITS) + xlo;
/* TODO: optimize it with ASM - no seperate / and % */
quo = (moo_liw_t)(dw / y1);
//q[i] = (moo_liw_t)(dw % y1);
rem = (moo_liw_t)(dw % y1);
MOO_ASSERT (moo, (dw / y1) == quo);
/*
}*/
/* adjust the quotient if over-estimated */
#if 0
dw = (moo_lidw_t)rem;
#if 1
dw = ((moo_lidw_t)xhi << MOO_LIW_BITS) + xlo;
/* TODO: optimize it with ASM - no seperate / and % */
quo = dw / y1;
rem = dw % y1;
/*rem = dw - (quo * y1);*/
adjust_quotient:
if (quo > MOO_TYPE_MAX(moo_liw_t) || ((moo_lidw_t)quo * y2) > ((dw << MOO_LIW_BITS) + q[i - 2]))
if (quo > MOO_TYPE_MAX(moo_liw_t) || (quo * y2) > ((rem << MOO_LIW_BITS) + q[i - 2]))
{
--quo;
dw += y1;
if (dw <= MOO_TYPE_MAX(moo_liw_t)) goto adjust_quotient;
rem += y1;
if (rem <= MOO_TYPE_MAX(moo_liw_t)) goto adjust_quotient;
}
#else
/*if (xhi == y1)
{
quo = MOO_TYPE_MAX(moo_liw_t);
rem = q[i];
}
else
{ */
dw = ((moo_lidw_t)xhi << MOO_LIW_BITS) + xlo;
/* TODO: optimize it with ASM - no seperate / and % */
quo = dw / y1;
//q[i] = (moo_liw_t)(dw % y1);
rem = dw % y1;
/*}*/
adjust_quotient:
dw = ((moo_lidw_t)quo * y2);
dw = quo * y2;
b = (moo_liw_t)(dw >> MOO_LIW_BITS);
if (b > rem || (b == rem && (moo_liw_t)dw > q[i - 2]))
{

View File

@ -199,7 +199,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
f = MOO_OOP_TO_SMPTR(fun);
arr = (moo_oop_oop_t)args;
MOO_DEBUG2 (moo, "<ffi.call> %p in %p\n", f, ffi->handle);
/*MOO_DEBUG2 (moo, "<ffi.call> %p in %p\n", f, ffi->handle);*/
dcMode (ffi->dc, DC_CALL_C_DEFAULT);
dcReset (ffi->dc);