Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninline the division in the AMD64 backend #169

Open
koute opened this issue Sep 18, 2024 · 0 comments
Open

Uninline the division in the AMD64 backend #169

koute opened this issue Sep 18, 2024 · 0 comments
Labels
D-easy An easy issue that might be good for someone new P-low Low priority

Comments

@koute
Copy link
Collaborator

koute commented Sep 18, 2024

Currently the division/remainder instructions in the AMD64 backend are implemented by generating quite a lot of code inline (due to having to handle all of the corner cases of emulating RISC-V division), and considering that division is a relatively rare and expensive operation anyway it probably doesn't make sense to bloat the code with it (I'd like to have some upper bound on how much native code one PolkaVM instruction can generate, and this instruction bloats it a lot).

Convert div_rem in crates/polkavm/src/compiler/amd64.rs into a generic routine (you'll probably want two, one for div and one for rem) that will be emitted only once by the recompiler (e.g. similar to the emit_*_trampoline functions, just with a ret at the end), and strip down the div_rem to essentially only 1) push the arguments on the stack, 2) call the generic routine, 3) once the generic route returns move the result into the destination register.

@koute koute added P-low Low priority D-easy An easy issue that might be good for someone new labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-easy An easy issue that might be good for someone new P-low Low priority
Projects
None yet
Development

No branches or pull requests

1 participant