Hello!
Today, I took a stab at implementing call for aarch64 in winch, I got the basic plumbing going, taking inspiration from x64, and cranelift, but I'm left with a couple of questions:
Right now, I have hardcoded the calling convention to SystemV, but my understanding is that we should somehow get this information from the assembler instead. I'm unsure how to do this, though, and the x64 implementation has a hardcoded x64. Can you guide me here?
bl
targets are completely off (even with cranelift), so I'm assuming that I am doing something wrong. How should I go about testing the generated asm?Re: register offsets: what you're probably seeing (just my educated guess) is that Wasm parameters come after the "caller vmctx" and "callee vmctx" parameters in Wasmtime's internal calling convention; so a wasm function with one arg will indeed take that one arg in x2
/w2
(depending on width)
cc @Saúl Cabrera for the design questions around calling convention
ohh that makes a lot of sense! is that internal calling convention described anywhere?
I don't think we've formally documented it separately (there are probably comments somewhere); it's kind of implicit in the code unfortunately, sorry :-/
You can find the documentation in the ABI module https://github.com/bytecodealliance/wasmtime/blob/main/winch/codegen/src/abi/mod.rs#L15
It's explicitly stated how the ABISig
behaves.
It's great that you've gotten calls almost working! For future reference and to avoid the risk of duplicated efforts it's advised to reach out through Zulip or comment in this issue https://github.com/bytecodealliance/wasmtime/issues/8321 whenever you'd like to implement a new Aarch64 instruction. For now calls are assigned to me, since it's the next immediate instruction that I was planning on working next, however, I haven't started, so if you have no objections, I'll add your github handle next to it.
I will next time for sure! I just started out of curiosity and then fell into the rabbit hole. I'll assign myself the other instruction I had to implement to get things working then.
I think you won't be able to edit the issue -- I can do that for you though. Feel free to send me your GH handle and the other instruction either here or DM!
here's my handle: MarinPostma
the other instruction I had to implement was trapz
and address_at_vmctx
@Saúl Cabrera how would you trigger a libcall from wasm?
a memcpy, I guess?
It depends what exactly you mean by libcall in this context. Are you trying to call out to some builtin function?
I am trying to enter the CalleeKind::LibCall
branch of the Masm::call
's callee argument
Usually in that case you'd load the address of the function into a register and emit a call using that register, similar to what's in there for x64 https://github.com/bytecodealliance/wasmtime/blob/main/winch/codegen/src/isa/x64/asm.rs#L1290
sorry, I did not express myself correctly. What I mean to do is to write some wasm code that will emit a libcall instruction. I tried with Memory.fill
, but it is just a regular call towasmtime_builtin_memory_fill
I wan to test my implementation
I don't think there's a great way to hit the libcall case in aarch64, the libcall is used as a fallback mechanism for when the target architecture doesn't offer support for certain operations (e.g., f32_floor
). Most (if not all) of the float operations for aarch64 have been implemented and none of those require a libcall https://github.com/bytecodealliance/wasmtime/blob/main/winch/codegen/src/isa/aarch64/masm.rs#L353
@Saúl Cabrera I believe it is done: https://github.com/bytecodealliance/wasmtime/pull/9751, can I do anything else? More instructions?
Thanks, I'll take look today! If you're interested, here's the list of missing instructions for aarch64 https://github.com/bytecodealliance/wasmtime/issues/8321 feel free to pick -- by the way, we also have the #winch stream, so feel free to move any other conversation there regarding other instructions/questions/etc.
Last updated: Dec 23 2024 at 13:07 UTC