In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/f196658042490a6287fc178f0bc20fd5558ac54b?hp=191f8909fa4eca1db16a91ada42dd4a065c04890>

- Log -----------------------------------------------------------------
commit f196658042490a6287fc178f0bc20fd5558ac54b
Author: Tomasz Konojacki <m...@xenu.pl>
Date:   Mon Oct 15 05:24:27 2018 +0200

    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]

-----------------------------------------------------------------------

Summary of changes:
 pp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pp.c b/pp.c
index 33eac6040d..cfa343fbbb 100644
--- a/pp.c
+++ b/pp.c
@@ -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.  */

-- 
Perl5 Master Repository

Reply via email to