haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Unit test on high bit shifts

Open ncannasse opened this issue 2 years ago • 3 comments

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.

ncannasse avatar Jul 13 '22 10:07 ncannasse

This gives me 2 an all targets (that I tested) except Eval.

Simn avatar Jul 13 '22 10:07 Simn

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.

ncannasse avatar Jul 13 '22 13:07 ncannasse

This also fails on PHP and python.

Simn avatar Aug 01 '22 10:08 Simn