target: mips-elf version: 4.4.1 There's a problem where compiling code with -fno-delayed-branch still fills branch delay slots.
[ubxju10]/home/jupiter/tmorita/dhrystone/test 1097 % cat minlib.c #include <stdarg.h> int printf(const char *format, ...) { register int a0 asm ("a0"); register int a1 asm ("a1"); register int a2 asm ("a2"); va_list ap; va_start(ap, format); a0 = 2; a1 = (int)format; a2 = (int)ap; __asm__ volatile ("nop; nop; syscall; nop" : : "r" (a0), "r" (a1), "r" (a2)); va_end(ap); } [ubxju10]/home/jupiter/tmorita/dhrystone/test 1098 % mips-elf-gcc -O2 -fno-delayed-branch -c minlib.c -o minlib.o [ubxju10]/home/jupiter/tmorita/dhrystone/test 1099 % mips-elf-objdump --disassemble minlib.o minlib.o: file format elf32-bigmips Disassembly of section .text: 00000000 <printf>: 0: 27bdfff8 addiu sp,sp,-8 4: 27a2000c addiu v0,sp,12 8: afa5000c sw a1,12(sp) c: afa60010 sw a2,16(sp) 10: 00802821 move a1,a0 14: afa70014 sw a3,20(sp) 18: afa20000 sw v0,0(sp) 1c: 00403021 move a2,v0 20: 24040002 li a0,2 ... 2c: 0000000c syscall 30: 00000000 nop 34: 03e00008 jr ra 38: 27bd0008 addiu sp,sp,8 <- branch delay slot filled [ubxju10]/home/jupiter/tmorita/dhrystone/test 1100 % The problem appears to be caused with GNU AS. It now has the capability to reorder instructions, and there is no ".set noreorder" emitted by the compiler, so the assembler fills the branch delay slot. [ubxju10]/home/jupiter/tmorita/dhrystone/test 1104 % cat test.s .text addiu $sp,$sp,8 jr $ra [ubxju10]/home/jupiter/tmorita/dhrystone/test 1105 % mips-elf-as test.s -o test.o [ubxju10]/home/jupiter/tmorita/dhrystone/test 1106 % mips-elf-objdump --disassemble test.o test.o: file format elf32-bigmips Disassembly of section .text: 00000000 <.text>: 0: 03e00008 jr ra 4: 27bd0008 addiu sp,sp,8 [ubxju10]/home/jupiter/tmorita/dhrystone/test 1107 % So when the -fno-delayed-branch switch is passed to mips-elf-gcc, a ".set noreorder" directive should be emitted into the assembly file. Toshi