diff options
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 174 |
1 files changed, 87 insertions, 87 deletions
@@ -921,28 +921,30 @@ PP(pp_postdec) PP(pp_pow) { - dVAR; dSP; dATARGET; + dVAR; dSP; dATARGET; SV *svl, *svr; #ifdef PERL_PRESERVE_IVUV bool is_int = 0; #endif tryAMAGICbin(pow,opASSIGN); + svl = sv_2num(TOPm1s); + svr = sv_2num(TOPs); #ifdef PERL_PRESERVE_IVUV /* For integer to integer power, we do the calculation by hand wherever we're sure it is safe; otherwise we call pow() and try to convert to integer afterwards. */ { - SvIV_please(TOPs); - if (SvIOK(TOPs)) { - SvIV_please(TOPm1s); - if (SvIOK(TOPm1s)) { + SvIV_please(svr); + if (SvIOK(svr)) { + SvIV_please(svl); + if (SvIOK(svl)) { UV power; bool baseuok; UV baseuv; - if (SvUOK(TOPs)) { - power = SvUVX(TOPs); + if (SvUOK(svr)) { + power = SvUVX(svr); } else { - const IV iv = SvIVX(TOPs); + const IV iv = SvIVX(svr); if (iv >= 0) { power = iv; } else { @@ -950,11 +952,11 @@ PP(pp_pow) } } - baseuok = SvUOK(TOPm1s); + baseuok = SvUOK(svl); if (baseuok) { - baseuv = SvUVX(TOPm1s); + baseuv = SvUVX(svl); } else { - const IV iv = SvIVX(TOPm1s); + const IV iv = SvIVX(svl); if (iv >= 0) { baseuv = iv; baseuok = TRUE; /* effectively it's a UV now */ @@ -989,7 +991,7 @@ PP(pp_pow) } SP--; SETn( result ); - SvIV_please(TOPs); + SvIV_please(svr); RETURN; } else { register unsigned int highbit = 8 * sizeof(UV); @@ -1082,7 +1084,7 @@ PP(pp_pow) #ifdef PERL_PRESERVE_IVUV if (is_int) - SvIV_please(TOPs); + SvIV_please(svr); #endif RETURN; } @@ -1090,18 +1092,21 @@ PP(pp_pow) PP(pp_multiply) { - dVAR; dSP; dATARGET; tryAMAGICbin(mult,opASSIGN); + dVAR; dSP; dATARGET; SV *svl, *svr; + tryAMAGICbin(mult,opASSIGN); + svl = sv_2num(TOPm1s); + svr = sv_2num(TOPs); #ifdef PERL_PRESERVE_IVUV - SvIV_please(TOPs); - if (SvIOK(TOPs)) { + SvIV_please(svr); + if (SvIOK(svr)) { /* Unless the left argument is integer in range we are going to have to use NV maths. Hence only attempt to coerce the right argument if we know the left is integer. */ /* Left operand is defined, so is it IV? */ - SvIV_please(TOPm1s); - if (SvIOK(TOPm1s)) { - bool auvok = SvUOK(TOPm1s); - bool buvok = SvUOK(TOPs); + SvIV_please(svl); + if (SvIOK(svl)) { + bool auvok = SvUOK(svl); + bool buvok = SvUOK(svr); const UV topmask = (~ (UV)0) << (4 * sizeof (UV)); const UV botmask = ~((~ (UV)0) << (4 * sizeof (UV))); UV alow; @@ -1110,9 +1115,9 @@ PP(pp_multiply) UV bhigh; if (auvok) { - alow = SvUVX(TOPm1s); + alow = SvUVX(svl); } else { - const IV aiv = SvIVX(TOPm1s); + const IV aiv = SvIVX(svl); if (aiv >= 0) { alow = aiv; auvok = TRUE; /* effectively it's a UV now */ @@ -1121,9 +1126,9 @@ PP(pp_multiply) } } if (buvok) { - blow = SvUVX(TOPs); + blow = SvUVX(svr); } else { - const IV biv = SvIVX(TOPs); + const IV biv = SvIVX(svr); if (biv >= 0) { blow = biv; buvok = TRUE; /* effectively it's a UV now */ @@ -1197,8 +1202,8 @@ PP(pp_multiply) } } /* product_middle too large */ } /* ahigh && bhigh */ - } /* SvIOK(TOPm1s) */ - } /* SvIOK(TOPs) */ + } /* SvIOK(svl) */ + } /* SvIOK(svr) */ #endif { dPOPTOPnnrl; @@ -1209,7 +1214,10 @@ PP(pp_multiply) PP(pp_divide) { - dVAR; dSP; dATARGET; tryAMAGICbin(div,opASSIGN); + dVAR; dSP; dATARGET; SV *svl, *svr; + tryAMAGICbin(div,opASSIGN); + svl = sv_2num(TOPm1s); + svr = sv_2num(TOPs); /* Only try to do UV divide first if ((SLOPPYDIVIDE is true) or (PERL_PRESERVE_IVUV is true and one or both SV is a UV too large @@ -1232,20 +1240,20 @@ PP(pp_divide) #endif #ifdef PERL_TRY_UV_DIVIDE - SvIV_please(TOPs); - if (SvIOK(TOPs)) { - SvIV_please(TOPm1s); - if (SvIOK(TOPm1s)) { - bool left_non_neg = SvUOK(TOPm1s); - bool right_non_neg = SvUOK(TOPs); + SvIV_please(svr); + if (SvIOK(svr)) { + SvIV_please(svl); + if (SvIOK(svl)) { + bool left_non_neg = SvUOK(svl); + bool right_non_neg = SvUOK(svr); UV left; UV right; if (right_non_neg) { - right = SvUVX(TOPs); + right = SvUVX(svr); } else { - const IV biv = SvIVX(TOPs); + const IV biv = SvIVX(svr); if (biv >= 0) { right = biv; right_non_neg = TRUE; /* effectively it's a UV now */ @@ -1263,10 +1271,10 @@ PP(pp_divide) DIE(aTHX_ "Illegal division by zero"); if (left_non_neg) { - left = SvUVX(TOPm1s); + left = SvUVX(svl); } else { - const IV aiv = SvIVX(TOPm1s); + const IV aiv = SvIVX(svl); if (aiv >= 0) { left = aiv; left_non_neg = TRUE; /* effectively it's a UV now */ @@ -1338,14 +1346,15 @@ PP(pp_modulo) bool dright_valid = FALSE; NV dright = 0.0; NV dleft = 0.0; - - SvIV_please(TOPs); - if (SvIOK(TOPs)) { - right_neg = !SvUOK(TOPs); + SV * svl; + SV * const svr = sv_2num(TOPs); + SvIV_please(svr); + if (SvIOK(svr)) { + right_neg = !SvUOK(svr); if (!right_neg) { - right = SvUVX(POPs); + right = SvUVX(svr); } else { - const IV biv = SvIVX(POPs); + const IV biv = SvIVX(svr); if (biv >= 0) { right = biv; right_neg = FALSE; /* effectively it's a UV now */ @@ -1353,6 +1362,7 @@ PP(pp_modulo) right = -biv; } } + sp--; } else { dright = POPn; @@ -1370,14 +1380,15 @@ PP(pp_modulo) /* At this point use_double is only true if right is out of range for a UV. In range NV has been rounded down to nearest UV and use_double false. */ - SvIV_please(TOPs); - if (!use_double && SvIOK(TOPs)) { - if (SvIOK(TOPs)) { - left_neg = !SvUOK(TOPs); + svl = sv_2num(TOPs); + SvIV_please(svl); + if (!use_double && SvIOK(svl)) { + if (SvIOK(svl)) { + left_neg = !SvUOK(svl); if (!left_neg) { - left = SvUVX(POPs); + left = SvUVX(svl); } else { - const IV aiv = SvIVX(POPs); + const IV aiv = SvIVX(svl); if (aiv >= 0) { left = aiv; left_neg = FALSE; /* effectively it's a UV now */ @@ -1385,6 +1396,7 @@ PP(pp_modulo) left = -aiv; } } + sp--; } } else { @@ -1581,13 +1593,16 @@ PP(pp_repeat) PP(pp_subtract) { - dVAR; dSP; dATARGET; bool useleft; tryAMAGICbin(subtr,opASSIGN); - useleft = USE_LEFT(TOPm1s); + dVAR; dSP; dATARGET; bool useleft; SV *svl, *svr; + tryAMAGICbin(subtr,opASSIGN); + svl = sv_2num(TOPm1s); + svr = sv_2num(TOPs); + useleft = USE_LEFT(svl); #ifdef PERL_PRESERVE_IVUV /* See comments in pp_add (in pp_hot.c) about Overflow, and how "bad things" happen if you rely on signed integers wrapping. */ - SvIV_please(TOPs); - if (SvIOK(TOPs)) { + SvIV_please(svr); + if (SvIOK(svr)) { /* Unless the left argument is integer in range we are going to have to use NV maths. Hence only attempt to coerce the right argument if we know the left is integer. */ @@ -1601,12 +1616,12 @@ PP(pp_subtract) /* left operand is undef, treat as zero. */ } else { /* Left operand is defined, so is it IV? */ - SvIV_please(TOPm1s); - if (SvIOK(TOPm1s)) { - if ((auvok = SvUOK(TOPm1s))) - auv = SvUVX(TOPm1s); + SvIV_please(svl); + if (SvIOK(svl)) { + if ((auvok = SvUOK(svl))) + auv = SvUVX(svl); else { - register const IV aiv = SvIVX(TOPm1s); + register const IV aiv = SvIVX(svl); if (aiv >= 0) { auv = aiv; auvok = 1; /* Now acting as a sign flag. */ @@ -1621,12 +1636,12 @@ PP(pp_subtract) bool result_good = 0; UV result; register UV buv; - bool buvok = SvUOK(TOPs); + bool buvok = SvUOK(svr); if (buvok) - buv = SvUVX(TOPs); + buv = SvUVX(svr); else { - register const IV biv = SvIVX(TOPs); + register const IV biv = SvIVX(svr); if (biv >= 0) { buv = biv; buvok = 1; @@ -1683,7 +1698,6 @@ PP(pp_subtract) } } #endif - useleft = USE_LEFT(TOPm1s); { dPOPnv; if (!useleft) { @@ -2373,7 +2387,7 @@ PP(pp_negate) { dVAR; dSP; dTARGET; tryAMAGICun(neg); { - dTOPss; + SV * const sv = sv_2num(TOPs); const int flags = SvFLAGS(sv); SvGETMAGIC(sv); if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) { @@ -2874,26 +2888,13 @@ PP(pp_int) { dVAR; dSP; dTARGET; tryAMAGICun(int); { - dTOPss; - IV iv; + SV * const sv = sv_2num(TOPs); + const IV iv = SvIV(sv); /* XXX it's arguable that compiler casting to IV might be subtly different from modf (for numbers inside (IV_MIN,UV_MAX)) in which else preferring IV has introduced a subtle behaviour change bug. OTOH relying on floating point to be accurate is a bug. */ - while (SvAMAGIC(sv)) { - SV *tsv = AMG_CALLun(sv,numer); - if (!tsv) - break; - if (SvROK(tsv) && SvRV(tsv) == SvRV(sv)) { - SETu(PTR2UV(SvRV(sv))); - RETURN; - } - else - sv = tsv; - } - iv = SvIV(sv); /* attempt to convert to IV if possible. */ - if (!SvOK(sv)) { SETu(0); } @@ -2903,9 +2904,6 @@ PP(pp_int) else SETi(iv); } - else if (SvROK(sv)) { - SETu(PTR2UV(SvRV(sv))); - } else { const NV value = SvNV(sv); if (value >= 0.0) { @@ -2931,15 +2929,17 @@ PP(pp_abs) { dVAR; dSP; dTARGET; tryAMAGICun(abs); { + SV * const sv = sv_2num(TOPs); /* This will cache the NV value if string isn't actually integer */ - const IV iv = TOPi; + const IV iv = SvIV(sv); - if (!SvOK(TOPs)) + if (!SvOK(sv)) { SETu(0); - else if (SvIOK(TOPs)) { + } + else if (SvIOK(sv)) { /* IVX is precise */ - if (SvIsUV(TOPs)) { - SETu(TOPu); /* force it to be numeric only */ + if (SvIsUV(sv)) { + SETu(SvUV(sv)); /* force it to be numeric only */ } else { if (iv >= 0) { SETi(iv); @@ -2954,7 +2954,7 @@ PP(pp_abs) } } } else{ - const NV value = TOPn; + const NV value = SvNV(sv); if (value < 0.0) SETn(-value); else |