double argument casting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,


I work with GCC4.5.1 version with SPARC-V8 target.

Working for embedded systems, I would be please to improve the code density.

When a caller function calls a callee function with short or char
arguments, the arguments are casted twice: inside the caller function
and inside the callee function, see the example. It is a waste of
performance in code density and speed!

I don't understand why there is a double casting.  Is there any
optimization I could activate in GCC to remove it?


   Best wishes,

   Laurent poche






Example:

sparc-elf-gcc -o test.elf test.c -Os



short somme(char a, short b){
  int i;
  for (i=0; i<b; i++){
    a+=a;
  }
  return a+b;
}
short somme2(char a, short b){
  int i;
  for (i=0; i<b; i++){
    a+=b;
  }
  return a+2*b;
}
int main(){
  volatile short b=1;
  volatile char a=1, c=1;
  b=somme(a,b);
  b=somme(c,b);
  b=somme(a,c);
  b=somme2(a,b);
  b=somme2(c,b);
  b=somme2(a,c);
  return 0;
}


0001024c <somme>:
   1024c:    85 2a 60 10     sll  %o1, 0x10, %g2
   10250:    82 10 20 00     clr  %g1
   10254:    10 80 00 03     b  10260 <somme+0x14>
   10258:    85 38 a0 10     sra  %g2, 0x10, %g2
   1025c:    82 00 60 01     inc  %g1
   10260:    80 a0 40 02     cmp  %g1, %g2
   10264:    26 bf ff fe     bl,a   1025c <somme+0x10>
   10268:    91 2a 20 01     sll  %o0, 1, %o0
   1026c:    91 2a 20 18     sll  %o0, 0x18, %o0
   10270:    91 3a 20 18     sra  %o0, 0x18, %o0
   10274:    81 c3 e0 08     retl
   10278:    90 02 40 08     add  %o1, %o0, %o0


000102b4 <main>:
   102b4:    9d e3 bf 98     save  %sp, -104, %sp
   102b8:    82 10 20 01     mov  1, %g1
   102bc:    c2 37 bf fc     sth  %g1, [ %fp + -4 ]
   102c0:    c2 2f bf ff     stb  %g1, [ %fp + -1 ]
   102c4:    c2 2f bf fe     stb  %g1, [ %fp + -2 ]
   102c8:    d0 0f bf ff     ldub  [ %fp + -1 ], %o0
   102cc:    d2 17 bf fc     lduh  [ %fp + -4 ], %o1
   102d0:    91 2a 20 18     sll  %o0, 0x18, %o0
   102d4:    93 2a 60 10     sll  %o1, 0x10, %o1
   102d8:    91 3a 20 18     sra  %o0, 0x18, %o0
   102dc:    7f ff ff dc     call  1024c <somme>
   102e0:    93 3a 60 10     sra  %o1, 0x10, %o1
      ...





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux