Skip to content

rv64 implement muldi3 intrinsic #461

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

Merged
merged 2 commits into from
May 11, 2022
Merged

Conversation

johannst
Copy link
Contributor

This fixes #459.

Implement the __muldi3 intrinsic to prevent infinite recursion during
multiplication on rv64 without the 'm' extension.

Implement the __muldi3 intrinsic to prevent infinite recursion during
multiplication on rv64 without the 'm' extension.
@Amanieu
Copy link
Member

Amanieu commented May 11, 2022

In the case of rv32im we would want to use the existing implementation which builds a 64-bit multiply on top of 32-bit multiplies. Could this be made conditional to just targets without m?

@johannst
Copy link
Contributor Author

For rv32 the rv64 specific __muldi3 intrinsic is not active.
But I agree for the rv64im case. I'll see if we can only enable this in case the m extension is not available.

@Amanieu
Copy link
Member

Amanieu commented May 11, 2022

Even though LLVM doesn't actually use __muldi3 for 64-bit multiply on rv32im, we should still make it available because it may be used when linking with C code generated by GCC. Same with __mulsi3.

@johannst
Copy link
Contributor Author

Okay thanks for the clarification.

Let me try to summarize to check if I understood you correctly

  • rv32i: riscv:__mulsi3, riscv:__muldi3
  • rv32im: riscv:__mulsi3, int/mul:__muldi3
  • rv64i: riscv:__mulsi3, riscv:__muldi3
  • rv64im: riscv:__mulsi3, int/mul:__muldi3

Please correct me if I got you wrong.

@Amanieu
Copy link
Member

Amanieu commented May 11, 2022

That's correct.

Adapt conditional compilation as:
rv32i : riscv:__mulsi3, riscv:__muldi3
rv32im: riscv:__mulsi3, int/mul:__muldi3
rv64i : riscv:__mulsi3, riscv:__muldi3
rv64im: riscv:__mulsi3, int/mul:__muldi3
@johannst
Copy link
Contributor Author

I adapted the conditions accordingly.
The one for int/mul:__muldi3 became somewhat lengthy, if you see a better way I am happy to make it more readable.

@Amanieu Amanieu merged commit 4117da3 into rust-lang:master May 11, 2022
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

Successfully merging this pull request may close these issues.

riscv64 infinite recursing during multiplication __muldi3
2 participants