This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

EGCS: pointer to member functions.


egcs-1.1.2 powerpc-linux-crosscompiler, RedHat 5.2 Linux.

I am implementing a finate state machine using a 2 dimensional array.  I
decided that the FSM actions would be member funtions of an FSM class.
I had a look at the generated assembly and am quite astonished at the
code that is generated.  Why is there so much overhead in calling a
function via a pointer as apposed to calling it directly ?  I'm not sure
why there are comparison statements (cmpwi).  The .cpp and .s files
follow.

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

class FOO
{    public :
        void    f1();
};

extern FOO foo;
void (FOO::*fp)();  // pointer to FOO member function.

void direct()
{
    foo.f1();
}

void indirect()
{
    (foo.*fp)();
}

--------------------------------------------
   .file   "foo.cpp"

 # rs6000/powerpc options: -mcpu=860 -msdata=data -G 8
 # GNU C++ version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(powerpc-linux) compiled by GNU C version egcs-2.91.66 19990314
(egcs-1.1.2 release).
 # options passed:  -mcpu=860 -O4 -Wall -Werror -fverbose-asm
 # options enabled:  -fdefer-pop -fomit-frame-pointer -fcse-follow-jumps

 # -fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
 # -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
 # -finline-functions -finline -fkeep-static-consts -fcaller-saves
 # -fpcc-struct-return -fgcse -frerun-cse-after-loop -frerun-loop-opt
 # -fschedule-insns -fschedule-insns2 -fsched-interblock -fsched-spec
 # -fexceptions -fsjlj-exceptions -fcommon -fverbose-asm -fgnu-linker
 # -fregmove -foptimize-register-move -fargument-alias -mpowerpc
 # -mnew-mnemonics -msoft-float -mcpu=860 -mcall-sysv -msdata=data

gcc2_compiled.:
    .section    ".text"
    .align 2
    .globl indirect__Fv
    .type    indirect__Fv,@function
indirect__Fv:
    stwu 1,-16(1)
    mflr 0
    stw 0,20(1)
    addis 9,0,fp@ha
    addi 9,9,fp@l
    lha 11,2(9)
    cmpwi 0,11,0
    bc 4,1,.L4
    lha 10,4(9)
    addis 9,0,foo@ha
    addi 9,9,foo@l
    lwzx 0,10,9
    slwi 11,11,2
    add 11,11,0
    lwz 11,-4(11)
    b .L5
.L4:
    lwz 11,4(9)
.L5:
    addis 9,0,fp@ha
    lha 0,fp@l(9)
    addis 3,0,foo@ha
    addi 3,3,foo@l
    add 3,0,3
    mtlr 11
    blrl
    lwz 0,20(1)
    mtlr 0
    la 1,16(1)
    blr
.Lfe1:
    .size    indirect__Fv,.Lfe1-indirect__Fv
    .align 2
    .globl direct__Fv
    .type    direct__Fv,@function
direct__Fv:
    stwu 1,-16(1)
    mflr 0
    stw 0,20(1)
    addis 3,0,foo@ha
    addi 3,3,foo@l
    bl f1__3FOO
    lwz 0,20(1)
    mtlr 0
    la 1,16(1)
    blr
.Lfe2:
    .size    direct__Fv,.Lfe2-direct__Fv
    .globl fp
    .section    ".sdata","aw"
    .align 2
fp:
    .space  8
    .size    fp,8
    .ident  "GCC: (GNU) egcs-2.91.66 19990314 (egcs-1.1.2 release)"
--------------------------------------------



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]