TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sljit: Platform independent low-level JIT compiler

139 pointsby nateb202210 months ago

9 comments

the_duke10 months ago
Interesting, first time I heard about sljit.<p>&gt; Although sljit does not support higher level features such as automatic register allocation<p>I don&#x27;t quite see how it can be architecture independent if it doesn&#x27;t do register allocation. Does it use a small fixed amount of virtual registers which work on every target? Or does it spill virtual registers to memory if required?<p>&gt; The key design principle of sljit is that it does not try to be smarter than the developer.<p>&gt; This principle is achieved by providing control over the generated machine code like assembly languages.<p>So it sounds like this is essentially your LLVM backend, taking care of going from intermediate representation to machine code.<p>Optimisations have to be done separately.<p>I see how a lightweight code generator could be quite useful, is sljit used in any larger projects?
评论 #40915755 未加载
评论 #40916151 未加载
评论 #40925136 未加载
评论 #40916002 未加载
steego10 months ago
From the website:<p><pre><code> The engine strikes a good balance between performance and maintainability. The LIR code can be compiled to many CPU architectures, and the performance of the generated code is very close to code written in assembly languages. Although sljit does not support higher level features such as automatic register allocation, it can be a code generator backend for other JIT compiler libraries. Developing these intermediate libraries takes far less time, because they only needs to support a single backend. </code></pre> <a href="https:&#x2F;&#x2F;zherczeg.github.io&#x2F;sljit&#x2F;" rel="nofollow">https:&#x2F;&#x2F;zherczeg.github.io&#x2F;sljit&#x2F;</a><p>I&#x27;d love to see some examples of other projects incorporating this library.
评论 #40920339 未加载
naasking10 months ago
What is the advantage relative to GNU Lightning, which seems like its most direct competitor.
评论 #40924919 未加载
peter_d_sherman10 months ago
This is interesting:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;sljit_src&#x2F;sljitLir.h">https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;sljit_src&#x2F;slji...</a><p>(Lines 167-205):<p>&#x2F;&#x2F; Scratch registers.<p>#define SLJIT_R0 1<p>#define SLJIT_R1 2<p>#define SLJIT_R2 3<p>&#x2F;&#x2F; Note: on x86-32, R3 - R6 (same as S3 - S6) are emulated (they are allocated on the stack). These registers are called virtual and cannot be used for memory addressing (cannot be part of any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such limitation on other CPUs. See sljit_get_register_index().<p>#define SLJIT_R3 4<p>[...]<p>#define SLJIT_R9 10<p>[...]<p>&#x2F;* Saved registers. *&#x2F;<p>#define SLJIT_S0 (SLJIT_NUMBER_OF_REGISTERS)<p>#define SLJIT_S1 (SLJIT_NUMBER_OF_REGISTERS - 1)<p>#define SLJIT_S2 (SLJIT_NUMBER_OF_REGISTERS - 2)<p>&#x2F;&#x2F; Note: on x86-32, S3 - S6 (same as R3 - R6) are emulated (they are allocated on the stack). These registers are called virtual and cannot be used for memory addressing (cannot be part of any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such limitation on other CPUs. See sljit_get_register_index().<p>#define SLJIT_S3 (SLJIT_NUMBER_OF_REGISTERS - 3)<p>[...]<p>#define SLJIT_S9 (SLJIT_NUMBER_OF_REGISTERS - 9)<p>Anyway, this is a cool technique...<p>Emulating additional registers on machines that don&#x27;t have them via the Stack, so that the assembly-like LIR can run on those machines too!<p>Very nice!
gizmo10 months ago
Although I only looked at the code briefly I suspect it will very hard to get good performance from the API as provided[1].<p>It looks like you have to do a function call for every high level assembly instruction which in turn does quite a bit of work. See `emit_x86_instruction`[2], most of which is redundant and most of which can be done ahead of time. To JIT quickly you want to work with templates if at all possible. Precompile those templates for the relevant architecture. Then at runtime you just patch the precompiled machine code with the correct addresses and registers. This extra speed really matters because if JITing code is cheap you can compile functions multiple times, inline aggressively and do many other optimizations that wouldn&#x27;t be economical otherwise.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;test_src&#x2F;sljitTestCall.h">https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;test_src&#x2F;sljit...</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;sljit_src&#x2F;sljitNativeX86_64.c">https:&#x2F;&#x2F;github.com&#x2F;zherczeg&#x2F;sljit&#x2F;blob&#x2F;master&#x2F;sljit_src&#x2F;slji...</a>
评论 #40920993 未加载
评论 #40921134 未加载
评论 #40917436 未加载
pierrec10 months ago
Since this is stackless, does it support checkpointing and resuming the execution state? This is sometimes a reason for making execution stackless, but I guess the JIT might make this more difficult. I can&#x27;t find any mention of this in the readme or project page so I&#x27;m guessing no, but it would be neat.
namjh10 months ago
Interesting project and kind of tangential topic, will JIT compilers still be widely adopted given they are considered a critical attack vector when it misbehaves? I wonder if there is an effort to formally verify its safety or do a complete redesign to ensure it.
评论 #40924545 未加载
ufo10 months ago
Does it support deoptimization back to bytecode? That&#x27;s useful for dynamic language JITs.
评论 #40920236 未加载
mllev10 months ago
Well this is epic