Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Webassembly compilation a look-up table?

Tags:

webassembly

My understanding is that Webassembly is basically a set of machine code instructions that all supported processors have in common, i.e. it contains commands like "pop register 2', but not specialized commands specific to only a few processors, e.g. Intel MMX commands.

It seems to me that, given programs limited to these common commands, compiling them is merely a matter of looking up the local equivalent machine code for each listed Wasm code, which would explain how "streaming compilation" is possible.

Is this description accurate, grossly oversimplified, or flat out wrong?

like image 269
Jack Avatar asked Mar 02 '26 05:03

Jack


1 Answers

Is WebAssembly compilation a look-up table?

No.

My understanding is that Webassembly is basically a set of machine code instructions that all supported processors have in common

No, it is not. WebAssembly has a simple instruction set that is assembly-like in some ways (bitwise operators, load, store, simple maths), however, in other ways it is not at all like assembly language. It supports functions, structured control flow - in the future it will support reference types, etc ...

It seems to me that, given programs limited to these common commands, compiling them is merely a matter of looking up the local equivalent machine code for each listed WASM code, which would explain how "streaming compilation" is possible.

The 'streaming compilation' works because the binary format of WebAssembly precedes each section, function body etc ... is preceded with its length. This makes it easy to split it into 'chunks' which are compiled across different threads.

Is this description accurate, grossly oversimplified, or flat out wrong?

Perhaps a bit of each? ;-)

You can find out much more about the design goals of WebAssembly on the 'Design Rationale' page on the website:

https://webassembly.org/docs/rationale/

like image 158
ColinE Avatar answered Mar 04 '26 09:03

ColinE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!