public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/4346: wrong float multiply with Sparc
@ 2001-09-18  5:56 tassart
  0 siblings, 0 replies; 2+ messages in thread
From: tassart @ 2001-09-18  5:56 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4346
>Category:       c
>Synopsis:       wrong float multiply with Sparc
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 18 05:56:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Stephan Tassart
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
SunOS 5.7 Generic_106541-16 sun4u sparc SUNW,Ultra-5_10
>Description:
#include <stdio.h>

int main(int argv, char *argc[]) {
  float a1;
  double acc;
  a1 = -1.83351052f;
  acc = a1*a1;
  printf("%.40g\n",acc);
  return 0;
}

/* This code compiles wrong the floating multiplication 
on Sparc. It produces 
	ld	[%fp-20], %f2
	ld	[%fp-20], %f3
	fmuls	%f2, %f3, %f2
	fstod	%f2, %f4

i.e. 
  float32 x float32 -> float32
  cast(float32)     -> float64

Instead of

	ld	[%fp-20], %f2
	ld	[%fp-20], %f3
	fsmuld	%f2, %f3, %f4

i.e.
 float32 x float32 -> float64 


This produces a loss of a precision in the floating
point multiplication. (and because of this loss, same
code compiled on another plateform produces a different
output)
 */


>How-To-Repeat:
compile on sparc the forementionned code with 

gcc -S foo.c -o foo.s 
>Fix:
Dunno
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c/4346: wrong float multiply with Sparc
@ 2001-09-28 21:26 aoliva
  0 siblings, 0 replies; 2+ messages in thread
From: aoliva @ 2001-09-28 21:26 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, tassart

Synopsis: wrong float multiply with Sparc

State-Changed-From-To: open->closed
State-Changed-By: aoliva
State-Changed-When: Fri Sep 28 21:26:28 2001
State-Changed-Why:
    GCC is correct, as far as the code you wrote goes.  There's no reason to do the multiplication that outputs a double; in fact, this could even give incorrect results in case the algorithm depended on the multiplication being performed in float, and only then converted to double, which is what the code asks for.  Perhaps if you convert the operands of the multiplication to double, GCC will do the multiplication the way you expect.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4346&database=gcc


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-09-28 21:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-18  5:56 c/4346: wrong float multiply with Sparc tassart
2001-09-28 21:26 aoliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).