Modulo Simplification
See original GitHub issueIs your feature request related to a problem? Please describe. I’m always frustrated when I see a bunch of shifts, division, logical and other arithmetic for the modulo operation.
Describe the solution you’d like The operations to be simplified into the modulo operation.
Describe alternatives you’ve considered Opening up the program in IDA to see what is really going on. I am guilty of doing exactly this as it still beats breaking out a pencil and paper to figure it out.
Additional context
int mod6(int i) {
return i % 6;
}
Here are some xml debug function decompilation outputs. (This one is guilty of not automatically appending the xml file extension)
mod2.xml.txt mod3.xml.txt mod4.xml.txt mod6.xml.txt
See, I do know what the modulo operator is…
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Simplification of Modulo formula - Mathematics Stack Exchange
Indeed it is, yes. The logic is that taking modulo can be exchanged with multiplication, i.e. a⋅bmodc=(amodc)⋅(bmodc)modc. for all a,b,c.
Read more >How to simplify modulo - math - Stack Overflow
How do I use it to simplify the following modulo operation? (a - 2*b + 1) mod N. There must be some way...
Read more >Fun With Modular Arithmetic - BetterExplained
I hadn't given it much thought, but realized the modulo is extremely powerful: it should be in our mental toolbox next to addition...
Read more >Modular multiplication (article) - Khan Academy
We will prove that (A * B) mod C = (A mod C * B mod C) mod C. We must show that...
Read more >Modulo Calculator - Symbolab
Identities Proving Identities Trig Equations Trig Inequalities Evaluate Functions Simplify · Statistics · Arithmetic Mean Geometric Mean Quadratic Mean ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Like @Swyter mentioned, work has been done for division by constants (see #1718, #668). Something like 2463cad should be doable eventually?
So you want to undo peephole optimization. Is there any way besides hardcoding a list of heuristics? Sounds like an interesting project.