simd-everywhere / simde

Implementations of SIMD instruction sets for systems which don't natively support them.
https://simd-everywhere.github.io/blog/
MIT License
2.32k stars 239 forks source link

Implement reverse-lane ABI for wasm #1114

Closed SoniEx2 closed 7 months ago

SoniEx2 commented 9 months ago

This is probably slower than it needs to be, but we tried to keep it clean more than anything.

Reverse-lane ABI is used in wabt, and even in wasmtime sometimes. Not really aware of any other wasm runtimes that support s390x/big-endian platforms...

(This is also probably wrong somehow, what with the whole "new contributor" thing. Suggestions/feedback/guidance would be appreciated.)

Closes #1113

mr-c commented 9 months ago

Thank you @SoniEx2 for this; how shall we test this in our CI? Do we have to use WABT, or ..?

SoniEx2 commented 9 months ago

How is simde testing set up? The intended use-case of this feature is to run unmodified wasm (simd) tests on s390x platform, including (simd) endian tests. Certainly, using wasm2c would work, but may be too heavyweight...? (And arguably the cyclic dependency is less than ideal...)

mr-c commented 9 months ago

How is simde testing set up? The intended use-case of this feature is to run unmodified wasm (simd) tests on s390x platform, including (simd) endian tests. Certainly, using wasm2c would work, but may be too heavyweight...? (And arguably the cyclic dependency is less than ideal...)

In https://github.com/simd-everywhere/simde/pull/1114/commits/9212c4a271cd9319759e0054a4380c470f650c67 I added s390x GCC builds using -DSIMDE_WASM_REVERSE_LANE_ORDER; should that be enough?

mr-c commented 9 months ago

Error log from s390x qemu + GCC 12: https://github.com/simd-everywhere/simde/actions/runs/7129811835/job/19414754673?pr=1114#step:10:1012

SoniEx2 commented 9 months ago

hmm...

the feature does work in wabt: https://github.com/SoniEx2/wasm2kotlin/actions/runs/7122216960/job/19392874088

however, wabt has code to specifically take advantage of reverse lane order, while the existing simde tests may not...

will look in a bit, currently on phone.

mr-c commented 9 months ago

Here is some of the test code:

https://github.com/simd-everywhere/simde/blob/471a34285aa6909d5b9b9ff3dcebfa6acf3bce47/test/wasm/simd128/bitmask.c#L62-L64

SoniEx2 commented 9 months ago

ah, indeed!

since wabt stores the entire wasm memory in reverse byte order (so wasm byte address 0 is at mem[size-1]), it aligns nicely with reverse lane order. but the simde tests assume direct byte order.

SoniEx2 commented 7 months ago

the solution we would like to see would be for the tests to use simde_wasm_*_make, but we no longer feel like these changes would be a particularly good fit for simde. we will just do what we need to do in wabt, tho if anyone wants to revisit this whole thing at some point, they are welcome to do so.

thanks anyway.