diff options
author | Tomasz Konojacki <me@xenu.pl> | 2018-10-15 05:24:27 +0200 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2018-11-02 14:53:42 +1100 |
commit | f196658042490a6287fc178f0bc20fd5558ac54b (patch) | |
tree | 9d76a58641f2aa0058af1375101d22fb35e31159 /pp.c | |
parent | 191f8909fa4eca1db16a91ada42dd4a065c04890 (diff) | |
download | perl-f196658042490a6287fc178f0bc20fd5558ac54b.tar.gz |
pp_divide: use modulo instead of multiplication
On most architectures with hardware integer division (like
x86 or aarch64), division instruction returns both the remainder
and the quotient. It means that performing modulo operation
immediately after division using the same operands is 100% free.
Essentially this commit changes "div" and "mul" into a single "div"
instruction, which results in minor speed up.
[perl #133511]
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1503,8 +1503,11 @@ PP(pp_divide) #endif ) { /* Integer division can't overflow, but it can be imprecise. */ + + /* Modern compilers optimize division followed by + * modulo into a single div instruction */ const UV result = left / right; - if (result * right == left) { + if (left % right == 0) { SP--; /* result is valid */ if (left_non_neg == right_non_neg) { /* signs identical, result is positive. */ |