Hey folks, I work on a networking project that currently rolls its own JIT for x64/aarch64, and am taking a look into swapping that over to use Cranelift instead. The main issue I'm seeing currently is a performance issue with the generated machine code - byteswaps are common in this space (endinaness conversion) and Cranelift has an open item but no existing support. I was thinking of working on adding a new opcode (Bswap, and possibly also Bswap32 and Bswap16) to the IR, and adding support to the codegen backends for emitting x64 and aarch64 bswap instructions. Would that be the right way to go about this, and is the project generally accepting of that sort of pull request?
Yeah, having a bswap
instruction would be useful, and there are other cranelift users that need them! cg_clif a rust compiler that uses cranelift has to do some interesting... codegen to get around this.
It'd be great to have native support for that!
In general we support a generic instruction and have a polymorphic type, so for example, we only have one band
but it has an implicit type operator that we can pass, (or it can be inferred) that makes it usable for many types, (i.e. band.i16
or band.i64
, etc..)
If you need any help adding that to cranelift let me know, and I can guide you through the process.
Yeah, when trying out Cranelift I wrote some similarly-weird codegen to work around the lack of bswap
, but it ended up being ~3x-5x slower than having a real bswap instruction at runtime, which is a real bummer in network code that's doing a bunch of host-to-network-order conversions. Thanks for the advice about the typing! I'll take a stab at this and reach out when I have questions
:thumbs_up: Good luck!
Ok, continuing this discussion from a few weeks ago, here's a PR to add bswap: https://github.com/bytecodealliance/wasmtime/pull/5147
This is my first time contributing to the project, please let me know who should be added as reviewers etc. I added unit tests for instruction encoding, and did some manual testing with a toy program and x86_64 and aarch64 machines to verify the bswap instruction worked. Please let me know what other test coverage might be expected
We'll take a look -- thanks a bunch for this! In general for reviews we don't really assign, we just have enough people watching the incoming PRs that someone will pick it up. One of us will get to it soon!
Awesome, thanks!
Last updated: Nov 22 2024 at 16:03 UTC