Search code examples
javascriptnode.jscpuv8

undefined >>> 0 == 4294967295?


Getting different results on different machines and wonder if this is expected behaviour or a potential error in implementation of '>>>' operation for certain CPUs?

Linux qemux86-64 4.18.41-yocto-standard #1 SMP PREEMPT Tue Oct 8 20:33:31 UTC 2019 x86_64 GNU/Linux
root@qemux86-64:~# node --v8-options|head -n 1
SSE3=1 SSSE3=1 SSE4_1=0 SAHF=1 AVX=0 FMA3=0 BMI1=0 BMI2=0 LZCNT=0 POPCNT=0 ATOM=0
root@qemux86-64:~# node -v             
v8.12.0
root@qemux86-64:~# node -e 'console.log(undefined >>> 0)'
4294967295

(undefined >>> 0) evaluates to 0 on other machines I tested. But, then with CPU features enabled: AVX FMA3 BMI1 BMI2 LZCNT POPCNT


Solution

  • V8 developer here. That's clearly a bug (undefined >>> 0 is always supposed to return 0), but it's unclear where that bug might be: could be in V8, could be in the C++ compiler that was used, could be in kernel or system libraries, could even be in the hardware (or emulator? The host name "qemux86-64" sounds like it might be a virtual machine); could also be less of a bug per se and more of an unexpected interaction between any of these components. FWIW, I can't repro.

    Node 8 is also fairly old, so the first thing to try would be a newer Node/V8. Maybe whatever it was has been fixed already.

    If you can still reproduce with a recent version (say, Node 12 / V8 7.7 or newer), then please file a bug at crbug.com/v8/new and include instructions on how to reproduce. Feel free to leave the bug number in a comment here.