develooper Front page | perl.perl5.porters | Postings from October 2000

pp_add -> pp_i_add efficiency hack?

Thread Next
From:
Simon Cozens
Date:
October 5, 2000 03:07
Subject:
pp_add -> pp_i_add efficiency hack?
Message ID:
20001005110301.A32445@the.earth.li
So, I'm trying to describe what an PVIV is, and the way to do that is to
generate one. OK, so...

% ./perl -Ilib -MDevel::Peek -e '$a="12";$a+=1; Dump($a)'
SV = PVNV(0x80f3c98) at 0x80fcf30
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  IV = 0
  NV = 13
  PV = 0x8101b40 "12"\0
  CUR = 2
  LEN = 3

Argh. Hang on, I didn't do anything floating point. Why has it upgraded to
PVNV?

We have two addition ops: one for integers, (pp_i_add) and one for 
non-integers. (pp_add) If "use integer" is in force, Perl can change
pp_add to pp_i_add at compile time, during the constant-folding stage.
Otherwise, at runtime, you have to go through pp_add which pops NVs off
the stack. This means that your SV gets upgraded to PVNV, possibly 
needlessly.

Would it be an efficiency hack to say the moral equivalent of

    if(SvIOK(left) && SvIOK(right))
        pp_i_add();

and save the upgrade?

-- 
"I will make no bargains with terrorist hardware."
-- Peter da Silva

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About