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

omit known zero offset #71

Open
HookedBehemoth opened this issue Sep 12, 2022 · 2 comments
Open

omit known zero offset #71

HookedBehemoth opened this issue Sep 12, 2022 · 2 comments

Comments

@HookedBehemoth
Copy link

Found that when writing code like ; mov QWORD [buffer + offset as i32], temp where offset is a immediate value this crate will unconditionally emit relative instructions. When explicitly checking for when offset is zero and emitting ; mov QWORD [buffer], temp reduces my emitted code significantly (~10%).
Maybe this crate could check if immediate values are zero and choose to emit smaller instructions.

@HookedBehemoth
Copy link
Author

To aid with size reduction it would also be nice to have a "smallest" size annotation. The assembler could then choose to use add/sub/jmp instructions with the smallest possible size for the immediate value. i.e.
; add r14, AUTO s.len() as _
with s.len() < 255 -> 49 83 c6 XX
else -> 49 81 c6 XX XX XX XX

@CensoredUsername
Copy link
Owner

The crate is built with the idea in mind that instruction sizes (and the generated instruction) should be predictable from the code, to allow things like instruction patching / hotswapping. The behaviour you mentioned first would need some kind of annotation as well to allow it.

I'm having trouble thinking of how to implement this properly though. The x64 instruction set is not regular at all, and just selecting the right instruction is already extremely hairy. Would probably have to just generate the three size possibilities, pass them each through it and see which compiles. And then figure out how to generate branching code from the backend (which also expects somewhat stable sizes).

Summarizing: I might consider it at some point but this is fairly low priority, especially considering the same behaviour can be implemented by the user easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants