haxe
haxe copied to clipboard
Unit test on high bit shifts
The following tests might give different results depending on platforms:
function shl( x, y ) return x << y;
shl(1,33); // can be 0 or 2, depending if native CPU opcode is used (which does &31 on shift value)
https://c9x.me/x86/html/file_module_x86_id_285.html
I think we should make it platform agnostic, but I'm curious to know if the issue is HL specific or if some other platforms are affected.
This gives me 2
an all targets (that I tested) except Eval.
Oh so OCaml is indeed doing something very specific regarding to bit shifting. This explains why the compiled version of 1 << 33 (using compiler optimisation) differs from 1 << 33 at runtime. I guess we should add a "land 31" to all bit shifts (both optimizer and eval) to match other targets.
This also fails on PHP and python.