Open kg opened 1 year ago
Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.
Author: | kg |
---|---|
Assignees: | - |
Labels: | `arch-wasm` |
Milestone: | - |
As of https://github.com/dotnet/runtime/pull/94446/commits/3a278eeb7c046ffe12ffbfeb6f955f382f51667a in #94446 basic cases now work in the interpreter, I had to fix some assumptions about scalarized structs (i.e. they're always int32) and also update the return value marshaling to handle scalarized return values. Will investigate AOT more.
The AOT wrapper appears to invoke using the wrong indirect signature when structs are involved. For a pinvoke with the signature 'float (double)', it's correct:
75336 117100 call_indirect 113 tables[0] s(d)
For a pinvoke accepting a struct and returning a float:
75201 11D70100 call_indirect 215 tables[0] s(l)
For a pinvoke accepting a struct and returning a struct:
75067 115300 call_indirect 83 tables[0] i(l)
It looks like the problem is it's picking an appropriately-sized int to contain the struct, but in this case it needs to pick an appropriately-sized float instead.
Tagging subscribers to this area: @brzvlad, @kotlarmilos See info in area-owners.md if you want to be subscribed.
I believe a lot of this is fixed but I don't think I added enough coverage to guarantee that it's all fixed.
The wasm ABI https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#function-signatures appears to imply that the following cases will all become scalars and be passed by-value instead of by-reference:
The current PInvoke generator doesn't support any of this (I'm working on fixing it in https://github.com/dotnet/runtime/pull/94446) so you may need to use my PR in order to test.
At present we only seem to implement case A & case C reliably. By updating
mini_wasm_is_scalar_vtype
inmini-wasm.c
we can make case B work* in the AOT compiler but if we also implement case D by allowing I8/U8 types through, we get assertion failures in the AOT compiler:* When I say 'work' above I mean 'compile'; the compiled code still does not work right in either the interpreter or AOT:
In the interpreter, the code will run but either gets garbage or 0 instead of the struct instance:
I think this is because the interpreter has its own logic for identifying scalar vtypes, but when I attempted to fix it that caused all sorts of problems.
Sample code I used for testing:
cc @vargaz