News for hackers. Stuff that matters.
Re:Mir: Strongly typed IR to implement fast and lightweight ... by cozzyd on Wednesday December 27, 2023 @03:17AM (#38780078)
Too bad it doesn't support SIMD. Would be nice for an easily embeddable SIMD-aware JIT to exist.
Re:Mir: Strongly typed IR to implement fast and lightweight ... by mike_hearn on Wednesday December 27, 2023 @01:21PM (#38784833)
What do you mean by easily embeddable? There are JVM JITs that understand SIMD to some extent, and let you write manual SIMD code using the vector API.
Re:Mir: Strongly typed IR to implement fast and lightweight ... by IshKebab on Wednesday December 27, 2023 @02:21PM (#38785495)
It means you can easily use it from another program. Pretty much it has to be written in a language without a runtime that can expose a C interface, i.e. C, C++, Zig or Rust.
Re:Mir: Strongly typed IR to implement fast and lightweight ... by cozzyd on Wednesday December 27, 2023 @04:50PM (#38787208)
I guess you can do something like emit code on a memfd, exec ispc to another memfd and dlopen the output but... clunky.
Re:Mir: Strongly typed IR to implement fast and lightweight ... by mike_hearn on Wednesday December 27, 2023 @05:15PM (#38787460)
I don't follow. You can load every JITC I know of with C or C++ interfaces. And what is a JITC if not a runtime?
Re:Mir: Strongly typed IR to implement fast and lightweight ... by IshKebab on Wednesday December 27, 2023 @05:51PM (#38787839)
The runtime I'm talking about is for the language that the JIT compiler is written in.

If I want to use a JIT compiler that is written in Java in my C++ game I now have to distribute the Java runtime with my game. That's an example of "not easily embeddable".

Re:Mir: Strongly typed IR to implement fast and lightweight ... by mike_hearn on Thursday December 28, 2023 @06:07AM (#38792231)
Two things here:

1. If by runtime you mean "set of files" you can (these days) compile the Graal JIT compiler to a fully standalone DSO/DLL or even statically link the results into a larger executable. And because the Graal JIT understands Truffle that means making standalone statically linkable JITCs for any language is now very easy.

But that said, games always consist of more than one file anyway so the importance of this doesn't seem too high.

2. If by runtime you mean "support code" then C, C++ and Rust all have runtimes so you'd really need to define what specifically you need from a runtime.

Re:Mir: Strongly typed IR to implement fast and lightweight ... by IshKebab on Thursday December 28, 2023 @02:44PM (#38797687)
I didn't know that about Graal but I guess it depends on how easy that process is. Remember we're talking about "easily embeddable". You can embed anything with enough effort!
Re:Mir: Strongly typed IR to implement fast and lightweight ... by mike_hearn on Friday December 29, 2023 @04:50AM (#38803284)
See here for a guide on how to compile some Java code to a native library:

https://www.graalvm.org/latest/reference-manual/native-image...

One of the kinds of code you can compile this way is a language interpreter using the Truffle framework, which is a way to write interpreters that turns them into advanced JIT compilers automatically. If you do that then your language interpreter, runtime and the Graal/Truffle JIT compiler will all be compiled into your shared library. You can then export a C API from it using the technique shown in that article to load and execute code.

Re:Mir: Strongly typed IR to implement fast and lightweight ... by killcoder on Thursday December 28, 2023 @08:28AM (#38793251)
WebAssembly in something like wasmtime is probably the closest we've got to this. Though I wish WebAssembly supported more (wider) SIMD instructions.