Live data from Hacker News

I Wrote a WebAssembly VM in C

irreducible.io

71–80 of 104 posts

Re: I Wrote a WebAssembly VM in C

#72

Earlier quoted context omitted.

Lisp and Smalltalk are 266 MB? tcc is 100KB https://www.bellard.org/tcc/

TCC doesn't do much optimization in turn, while commercial implementations of Lisp and Smalltalk are surely much larger than that.

I'm not sure what your point is. The person I replied to was justifying a 266MB binary by saying a compiler was included. Are you saying optimization would make tcc 2,660 times as big?

Re: I Wrote a WebAssembly VM in C

#73

Earlier quoted context omitted.

TCC doesn't do much optimization in turn, while commercial implementations of Lisp and Smalltalk are surely much larger than that.

I'm not sure what your point is. The person I replied to was justifying a 266MB binary by saying a compiler was included. Are you saying optimization would make tcc 2,660 times as big?

The point is that LLVM does much, much more than TCC and, while it is definitely possible that LLVM could have done that in a smaller binary, TCC is probably not a good thing to compare with because it only does a bare minimum. I should also note that LLVM is a cross-compiler by default...

Re: I Wrote a WebAssembly VM in C

#74

This is an interesting approach, great work! For anyone that wants to check where the meat is at, is mostly in this file: https://github.com/irrio/semblance/blob/main/src/wrun.c Thinking out loud, I think it would have been a great idea to conform with the Wasm-C-API ( https://github.com/WebAssembly/wasm-c-api ) as a standard interface for the project (which most of the Wasm runtimes: Wasmer, V8, wasmi, etc. have ado…

afaik it's far from adopted by Wasmer. https://github.com/wasmerio/wasmer/issues/2615 - stale then autoclosed

Re: I Wrote a WebAssembly VM in C

#75

Earlier quoted context omitted.

I'm not sure what your point is. The person I replied to was justifying a 266MB binary by saying a compiler was included. Are you saying optimization would make tcc 2,660 times as big?

The point is that LLVM does much, much more than TCC and, while it is definitely possible that LLVM could have done that in a smaller binary, TCC is probably not a good thing to compare with because it only does a bare minimum. I should also note that LLVM is a cross-compiler by default...

The person I replied to just said it is 266MB because it includes a compiler, and that obviously isn't true.

https://github.com/bytecodealliance/wasm-micro-runtime

This says 4000 lines

https://github.com/explodingcamera/tinywasm

What are we talking about here? There is obviously no reason a wasm jit has to be 266 MB

Re: I Wrote a WebAssembly VM in C

#76
post #74

This is an interesting approach, great work! For anyone that wants to check where the meat is at, is mostly in this file: https://github.com/irrio/semblance/blob/main/src/wrun.c Thinking out loud, I think it would have been a great idea to conform with the Wasm-C-API ( https://github.com/WebAssembly/wasm-c-api ) as a standard interface for the project (which most of the Wasm runtimes: Wasmer, V8, wasmi, etc. have ado…

afaik it's far from adopted by Wasmer. https://github.com/wasmerio/wasmer/issues/2615 - stale then autoclosed

It seems the issue was not up to date, thanks for pointing it out (just commented in Github to make it clear for future readers).

Wasmer supports most of the Wasm-C-API, with some exceptions for APIs that are not that common to use: finalize, hostref and threads (tables just had some quirks on the implementation that we had to polish, but is generally implemented [1]).

https://github.com/wasmerio/wasmer/blob/main/lib/c-api/tests...

If you are interested in running any of these cases using Wasmer via the Wasm-C-API please let us know... it should be mostly trivial to add support!

[1] https://github.com/wasmerio/wasmer/blob/main/lib/c-api/src/w...

Re: I Wrote a WebAssembly VM in C

#77
post #70

Earlier quoted context omitted.

This is an opportunity to learn. The way WebAssembly is defined is the standard way PL semantics are defined.

WebAssembly isn't a programming language, it's an ISA or a bytecode VM. They've defined it in a very over-engineered way, with different representations all the way through. It has created issues for people working on assemblers and code generation because it's hard to choose a good representation for compilers to generate. This all could have been avoided.

Those are all programming languages.

Re: I Wrote a WebAssembly VM in C

#78

Earlier quoted context omitted.

I think it's much better to just learn how to read inference rules. They're actually quite simple, and are used ubiquitously to define PL semantics definitions. Constraining this on "that's not an option" is a big waste of time - learning this will open up all of the literature written on the subject.

The WASM spec is so well defined presumably because Andreas Rossberg is the editor - and he did a bunch of PL research on extensions to Standard ML, which is famous for it's specification!

I totally agree. Standard ML set the stage for everyone to finally formally specify a full language, and only WebAssembly has carried the torch as far as I know (other than small research languages).

Re: I Wrote a WebAssembly VM in C

#79
post #68

Earlier quoted context omitted.

> anything involving memory [..] needs safety checks that becomes multi-instruction Not necessarily; on AMD64 you can do memory accesses in a single instruction relatively easily by using the CPU's paging machinery for safety checks plus some clever use of address space. > branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops Even with metering the branches wo…

How do you avoid branches in 64-bit WASM?

You can run the guest in another thread/process and give it its own dedicated address space, or use something like memory protection keys.

Re: I Wrote a WebAssembly VM in C

#80
post #74

Earlier quoted context omitted.

afaik it's far from adopted by Wasmer. https://github.com/wasmerio/wasmer/issues/2615 - stale then autoclosed

It seems the issue was not up to date, thanks for pointing it out (just commented in Github to make it clear for future readers). Wasmer supports most of the Wasm-C-API, with some exceptions for APIs that are not that common to use: finalize, hostref and threads (tables just had some quirks on the implementation that we had to polish, but is generally implemented [1]). https://github.com/wasmerio/wasmer/blob/main/lib…

Thank you! I'll take a look...
Post reply on HN