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: simonb%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: Tue, 14 Nov 2023 01:31:10 +0900

 simonb@ wrote:
 
 > Can you please try this experiment to hopefully rule in/out simple CP1 hazards?
 > 
 > In sys/arch/mips/include/fenv.h change __rfs() to add two nops before using
 > the result:
 > 
 > 	__asm __volatile(
 > 	    ".set push\n"
 > 	    ".set noreorder\n"
 > 	    "cfc1 %0,$31\n"
 > 	    "nop\n"
 > 	    "nop\n"
 > 	    ".set pop" : "=r" (__fpsr));
 
 It looks this doesn't help.
 
 With the original libc:
 ---
 news3470-% objdump -drz /s/netbsd-9/src/lib/libc/obj.newsmips/dtoa.pico | head -40 
 
 /s/netbsd-9/src/lib/libc/obj.newsmips/dtoa.pico:     file format elf32-tradbigmips
 
 
 Disassembly of section .text:
 
 00000000 <__dtoa>:
        0:       3c1c0000        lui     gp,0x0
                         0: R_MIPS_HI16  _gp_disp
        4:       279c0000        addiu   gp,gp,0
                         4: R_MIPS_LO16  _gp_disp
        8:       0399e021        addu    gp,gp,t9
        c:       27bdff88        addiu   sp,sp,-120
       10:       afbc0010        sw      gp,16(sp)
       14:       afb20058        sw      s2,88(sp)
       18:       afbf0074        sw      ra,116(sp)
       1c:       afbe0070        sw      s8,112(sp)
       20:       afb7006c        sw      s7,108(sp)
       24:       afb60068        sw      s6,104(sp)
       28:       afb50064        sw      s5,100(sp)
       2c:       afb40060        sw      s4,96(sp)
       30:       afb3005c        sw      s3,92(sp)
       34:       afb10054        sw      s1,84(sp)
       38:       afb00050        sw      s0,80(sp)
       3c:       e7ac007c        swc1    $f12,124(sp)
       40:       e7ad0078        swc1    $f13,120(sp)
       44:       00c09025        move    s2,a2
       48:       afa70084        sw      a3,132(sp)
       4c:       8fa3008c        lw      v1,140(sp)
       50:       4442f800        cfc1    v0,$31
       54:       00000000        nop
       58:       30420003        andi    v0,v0,0x3
       5c:       2442ffff        addiu   v0,v0,-1
       60:       2c440003        sltiu   a0,v0,3
       64:       108000cb        beqz    a0,394 <__dtoa+0x394>
       68:       24140001        li      s4,1
       6c:       8f840000        lw      a0,0(gp)
                         6c: R_MIPS_GOT16        .rodata
       70:       00021080        sll     v0,v0,0x2
       74:       24840000        addiu   a0,a0,0
 news3470-% env LD_LIBRARY_PATH=/s/netbsd-9/src/lib/libc/obj.newsmips ldd ./a.out
 ./a.out:
         -lc.12 => /s/netbsd-9/src/lib/libc/obj.newsmips/libc.so.12
 news3470-% env LD_LIBRARY_PATH=/s/netbsd-9/src/lib/libc/obj.newsmips ./a.out
 300.0
 314
 ?00.0
 1570
 news3470-% 
 ---
 
 With your patch:
 ---
 news3470-% objdump -drz /s/netbsd-9/src/lib/libc/obj.newsmips/dtoa.pico | head -40 
 
 /s/netbsd-9/src/lib/libc/obj.newsmips/dtoa.pico:     file format elf32-tradbigmips
 
 
 Disassembly of section .text:
 
 00000000 <__dtoa>:
        0:       3c1c0000        lui     gp,0x0
                         0: R_MIPS_HI16  _gp_disp
        4:       279c0000        addiu   gp,gp,0
                         4: R_MIPS_LO16  _gp_disp
        8:       0399e021        addu    gp,gp,t9
        c:       27bdff88        addiu   sp,sp,-120
       10:       afbc0010        sw      gp,16(sp)
       14:       afb20058        sw      s2,88(sp)
       18:       afbf0074        sw      ra,116(sp)
       1c:       afbe0070        sw      s8,112(sp)
       20:       afb7006c        sw      s7,108(sp)
       24:       afb60068        sw      s6,104(sp)
       28:       afb50064        sw      s5,100(sp)
       2c:       afb40060        sw      s4,96(sp)
       30:       afb3005c        sw      s3,92(sp)
       34:       afb10054        sw      s1,84(sp)
       38:       afb00050        sw      s0,80(sp)
       3c:       e7ac007c        swc1    $f12,124(sp)
       40:       e7ad0078        swc1    $f13,120(sp)
       44:       00c09025        move    s2,a2
       48:       afa70084        sw      a3,132(sp)
       4c:       8fa3008c        lw      v1,140(sp)
       50:       4442f800        cfc1    v0,$31
       54:       00000000        nop
       58:       00000000        nop
       5c:       30420003        andi    v0,v0,0x3
       60:       2442ffff        addiu   v0,v0,-1
       64:       2c440003        sltiu   a0,v0,3
       68:       108000cb        beqz    a0,398 <__dtoa+0x398>
       6c:       24140001        li      s4,1
       70:       8f840000        lw      a0,0(gp)
                         70: R_MIPS_GOT16        .rodata
       74:       00021080        sll     v0,v0,0x2
 news3470-% env LD_LIBRARY_PATH=/s/netbsd-9/src/lib/libc/obj.newsmips ./a.out
 300.0
 314
 ?00.0
 1570
 news3470-% 
 ---
 
 I'm trying to check which gcc -ffoo option causes the wrong behaviour,
 but it's a bit hard to analyze..
 
 At least changing ${DESTDIR}/usr/include/mips/fenv.h from
 >> static inline fpu_control_t
 >> __rfs(void)
 to
 >> static __noinline fpu_control_t
 >> __rfs(void)
 also solves the problem, but asm outputs are completely different
 in these two cases.
 
 ---
 Izumi Tsutsui
 


Home | Main Index | Thread Index | Old Index