Jon Berndt writes:
> 
> Are there any reasons to choose one method over the other in the declaration
> of local variables that are used each frame?
> 
> Here are some examples. Note that this hypothetical routine would be called
> each pass through the EOM (for example):
> 

< following use local variables for local temporaries >
> ============= Method 1)
> ============= Method 2)

These should be equivalant


< following uses class variables for local temporaries > 
> ============= Method 3)

This will use a memory store to the class variable which may or may not
happen when using local variables. 
i.e an optimizing compiler will just use register 'space' for the temporaries 
if fpu stack or register 'space' permits

Of course the only way to really tell is to profile

HTH

Norman


==== cut jon.cpp ====

#include <math.h>
extern float abc;

float testa(float a, float b)
{
    abc = sin(a);
    return abc + b;
}

float testb(float a, float b)
{
    float abc = sin(a);
    return abc + b;
}

=== cut resultant assembly for gcc -O2 jon.cpp ===

        .file   "jon.cpp"
        .text
        .align 2
        .p2align 4,,15
.globl __Z5testaff
        .def    __Z5testaff;    .scl    2;      .type   32;     .endef
__Z5testaff:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        flds    8(%ebp)
        fstpl   (%esp)
        call    _sin
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fsts    _abc
        fadds   12(%ebp)
        movl    %ebp, %esp
        popl    %ebp
        ret
        .align 2
        .p2align 4,,15
.globl __Z5testbff
        .def    __Z5testbff;    .scl    2;      .type   32;     .endef
__Z5testbff:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        flds    8(%ebp)
        fstpl   (%esp)
        call    _sin
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fadds   12(%ebp)
        movl    %ebp, %esp
        popl    %ebp
        ret
        .def    _sin;   .scl    2;      .type   32;     .endef


_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to