I think these modifications should be able to optimize related calculations.
Sorry if I am mistaken.
Details
- Reviewers
klausler
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This patch only optimizes cases with upper halves all zero. Signed division has opportunities for optimization when upper halves are all ones, too.
But this code only exists as a backstop for builds with C compilers that don't have native 128-bit ints. Correctness is the only thing that matters. I would be very nervous about changing this code unless its performance became important.
flang/include/flang/Common/uint128.h | ||
---|---|---|
23 | Please use the CHECK macro from flang/include/Common rather than assert(). Or don't crash at all; the original code returns maximum values for division by zero, which is not unreasonable. | |
168–169 | The original statement ("++quotient;") is more clear. | |
181 | I think this code is wrong for negative *this. Are you sure that (-1) % 2 should be -1? Are you sure that (-3) % (-2) should be -3? |
Thank you so much for your comments. I learned a lot from them! I noticed algorithms are ingenious here, so I just wanted to make them faster. I kept only one modification and added a corresponding comment. If you think it's unnecessary, I will close this revision. Thanks again!
Please use the CHECK macro from flang/include/Common rather than assert(). Or don't crash at all; the original code returns maximum values for division by zero, which is not unreasonable.