NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-mips/57680: printf("%.1f") shows wrong results on R3000mipseb



The following reply was made to PR port-mips/57680; it has been noted by GNATS.

From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: riastradh%NetBSD.org@localhost
Cc: gnats-bugs%netbsd.org@localhost, tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: port-mips/57680: printf("%.1f") shows wrong results on R3000mipseb
Date: Wed, 15 Nov 2023 23:30:45 +0900

 > >  If you take the _non-working_ intermediate .s file with inline __rfs
 > >  in the source code, and insert nops where the _working_ one has nops
 > >  after lwc1, and then assemble and link it all, does that result work?
 > 
 > I've added intermidiate .s files by --save-temps to gist:
 > 
 > - https://gist.github.com/tsutsui/85b03f26aa1bfd3fdd884bce8fd8c1e7#file-dtoa-save-temps-inline-s
 >    dtoa.s by 'gcc --save-temps' from the original libc source,
 >    i.e. non-working printf
 > 
 > - https://gist.github.com/tsutsui/85b03f26aa1bfd3fdd884bce8fd8c1e7#file-dtoa-save-temps-noinline-s
 >    dtoa.s by 'gcc --save-temps' with __noinline __rfs in <mips/fenv.h>,
 >    working printf
 > 
 > - https://gist.github.com/tsutsui/85b03f26aa1bfd3fdd884bce8fd8c1e7#file-dtoa-save-temps-s-diff
 >    diff between the above two --save-temps .s files
 > 
 > It looks:
 >  - the inline version uses ".set reorder" by default and it puts
 >    ".set noreorder" and ".set nomacro" around branch instructions
 >    (to handle branch delay slot?)
 > 
 >  - the inline version also put '#nop' (commented out nop) after
 >    lwc1 instructions (not confirmed where this comes from)
 
 This '#nop' comes from src/external/gpl3/gcc/dist/gcc/config/mips/mips.md:
  https://github.com/NetBSD/src/blob/netbsd-9/external/gpl3/gcc/dist/gcc/config/mips/mips.md#L7176-L7186
 ---
 ;; Like nop, but commented out when outside a .set noreorder block.
 (define_insn "hazard_nop"
   [(const_int 1)]
   ""
   {
     if (mips_noreorder.nesting_level > 0)
       return "nop";
     else
       return "#nop";
   }
   [(set_attr "type"	"nop")])
 
 ---
 
 I rebuild gcc with the following diff and printf test problem works
 as expected:
 ---
 Index: external/gpl3/gcc/dist/gcc/config/mips/mips.md
 ===================================================================
 RCS file: /cvsroot/src/external/gpl3/gcc/dist/gcc/config/mips/mips.md,v
 retrieving revision 1.1.1.6
 diff -u -p -d -r1.1.1.6 mips.md
 --- external/gpl3/gcc/dist/gcc/config/mips/mips.md	19 Jan 2019 10:14:39 -0000	1.1.1.6
 +++ external/gpl3/gcc/dist/gcc/config/mips/mips.md	15 Nov 2023 14:25:41 -0000
 @@ -7181,7 +7181,7 @@
      if (mips_noreorder.nesting_level > 0)
        return "nop";
      else
 -      return "#nop";
 +      return "nop";
    }
    [(set_attr "type"	"nop")])
  
 ---
 
 Actually dtoa.pico has nops as __noinline __rfs() case:
 ---
       ac:       3c027ff0        lui     v0,0x7ff0
       b0:       02021824        and     v1,s0,v0
       b4:       106200d3        beq     v1,v0,404 <__dtoa+0x3f8>
       b8:       ac800000        sw      zero,0(a0)
       bc:       c7a00024        lwc1    $f0,36(sp)
       c0:       00000000        nop
       c4:       c7a10020        lwc1    $f1,32(sp)
       c8:       00000000        nop
       cc:       e7a0002c        swc1    $f0,44(sp)
       d0:       e7a10028        swc1    $f1,40(sp)
       d4:       c7a2002c        lwc1    $f2,44(sp)
       d8:       44800000        mtc1    zero,$f0
       dc:       c7a30028        lwc1    $f3,40(sp)
 ---
 
 However, IIUC if ".set reorder" is specified in as sources,
 gas(1) should have responsibilities to insert necessary nops
 to avoid hazards?
 
 ---
 Izumi Tsutsui
  
 


Home | Main Index | Thread Index | Old Index