question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modulo Simplification

See original GitHub issue

Is 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;
}

image

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sad-devcommented, Jun 8, 2022

Like @Swyter mentioned, work has been done for division by constants (see #1718, #668). Something like 2463cad should be doable eventually?

1reaction
pjsoberoicommented, Jun 8, 2022

So you want to undo peephole optimization. Is there any way besides hardcoding a list of heuristics? Sounds like an interesting project.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found