 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Thu Jan 13, 2005 8:06 pm Post subject: gcc 128-bits bug. |
|
|
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: | #include <tamtypes.h>
void foobar(int a, int b, int c, int d, int e, int f, int g, int h, u128 i);
void test() {
foobar(1, 2, 3, 4, 5, 6, 7, 8, 9);
} |
That will generate:
| Code: | 00000000 <test>:
0: 27bdffd0 addiu sp,sp,-48
4: ffbf0020 sd ra,32(sp)
8: ffbe0010 sd s8,16(sp)
c: 03a0f02d move s8,sp
10: 700014a9 por v0,zero,zero
14: 24020009 li v0,9
18: 7fa20000 sq v0,0(sp)
1c: 24040001 li a0,1
20: 24050002 li a1,2
24: 24060003 li a2,3
28: 24070004 li a3,4
2c: 24080005 li t0,5
30: 24090006 li t1,6
34: 240a0007 li t2,7
38: 0c000000 jal 0 <test>
38: R_MIPS_26 foobar
3c: 240b0008 li t3,8
40: 03c0e82d move sp,s8
44: dfbf0020 ld ra,32(sp)
48: dfbe0010 ld s8,16(sp)
4c: 03e00008 jr ra
50: 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. _________________ pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department. |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Thu Jan 13, 2005 9:45 pm Post subject: |
|
|
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 ;) _________________ pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|