perl 5.003_05: pp.c
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>
Tue, 3 Sep 1996 21:49:22 +0000 (17:49 -0400)
committerAndy Dougherty <doughera@lafcol.lafayette.edu>
Tue, 3 Sep 1996 21:49:22 +0000 (17:49 -0400)
Date: Fri, 23 Aug 1996 17:22:40 -0400 (EDT)
From: Chip Salzenberg <salzench@nielsenmedia.com>
Subject: Minor integer speedups in mathematics

This patch provides minor speedups by using integer math and SVt_IV
values when performing bitwise operations and modulus.

Date: Tue, 3 Sep 1996 17:49:22 -0400 (EDT)
From: Kenneth Albanowski <kjahds@kjahds.com>
Subject: Pack Patch (was Re: 5.002 - pack/unpack does not do "I" right)

(double)auint cast added for call to sv_setnv().

pp.c

diff --git a/pp.c b/pp.c
index 711ba29..cc2ef0b 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -687,19 +687,17 @@ PP(pp_modulo)
 {
     dSP; dATARGET; tryAMAGICbin(mod,opASSIGN);
     {
-      register unsigned long tmpulong;
-      register long tmplong;
-      I32 value;
+      register IV value;
+      register UV uval;
 
-      tmpulong = (unsigned long) POPn;
-      if (tmpulong == 0L)
+      uval = POPn;
+      if (!uval)
        DIE("Illegal modulus zero");
       value = TOPn;
-      if (value >= 0.0)
-       value = (I32)(((unsigned long)value) % tmpulong);
+      if (value >= 0)
+       value = (UV)value % uval;
       else {
-       tmplong = (long)value;
-       value = (I32)(tmpulong - ((-tmplong - 1) % tmpulong)) - 1;
+       value = (uval - ((UV)(-value - 1) % uval)) - 1;
       }
       SETi(value);
       RETURN;
@@ -926,7 +924,10 @@ PP(pp_bit_and) {
       if (SvNIOKp(left) || SvNIOKp(right)) {
        unsigned long value = U_L(SvNV(left));
        value = value & U_L(SvNV(right));
-       SETn((double)value);
+       if ((IV)value == value)
+           SETi(value);
+       else
+           SETn((double)value);
       }
       else {
        do_vop(op->op_type, TARG, left, right);
@@ -944,7 +945,10 @@ PP(pp_bit_xor)
       if (SvNIOKp(left) || SvNIOKp(right)) {
        unsigned long value = U_L(SvNV(left));
        value = value ^ U_L(SvNV(right));
-       SETn((double)value);
+       if ((IV)value == value)
+           SETi(value);
+       else
+           SETn((double)value);
       }
       else {
        do_vop(op->op_type, TARG, left, right);
@@ -962,7 +966,10 @@ PP(pp_bit_or)
       if (SvNIOKp(left) || SvNIOKp(right)) {
        unsigned long value = U_L(SvNV(left));
        value = value | U_L(SvNV(right));
-       SETn((double)value);
+       if ((IV)value == value)
+           SETi(value);
+       else
+           SETn((double)value);
       }
       else {
        do_vop(op->op_type, TARG, left, right);
@@ -1019,11 +1026,11 @@ PP(pp_complement)
       register I32 anum;
 
       if (SvNIOKp(sv)) {
-       IV iv = ~SvIV(sv);
-       if (iv < 0)
-           SETn( (double) ~U_L(SvNV(sv)) );
+       UV value = ~SvIV(sv);
+       if ((IV)value == value)
+           SETi(value);
        else
-           SETi( iv );
+           SETn((double)value);
       }
       else {
        register char *tmps;
@@ -2687,7 +2694,10 @@ PP(pp_unpack)
                    Copy(s, &auint, 1, unsigned int);
                    s += sizeof(unsigned int);
                    sv = NEWSV(41, 0);
-                   sv_setiv(sv, (I32)auint);
+                   if (auint <= I32_MAX)
+                       sv_setiv(sv, (I32)auint);
+                   else
+                       sv_setnv(sv, (double)auint);
                    PUSHs(sv_2mortal(sv));
                }
            }