Permalink
Browse files

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]
  • Loading branch information...
xenu authored and jkeenan committed Sep 12, 2018
1 parent 3366620 commit 103d1ddd6bdaaee0b639d97f5ba91878465dceca
Showing with 1 addition and 1 deletion.
  1. +1 −1 pp.c
View
2 pp.c
@@ -1504,7 +1504,7 @@ PP(pp_divide)
) {
/* Integer division can't overflow, but it can be imprecise. */
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. */

0 comments on commit 103d1dd

Please sign in to comment.