Commit 20564352 authored by jjgarcia's avatar jjgarcia

ASH was bitten by a C feature: that numbers cannot be right shifted (>>) more...

ASH was bitten by a C feature: that numbers cannot be right shifted (>>) more than the number of bits they have. Otherwise the result is unspecified, and in intel bogus (due to the use of SAR).
parent f99b39e8
......@@ -439,12 +439,24 @@ ecl_ash(cl_object x, cl_fixnum w)
return(x);
y = big_register0_get();
if (w < 0) {
cl_index bits = -w;
if (FIXNUMP(x)) {
/* The result of shifting a number further than the number
* of digits it has is unpredictable in C. For instance, GCC
* on intel masks out all bits of "bits" beyond the 5 and
* it may happen that a shift of 37 becomes a shift of 5.
* Furthermore, in general, shifting negative numbers leads
* to implementation-specific results :-/
*/
cl_fixnum y = fix(x);
y >>= -w;
if (bits >= FIXNUM_BITS) {
y = (y < 0)? -1 : 0;
} else {
y >>= bits;
}
return MAKE_FIXNUM(y);
}
mpz_div_2exp(y->big.big_num, x->big.big_num, -w);
mpz_div_2exp(y->big.big_num, x->big.big_num, bits);
} else {
if (FIXNUMP(x)) {
mpz_set_si(y->big.big_num, fix(x));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment