FFI: Move code for cdata arithmetic to lj_carith.c.

This commit is contained in:
Mike Pall
2011-01-26 21:46:02 +01:00
parent 2526498c71
commit 3184f17169
11 changed files with 308 additions and 260 deletions

View File

@@ -251,38 +251,4 @@ void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual)
lj_cconv_ct_tv(cts, d, dp, o, 0);
}
/* -- 64 bit integer arithmetic helpers ----------------------------------- */
/* 64 bit integer x^k. */
uint64_t lj_cdata_powi64(uint64_t x, uint64_t k, int isunsigned)
{
uint64_t y = 0;
if (k == 0)
return 1;
if (!isunsigned) {
if ((int64_t)k < 0) {
if (x == 0)
return U64x(7fffffff,ffffffff);
else if (x == 1)
return 1;
else if ((int64_t)x == -1)
return (k & 1) ? -1 : 1;
else
return 0;
}
}
for (; (k & 1) == 0; k >>= 1) x *= x;
y = x;
if ((k >>= 1) != 0) {
for (;;) {
x *= x;
if (k == 1) break;
if (k & 1) y *= x;
k >>= 1;
}
y *= x;
}
return y;
}
#endif