Samsung / walrus

WebAssembly Lightweight RUntime
Apache License 2.0
35 stars 10 forks source link

Merging JIT with Interpreter #164

Closed clover2123 closed 8 months ago

clover2123 commented 10 months ago

Let's discuss merging JIT with existing interpreter.

I have some questions about JIT compiler.

clover2123 commented 10 months ago

@zherczeg Would you please check this issue?

zherczeg commented 10 months ago

Yes, single functions can be compiled. It will increase the resource costs somewhat, and disallow direct function calls (this feature was used in the old jit). But I don't see any other disadvantage. Maybe we should add some management for global jit compiled helpers to compile them only once. We can move into this direction if you want it.

clover2123 commented 10 months ago

supporting JITC for single function is not an urgent task now, but IMHO this approach is mandatory to switch between interpreter mode and JITC mode in the future. I just want to know that there is any difficulty to support this.

Now, I think that it's the time to merge two branches (interp and jit or jit_next) into the main branch since there occur many conflicts (like #163) as we develop each branch separately. Merged walrus will operate in one of two modes (interpret or JITC) for a while. Are there any issues other than #163 in merging two branches?

zherczeg commented 10 months ago

I don't think single function compilation is a difficult task. There are some problems, which needs to be carefully handled, but not that many.

About merging: most of the patches in JIT branch are not compiling now due to the changes in the interpreter. The last patch compiles of course. It looks like a bigger work to make all of them compile cleanly. Squashing is an option, but the patch will be big. What shall we do?

Target status: x86-64 is working, except simd x86-32 was working, there are some fails since the last merge ARM64 fully works ARM32 has some issues (mainly unaligned accesses), patches are proposed for them RISCV: unknown

zherczeg commented 10 months ago

Btw jit_next is the branch for merging. jit contains a legacy implementation, it could be removed.

zherczeg commented 10 months ago

I have updated the compile function: void jitCompile(ModuleFunction* functions, size_t functionsLength, int verboseLevel)

If functionsLength is 0, it compiles all functions. Otherwise the functions listed in functions are compiled only. If a function has been already compiled, it is always ignored (no double compiling). Is this API acceptable for your plans?

clover2123 commented 10 months ago

@zherczeg That would be great! Thanks for the quick update. BTW I think that after fixing some conflicts with interpreter, we can merge it into the main branch. And then, we can develop walrus based on the main branch together.

zherczeg commented 9 months ago

Let me give a status update.

ARM64 - Works with simd ARM32 (normal and thumb2) - Wirks ,except floating point simd An emulation layer is created: https://github.com/Samsung/walrus/pull/165 x86 - Works except simd

If https://github.com/Samsung/walrus/pull/175 lands, the emulation layer can be simplified.

Do we need to do anything else before merging?

clover2123 commented 9 months ago

Thanks for your great contribution👍 SIMD support on ARM platforms would be enough After merging, we can work on performance/memory optimizations together

zherczeg commented 9 months ago

Thank you very much! How shall we land the patch? In its current state (where several patches does not compile), or do you need any modifications?

zherczeg commented 9 months ago

Shall we continue the simd support on x86, or do something else?

clover2123 commented 9 months ago

Would you please merge into the main branch? At first, dividing interpreter and jit mode would be enough as is. SIMD on x86 is not an urgent issue, so let's merge them and work on it later

clover2123 commented 8 months ago

Resolved by #177