4 ms·
One thing I didn't realize for awhile is that it's not actually an assembly language. At least not in a traditional way. Because it is high level, with things l
by ilaksh 3y ago
One thing I didn't realize for awhile is that it's not actually an assembly language. At least not in a traditional way. Because it is high level, with things like loop and if-else, etc.
I assume it was initially intended to be more like a "real" assembly language but then they realized how much more optimized things could be if they went with higher level constructs.
- capitainenemo 3y agoWell, it grew out of ASM.js, so not really an accident. https://en.wikipedia.org/wiki/WebAssembly https://en.wikipedia.org/wiki/WebAssembly "the initial implementation was based on the feature set of asm.js." https://en.wikipedia.org/wiki/Asm.js https://en.wikipedia.org/wiki/Asm.js NaCL tried more to be a real assembly language but had cross-platform issues.
- pjmlp 3y agoHence why PNaCL came to be.
- capitainenemo 3y agoHuh. I thought PNaCL had cross-platform endian issues from what I'd read at the time. However: https://www.tomshardware.com/news/chrome-deprecates-pnacl-embraces-webassembly,34583.html https://www.tomshardware.com/news/chrome-deprecates-pnacl-em... Just mentions API concerns and: https://robert.ocallahan.org/2013/05/blink-pnacl-and-standards.html?gad_source=1 https://robert.ocallahan.org/2013/05/blink-pnacl-and-standar... " PNaCl and Pepper are not open standards, and there are not even any proposals on the table to standardize them in any forum. They have documentation, but for the details one must defer to the large bundle of Chrome code that implements them. " and "1. NaCl is CPU-specific. That's not suitable for the web. 2. PNaCl is in theory portable, so it is potentially worth considering. 3. However there is no spec for PNaCl, and standardizing it would take an extreme amount of effort: It means standardizing a subset of LLVM IR, which is quite rich and complex, as well as the Pepper plugin API. This is an enormous amount of work that has not even been begun by Google AFAIK." But you're right, I don't see anyone mentioning any hardware complications. Oh well. Moot point these days, and I think we're all better off that everyone else stood their ground, in terms of security, integration with JS APIs, and having a variety of WASM implementations.
- capitainenemo 3y ago(And I'm sure the situation would have been very different nowdays, with a google controlled engine dominating 95% of browsers)
- kevingadd 3y agoif-else is basically the equivalent of syntax sugar, and it was controversial for a while whether it should be included. WASM's 'loop' isn't really that high level, it's a backwards branch target with no built in bells or whistles. It's less powerful than 'while' in C.
- eru 3y agoYes. If you want to argue that WASM is higher level than 'real' assembly, I would point towards its ability to call functions more than its slightly weird jumps.
- int_19h 3y agoIf I remember correctly, the main reason why Wasm has structured control flow rather than old-school arbitrary jumps is not because you can optimize the former better in general, but specifically because it enables efficient JIT streaming compilation with simultaneous code verification (for sandboxing), which was deemed important for web use cases. Simply put, wasm is optimized to allow JITs to be simpler, at the expense of making it harder to write compilers for it.
- kevingadd 3y agoThe structured control flow also specifically makes secure compilation much easier. If you want to do something like CFI, it's easy since you know where all your branches and branch targets are and who can reach them.
- int_19h 3y agoYes, that is the "verification" part I mentioned. With VMs like Java or .NET, the compiler has to infer essentially the same graph from unstructured labels and jumps.
- Findecanor 3y agoI find that being guaranteed to have only structured control flow, and having loops and if-else constructs marked as such in advance could also simplify a AOT-compiler a little. If you're doing liveness analysis, you wouldn't have to first deduce which edges are unstructured jumps and which are loop edges. If you're trying to find more opportunities for if-conversion, you wouldn't have to first deduce which edges those are.
- int_19h 3y agoI should add, however, that the unmentioned elephant in the room is V8 JIT (TurboFan), which simply doesn't handle irreducible control flow. While there are some valid theoretical arguments around the current arrangement in Wasm, looking at the history of the associated discussions makes it pretty obvious that having V8 support Wasm and generate fast code similar to what it can do for asm.js was an overriding concern in many cases. And Google straight up said that if Wasm has ICF, they will not bother supporting such cases, so it will be done by a much slower fallback: https://github.com/WebAssembly/design/issues/796#issuecomment-298268883 https://github.com/WebAssembly/design/issues/796#issuecommen... AFAIK no other Wasm implementation has the same constraint - the rest generally tend to desugar everything to (potentially irreducible) CFG and then proceed from there. So this is, at least to some extent, yet another case of a large company effectively forcing an open standard to be more convenient for them specifically.