The bignum refactoring for the front-end is pretty much complete and so far all unit tests pass. However, I think there is one feature missing from the bignum code. I would like to be able to do unsigned right shifts in addition to signed shifts.
If you have time, Marc, could you add an unsigned flag to the shift function, and perhaps have it assume signed shift by default? If you do, please make sure to pull the latest code from the repo.
Tomorrow I'll try the boostrap again and see how far we can get. Hopefully I won't have introduced too many bugs in the code I just modified! (fingers crossed).
- Maxime
Afficher les réponses par date
On 2011-02-17, at 5:06 PM, chevalma@iro.umontreal.ca wrote:
The bignum refactoring for the front-end is pretty much complete and so far all unit tests pass. However, I think there is one feature missing from the bignum code. I would like to be able to do unsigned right shifts in addition to signed shifts.
If you have time, Marc, could you add an unsigned flag to the shift function, and perhaps have it assume signed shift by default? If you do, please make sure to pull the latest code from the repo.
Tomorrow I'll try the boostrap again and see how far we can get. Hopefully I won't have introduced too many bugs in the code I just modified! (fingers crossed).
Unsigned right shift depends on the word size (the other "signed" shifts do not depend on the word size). In other words, if I use C constructs, ((unsigned int)-128) >> 3 is not equal to ((unsigned short)-128) >> 3.
If you need unsigned right shifts, use this:
function num_unsigned_shift_right(n, shift, width) { return num_shift(num_and(n, num_not(num_shift(-1,width))), -shift); }
for example
num_unsigned_shift_right(-128, 3, 8) => 16 num_unsigned_shift_right(-128, 3, 16) => 8176 num_unsigned_shift_right(-128, 3, 32) => 536870896
I assume you need this to do constant folding of JS's >>> operator. In that case, I believe width has to be set to 32.
Marc