Silly question, but is there an x86 instruction set emulator written in JavaScript? Not even Linux, just something that takes x86 instructions into a "virtual CPU" and lets you run the assembly statements?
Not a silly question at all. I would also like to know this. Would be a fun way to play around with assembly without the need of a tool chain etc. Maybe even on your phone while on the train. If this doesn't exist already, I'd be happy to start working on something like this.
So, how do you do 64-bit arithmetic in JavaScript? Emulate with two 32-bit number? Won't that be a huge performance bottleneck, one that cannot be optimized by JIT?
Yes, you emulate them with 32-bit numbers. It is a huge performance bottleneck if you do it naively, which most compile-to-JS languages that support 64-bit integers do. Emscripten even has a flag to let you choose between correct-but-slow 64-bit integers and fast-but-incorrect (drops to 53 bits).
It is possible to get fast longs in JS, though, if you push your optimizer far enough. This is what we have done in Scala.js. I wrote a paper about this, but it is still under submission so I cannot disclose it just yet. However, I can point to the implementation:
> js-ctypes is only available from chrome code; that is, ctypes is not available to websites, only application and extension code.
Basically `js-ctypes` won't work in an actual browser. So you cannot use it. There are other Node.js-specific native packages that give a representation for 64-bit integers, but not arithmetic operations. Besides, even if they had arithmetic operations, they would be heap-allocated, and since the JIT cannot understand them, it would not be able to optimize them as well as what we built for Scala.js.