added experimental code for faster number to string conversion

This commit is contained in:
hyunghwan.chung 2019-03-29 07:05:53 +00:00
parent 374d3682d2
commit 93f6847034
2 changed files with 73 additions and 6 deletions

View File

@ -1548,7 +1548,6 @@ static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs,
/* TODO: this function needs to be rewritten for performance improvement. /* TODO: this function needs to be rewritten for performance improvement.
* the binary long division is extremely slow for a big number */ * the binary long division is extremely slow for a big number */
#if 1
/* Perform binary long division. /* Perform binary long division.
* http://en.wikipedia.org/wiki/Division_algorithm * http://en.wikipedia.org/wiki/Division_algorithm
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
@ -1588,11 +1587,33 @@ static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs,
} }
} }
} }
#else
/* TODO: more efficient method */
#endif
} }
#if 0
static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* q, moo_liw_t* r)
{
moo_oow_t rsize, qsize;
/* estimate result sizes */
rsize = ys;
qsize = xs - ys + 1;
npos = xs - 1;
dpos = ys - 1;
for (j = qsize - 1; j >= 0; j--, npos--)
{
if (ndigs[npos] == ddigs[dpos]
else
carry = scarry = 0;
qdigs[j] = qest;
}
}
#endif
static moo_oop_t add_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y) static moo_oop_t add_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y)
{ {
moo_oow_t as, bs, zs; moo_oow_t as, bs, zs;
@ -4286,6 +4307,48 @@ moo_oop_t moo_absint (moo_t* moo, moo_oop_t x)
return x; return x;
} }
static moo_liw_t div_with_carry (moo_liw_t x, moo_liw_t y, moo_liw_t* r)
{
/* TODO: optimize it with ASM */
moo_liw_t q;
moo_lidw_t dd;
dd = ((moo_lidw_t)*r << MOO_LIW_BITS) + x;
q = dd / y;
*r = dd % y;
return q;
}
static get_last_digit (moo_t* moo, moo_liw_t* x, moo_oow_t xs, int base)
{
moo_oow_t i = xs;
moo_liw_t r = 0;
while (i > 0)
{
--i;
x[i] = div_with_carry(x[i], base, &r);
}
return r;
}
void test_last_digit (moo_t* moo)
{
moo_ooch_t x[] = { 'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4',
'F','F','9','9','1', '2','3','4' };
moo_oop_t q = moo_strtoint (moo, x, MOO_COUNTOF(x), 16);
moo_oop_t s = moo_inttostr (moo, q, 10);
MOO_DEBUG1 (moo, "[%O]\n", s);
}
moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix) moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix)
{ {
moo_ooi_t v = 0; moo_ooi_t v = 0;

View File

@ -272,6 +272,10 @@ int main (int argc, char* argv[])
signal (SIGTERM, SIG_IGN); signal (SIGTERM, SIG_IGN);
#endif #endif
/*
test_last_digit (moo);
exit (0);
*/
moo_catch_termreq (); moo_catch_termreq ();
moo_start_ticker (); moo_start_ticker ();