Page 1 of 1

gcc 128-bits bug.

Posted: Thu Jan 13, 2005 8:06 pm
by pixel
Just to warn you that I've discovered a bug in the current toolchain when dealing with 128 bits data. Here is an example:

Code: Select all

#include <tamtypes.h>

void foobar&#40;int a, int b, int c, int d, int e, int f, int g, int h, u128 i&#41;;

void test&#40;&#41; &#123;
    foobar&#40;1, 2, 3, 4, 5, 6, 7, 8, 9&#41;;
&#125;
That will generate:

Code: Select all

00000000 <test>&#58;
   0&#58;   27bdffd0        addiu   sp,sp,-48
   4&#58;   ffbf0020        sd      ra,32&#40;sp&#41;
   8&#58;   ffbe0010        sd      s8,16&#40;sp&#41;
   c&#58;   03a0f02d        move    s8,sp
  10&#58;   700014a9        por     v0,zero,zero
  14&#58;   24020009        li      v0,9
  18&#58;   7fa20000        sq      v0,0&#40;sp&#41;
  1c&#58;   24040001        li      a0,1
  20&#58;   24050002        li      a1,2
  24&#58;   24060003        li      a2,3
  28&#58;   24070004        li      a3,4
  2c&#58;   24080005        li      t0,5
  30&#58;   24090006        li      t1,6
  34&#58;   240a0007        li      t2,7
  38&#58;   0c000000        jal     0 <test>
                        38&#58; R_MIPS_26   foobar
  3c&#58;   240b0008        li      t3,8
  40&#58;   03c0e82d        move    sp,s8
  44&#58;   dfbf0020        ld      ra,32&#40;sp&#41;
  48&#58;   dfbe0010        ld      s8,16&#40;sp&#41;
  4c&#58;   03e00008        jr      ra
  50&#58;   27bd0030        addiu   sp,sp,48
That is, the 9th argument is placed onstack (the sq v0, 0(sp)) and AFAIK, the stack is 64-bits aligned, not 128 bits, and gcc obviously doesn't do any work here to align the stack pointer before doing the sq. So this code have a 50% success rate. This does apply to varargs as well.

Posted: Thu Jan 13, 2005 9:45 pm
by pixel
Okaaaay, after some talks on IRC, and some investigations, it seems that our nice gcc is doing 16-bytes alignments when setting up the stack, so that it knows where is the current arguments. Adding another argument to the previous code gives correct code. Sorry for the confusion ;)