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

implement missing cvt u64 -> r64 for x86-64 #37

Open
robertmuth opened this issue Aug 11, 2024 · 0 comments
Open

implement missing cvt u64 -> r64 for x86-64 #37

robertmuth opened this issue Aug 11, 2024 · 0 comments

Comments

@robertmuth
Copy link
Owner

since x86-64 does not have such an instruction (only one for s64 -> r64)
we should probably rewrite this at the IR level

cvt dst:r64 = src:u64

would become

if top bit of src:u64 is set:
shr dst2:u64 src:u64 1 # clears the top bit by halving the input
cvt dst3:s64 dst2:u64 # nop at the machine level
cvt dst:r64 dst3:s64 # use the available instruction
add dst:r64 dst:r64 dst:r64 # double the output
else:
cvt dst2:s64 dst:u64 # nop at the machine level
cvt dst:r64 dst2:s64 # use the available instruction

r64 only has about 52 significant bit so throwing one is no big deal

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

No branches or pull requests

1 participant