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 00:50:36 +0900

 riastradh@ wrote:
 
 > 	lwc1	$f0,36(sp)
 > 	lwc1	$f1,32(sp)
 > 	swc1	$f0,44(sp)
 > 	swc1	$f1,40(sp)
 > 
 > So the load and store of $f0 are separated by an instruction that
 > doesn't involve $f0, and similarly for $f1.
 > 
 > Do you see any nops there that appear to be needed?
 
 I wonder how many nops are actually required for the FP coprocessor
 (i.e. from/to a different chip) registers..
 
 > It would be nice if we could isolate this to a smaller subroutine than
 > dtoa, which is gigantic.
 
 The following diff against dtoa.c reduces outputs a bit
 (requires "DBG="-O2 -Wno-error=uninitialized -Wno-error=unused-variable
  -Wno-error=unused-but-set-variable -Wno-error=maybe-uninitialized
  -Wno-error=unused-label"):
 
 ---
 Index: gdtoa/dtoa.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/gdtoa/dtoa.c,v
 retrieving revision 1.10
 diff -u -p -d -r1.10 dtoa.c
 --- gdtoa/dtoa.c	16 May 2012 17:48:59 -0000	1.10
 +++ gdtoa/dtoa.c	14 Nov 2023 15:41:55 -0000
 @@ -148,6 +148,7 @@ dtoa
  #endif /*}}*/
  #endif /*}*/
  
 +#if 0
  #ifndef MULTIPLE_THREADS
  	if (dtoa_result) {
  		freedtoa(dtoa_result);
 @@ -259,6 +260,7 @@ dtoa
  		denorm = 1;
  		}
  #endif
 +#endif
  	ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
  	k = (int)ds;
  	if (ds < 0. && ds != k)
 @@ -331,6 +333,7 @@ dtoa
  				i = 1;
  		}
  	s = s0 = rv_alloc((size_t)i);
 +#if 0
  	if (s == NULL)
  		return NULL;
  
 @@ -838,5 +841,6 @@ dtoa
  	*decpt = k + 1;
  	if (rve)
  		*rve = s;
 +#endif
  	return s0;
  	}
 
 ---
 
 --- /tmp/dtoa-small-inline-rfs.s	2023-11-15 00:38:15.396489398 +0900
 +++ /tmp/dtoa-small-noinline-rfs.s	2023-11-15 00:38:14.084341125 +0900
 [...]
      :	44831000 	mtc1	v1,$f2
      :	c4800004 	lwc1	$f0,4(a0)
      :	00001025 	move	v0,zero
      :	44821800 	mtc1	v0,$f3
      :	c4810000 	lwc1	$f1,0(a0)
      :	8f820000 	lw	v0,0(gp)
      :	46201001 	sub.d	$f0,$f2,$f0
      :	c4420004 	lwc1	$f2,4(v0)
 +    :	00000000 	nop
      :	c4430000 	lwc1	$f3,0(v0)
      :	8f820000 	lw	v0,0(gp)
      :	46220002 	mul.d	$f0,$f0,$f2
      :	c4420004 	lwc1	$f2,4(v0)
 +    :	00000000 	nop
      :	c4430000 	lwc1	$f3,0(v0)
 +    :	00000000 	nop
      :	46220000 	add.d	$f0,$f0,$f2
      :	44801000 	mtc1	zero,$f2
 +    :	00000000 	nop
      :	44801800 	mtc1	zero,$f3
      :	00000000 	nop
      :	46220000 	add.d	$f0,$f0,$f2
      :	4622003c 	c.lt.d	$f0,$f2
      :	4442f800 	cfc1	v0,$31
      :	4442f800 	cfc1	v0,$31
      :	00000000 	nop
      :	34410003 	ori	at,v0,0x3
      :	38210002 	xori	at,at,0x2
      :	44c1f800 	ctc1	at,$31
      :	00000000 	nop
      :	462000a4 	cvt.w.d	$f2,$f0
      :	44c2f800 	ctc1	v0,$31
      :	00000000 	nop
      :	44021000 	mfc1	v0,$f2
 -    :	4501002b 	bc1t	140 <__dtoa+0x140>
 +    :	4501002d 	bc1t	180 <__dtoa+0x174>
      :	00000000 	nop
      :	2c430017 	sltiu	v1,v0,23
 -    :	10600010 	beqz	v1,e0 <__dtoa+0xe0>
 +    :	10600010 	beqz	v1,118 <__dtoa+0x10c>
      :	2cc3000a 	sltiu	v1,a2,10
      :	8f830000 	lw	v1,0(gp)
      :	000220c0 	sll	a0,v0,0x3
      :	00641821 	addu	v1,v1,a0
      :	00002825 	move	a1,zero
      :	c4600004 	lwc1	$f0,4(v1)
      :	44851000 	mtc1	a1,$f2
      :	00002025 	move	a0,zero
      :	c4610000 	lwc1	$f1,0(v1)
      :	44841800 	mtc1	a0,$f3
      :	00000000 	nop
      :	4620103c 	c.lt.d	$f2,$f0
      :	00000000 	nop
 [...]
 
 ---
 Izumi Tsutsui
 


Home | Main Index | Thread Index | Old Index