diff --git a/moo/kernel/test-001.moo b/moo/kernel/test-001.moo index 25f7fd6..419b1f7 100644 --- a/moo/kernel/test-001.moo +++ b/moo/kernel/test-001.moo @@ -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 ], ## ========================= diff --git a/moo/lib/bigint.c b/moo/lib/bigint.c index 887c193..485b3f0 100644 --- a/moo/lib/bigint.c +++ b/moo/lib/bigint.c @@ -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])) { diff --git a/moo/mod/ffi.c b/moo/mod/ffi.c index 2b64393..e5a44b8 100644 --- a/moo/mod/ffi.c +++ b/moo/mod/ffi.c @@ -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, " %p in %p\n", f, ffi->handle); + /*MOO_DEBUG2 (moo, " %p in %p\n", f, ffi->handle);*/ dcMode (ffi->dc, DC_CALL_C_DEFAULT); dcReset (ffi->dc);