6 Replies Latest reply on Dec 2, 2013 8:24 AM by savin.zlobec

    sourceryg++-2013.05-nios2 custom DF insn broken

    savin.zlobec

      Hi,

       

      I just took the nios2 sourceryg++-2013.05 for a test. Looks good, but the custom DF instructions are severely broken.

       

      The compiler will segfault compiling the following code:

       

      ---

      #include <ieeefp.h>

       

      int A(double n)

      {

        return isnan(n);

      }

       

      int B(double n)

      {

        return finite(n);

      }

      ---

       

      If following flags are used: nios2-elf-gcc -Wall -mcustom-frdxlo=0 -mcustom-frdxhi=1 -mcustom-frdy=2 -mcustom-fwrx=3

      -mcustom-fwry=4 -mcustom-fcmpned=5 -mcustom-fcmpeqd=6 -mcustom-fcmpltd=7 -mcustom-fcmpled=8 -mcustom-fcmpgtd=9

      -mcustom-fcmpged=10

       

      Avoiding builtin isnan and finine using fpclassify seems to work. But still the generated code for custom insn DF compare is

      wrong. A simple testcase:

       

      ---

      int C(double n)

      {

        return (n != 0) ? 11 : 22;

      }

      ---

       

      Will compile to:

       

         0:    defffd04     addi    sp,sp,-12

         4:    df000215     stw    fp,8(sp)

         8:    df000204     addi    fp,sp,8

         c:    e13ffe15     stw    r4,-8(fp)

        10:    e17fff15     stw    r5,-4(fp)

        14:    e13ffe17     ldw    r4,-8(fp)

        18:    e17fff17     ldw    r5,-4(fp)

        1c:    0005883a     mov    r2,zero

        20:    0007883a     mov    r3,zero

        24:    2141c0f2     custom    3,zero,r4,r5

        28:    10c5c172     custom    5,r2,r2,r3

        2c:    1000021e     bne    r2,zero,38 <C+0x38>

        30:    008002c4     movi    r2,11

        34:    00000106     br    3c <C+0x3c>

        38:    00800584     movi    r2,22

        3c:    e037883a     mov    sp,fp

        40:    df000017     ldw    fp,0(sp)

        44:    dec00104     addi    sp,sp,4

        48:    f800283a     ret

       

      Where old gcc version 3.4.6 from Altera produces correct code:

       

         0:    defffc04     addi    sp,sp,-16

         4:    df000315     stw    fp,12(sp)

         8:    df000304     addi    fp,sp,12

         c:    e13ffd15     stw    r4,-12(fp)

        10:    e17ffe15     stw    r5,-8(fp)

        14:    e13ffd17     ldw    r4,-12(fp)

        18:    e17ffe17     ldw    r5,-8(fp)

        1c:    0005883a     mov    r2,zero

        20:    0007883a     mov    r3,zero

        24:    2141c0f2     custom    3,zero,r4,r5

        28:    10c3c172     custom    5,at,r2,r3

        2c:    0800011e     bne    at,zero,34 <C+0x34>

        30:    00000306     br    40 <C+0x40>

        34:    008002c4     movi    r2,11

        38:    e0bfff15     stw    r2,-4(fp)

        3c:    00000206     br    48 <C+0x48>

        40:    00800584     movi    r2,22

        44:    e0bfff15     stw    r2,-4(fp)

        48:    e0bfff17     ldw    r2,-4(fp)

        4c:    df000317     ldw    fp,12(sp)

        50:    dec00404     addi    sp,sp,16

        54:    f800283a     ret