4 ms·
From what I understand, asm.js is using JavaScript as a kind of portable assembly language which means there is no VM.
by hansjorg 13y ago
From what I understand, asm.js is using JavaScript as a kind of portable assembly language which means there is no VM.
- haberman 13y agoNo VM? What do you call V8, SpiderMonkey, etc?
- wvenable 13y agoBrowsers are supposed to compile asm.js code directly into native code before running it. Running it through the VM is the fallback for browsers that don't support it directly.
- haberman 13y agoI can compile BF directly to native code (and actually I did: http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-jits.html http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-s...) so does that make BF native code? The point of these questions is that the GGP's statements are absurd. There is no universe in which asm.js is "native code".
- wvenable 13y agoTrue but I'm replying to a comment stream that describes asm.js code as "portable assembly language" which is a pretty reasonable description. It's certainly not native code since no CPU exists that can execute asm.js code directly.
- adamtj 13y agoNo, it's not technically native code, nor is it exactly assembly or bytecode. It an IR that browsers can JIT very easily. Which is basically the same thing. It's interesting to note that x86 and amd64 code isn't even truly "native". They're just bytecode IRs that are interpreted by a CISC virtual machine emulated in microcode running on a RISC cpu that you can't program directly. Everything is an IR. Python is an IR for the thoughts in my head. It's turtles all the way down.
- haberman 13y ago> No, it's not technically native code, nor is it exactly assembly or bytecode. It an IR that browsers can JIT very easily. Which is basically the same thing. So BF is "basically" native code too, since it can be JITted very easily? In fact, it's much easier to JIT BF than asm.js, so according to your definition it is even more "native" than asm.js. The way you are using "native" takes away all of its meaning. > Everything is an IR. Python is an IR for the thoughts in my head. It's turtles all the way down. It's really not. Yes, every executable representation is a representation (though we don't usually call representations "intermediate" if they are designed to be executed directly). But the hand-wavy idea that because two things are both representations they are "basically the same thing" is so far from true that it is the opposite of insight. The truth is that the differences between representations is one of the deepest concepts in compilers and VMs. For example, the entire difference between asm.js and PNaCl mostly boils down to the differences between their two different representations (a modified LLVM bitcode vs. a JavaScript subset). If these two things are "basically the same" then asm.js and PNaCl are "basically the same" too.
- lifthrasiir 13y agoThe conversion from asm.js to native code is much easier than the conversion from JavaScript to native code. The conversion from the real assembly code to native code would be slightly easier than that, but not significantly, making asm.js close to the assembly language (with an infinite number of registers, if that's your concern).
- haberman 13y agoIf "ease of converting to native code" is your criterion for "close to assembly language," then Brainf*ck is about the closest to assembly language you can get, because you can write a BF->x86 JIT in about 100 lines of C: http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-jits.html http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-s... So if that's what we're going for, we should forget asm.js and PNaCl and just use BF and expect very close to native speed. But this won't in fact give native code speed, despite how easy BF is to JIT. Why do you suppose that is?
- lifthrasiir 13y agoHuh, I thought it is obvious from the context but I'll restate my words here: It is easier to make native codes from asm.js code than to make native code with the similar performance characteristics from JavaScript code. It is always easy to get things just work, even while it may mean that printing "Hello, world!" would take minutes. But it is hard to get things work and fast, and there is a certain threshold that it is much harder to optimize once that threshold has been reached. Asm.js have much higher threshold than JavaScript's (and obviously BF's); you can literally replace each line of the already-verified asm.js code with a direct translation with a simple register allocator and it may occasionally (not always, of course) beat optimized JavaScript implementations. Yes, modern JavaScript implementations can optimize the same JavaScript code to that level once it becomes a hotspot! But having a higher threshold changes the problem, for example, time spent to analyze and annotate JavaScript code with hidden types and guards and assumptions can now spent for other optimization passes (e.g. auto-vectorizations). And you are seriously wrong with BF JIT, you at least have to merge runs of same instructions. (Not to mention other common optimizations, c2bf has only some of them.) Of course it would only matter if you want BF to be fast...