arithmetic: Truncate binary operations on based numbers

When the wordsize is small enough that we can operate with native
results, we should truncate according to the word size, not truncate
to 64 bits.

Fixes: #624

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2023-11-29 23:15:29 +01:00
parent 94d4f16ac8
commit aa1ba7c7d1

View file

@ -1210,12 +1210,17 @@ algebraic_p arithmetic::evaluate(id op,
// Perform conversion of integer values to the same base
integer_p xi = integer_p(object_p(x.Safe()));
integer_p yi = integer_p(object_p(y.Safe()));
if (xi->native() && yi->native())
uint ws = Settings.WordSize();
if (xi->native() && yi->native() && (!is_based(xt) || ws < 64))
{
ularge xv = xi->value<ularge>();
ularge yv = yi->value<ularge>();
if (ops.integer_ok(xt, yt, xv, yv))
{
if (is_based(xt))
xv &= (1UL << ws) - 1UL;
return rt.make<integer>(xt, xv);
}
}
}