[uClibc]0.9.19 mipsel floating point printf problem?

Marshall M. Midden m4 at brecis.com
Fri May 16 22:54:46 UTC 2003


There are two needs for floating point numbers.

"mips-objdump -hpDSxdlr" your test program .o file.

See which registers are used for the call to printf.

> From uclibc-bounces at uclibc.org Fri May 16 15:31:09 2003
>  
> > My test program has been this trivial program:
> > 
> >     float a = 1.0, b = 5.0;
> > 
> >     printf("Hello\n");
> >     f = a / b;
> >     printf("f is now %g\n", f);

The reason?  float (really double) must be aligned on even registers.
(And on the stack [mod 8] if the stack is used!)

Here is my .c:

#include <stdio.h>

int main()
{
  float a = 1.0, b = 5.0;
  float f;

  printf("Hello\n");
  f = a / b;
  printf("f is now %g\n", f);
  exit(0);
}

Here is my .o, with highlights for reading:
    main():
       0:   27bdffd8        addiu   sp,sp,-40
       4:   afbf0024        sw      ra,36(sp)
       8:   afbe0020        sw      s8,32(sp)
       c:   03a0f021        move    s8,sp
      10:   3c013f80        lui     at,0x3f80
      14:   44810000        mtc1    at,$f0
      18:   e7c00010        swc1    $f0,16(s8)
      1c:   3c0140a0        lui     at,0x40a0
      20:   44810000        mtc1    at,$f0
      24:   e7c00014        swc1    $f0,20(s8)
      28:   2784c000        addiu   a0,gp,-16384
			    28: R_MIPS_GPREL16      .sdata+0x4000
      2c:   0c000000        jal     0 <main>
			    2c: R_MIPS_26   printf
      30:   00000000        nop
      34:   c7c20010        lwc1    $f2,16(s8)
      38:   c7c00014        lwc1    $f0,20(s8)
      3c:   46001003        div.s   $f0,$f2,$f0
      40:   e7c00018        swc1    $f0,24(s8)
      44:   c7c00018        lwc1    $f0,24(s8)
      48:   46000021        cvt.d.s $f0,$f0
      4c:   3c040000        lui     a0,0x0
			    4c: R_MIPS_HI16 .rodata
>>    50:   24840000        addiu   a0,a0,0
			    50: R_MIPS_LO16 .rodata
>>    54:   44070000        mfc1    a3,$f0
      58:   0c000000        jal     0 <main>
			    58: R_MIPS_26   printf
>>    5c:   44060800        mfc1    a2,$f1
      60:   0c000000        jal     0 <main>
			    60: R_MIPS_26   exit
      64:   00002021        move    a0,zero


So, a0 = first argument, and a2 & a3 are the floating argument.
(a1 is skipped, as things must be even aligned for registers
and mod 8 if on stack)  [And remember the branch delay slot that is
executed before branch instructions complete.]

Ever wonder why the stack is always changed via mod 8?  Gotta keep
the stack in known state in case "long long" or "double" ("float")
are used.

NOTE: this is a mips big endian.


More information about the uClibc mailing list