www.delorie.com/archives/browse.cgi   search  
Mail Archives: pgcc/1998/09/08/08:34:26

X-pop3-spooler: POP3MAIL 2.1.0 b 4 980420 -bs-
Message-Id: <m0zGIrO-0000FVC@chkw386.ch.pwr.wroc.pl>
Date: Tue, 8 Sep 98 08:10
From: strasbur AT chkw386 DOT ch DOT pwr DOT wroc DOT pl (Krzysztof Strasburger)
To: beastium-list AT Desk DOT nl
Subject: -O1 -ffast-math bug on Pentium Pro
Sender: Marc Lehmann <pcg AT goof DOT com>
Status: RO
Lines: 116

I reduced the code size needed to reproduce the bug.
Compiled with -mpentiumpro -O1 -malign-double -malign-jumps=0 -malign-loops=0
-malign-functions=0 -fno-exceptions -traditional -ffast-math.
main() calls fmbug(), should print p=1. Prints p=0.
I hope this will help to fix the bug.
Krzysztof

int main()
{
    double p;
    extern int fmbug();
    p = 1.;
    fmbug(&p);
    printf("p=%f\n",p);
    return 0;
}

The fmbug() function is now very small.

int fmbug(param)
double *param;
{
    double h1;

    h1 = -(*param);
    if (abs(*param) < 1e-10 || h1 > -1e-10) {
	*param = 0.;
    }
    return 0;
}

Here is the asembler output of pgcc-1.1a (fmbug, with fast-math)

	.file	"fmbug.c"
	.version	"01.01"
gcc2_compiled.:
..text
..globl fmbug
	.type	 fmbug,@function
fmbug:
	pushl %ebp
	movl %esp,%ebp
	subl $24,%esp
	movl 8(%ebp),%ecx
	fldl (%ecx)
	fld %st(0)
	fchs
	fxch %st(1)
	fnstcw -4(%ebp)
	movl -4(%ebp),%eax
	movb $12,%ah
	movl %eax,-16(%ebp)
	fldcw -16(%ebp)
	fistpl -20(%ebp)
	fldcw -4(%ebp)
	movl -20(%ebp),%edx
	sarl $31,%edx
	movl -20(%ebp),%eax
	xorl %edx,%eax
	subl %edx,%eax
	fldl .LC0
	pushl %eax
	ficompl (%esp)
	addl $4,%esp
	fnstsw %ax
	seta %al
	movzbl %al,%edx
	fldl .LC1
	fcompp
	fnstsw %ax
	setb %al
	movb %al,-20(%ebp)
	movzbl -20(%ebp),%eax
	orl %eax,%edx
	je .L2
	movl $0,(%ecx)
	movl $0,4(%ecx)
..L2:
	xorl %eax,%eax
	movl %ebp,%esp
	popl %ebp
	ret
..Lfe1:
	.size	 fmbug,.Lfe1-fmbug
..section	.rodata
	.align 8
..LC0:
	.long 0xd9d7bdbb,0x3ddb7cdf
	.align 8
..LC1:
	.long 0xd9d7bdbb,0xbddb7cdf
..text
	.ident	"GCC: (GNU) pgcc-2.91.57 19980901 (egcs-1.1 release)"

and the difference 

--- fmbug.s.fm	Tue Sep  8 07:37:50 1998
+++ fmbug.s.nfm	Tue Sep  8 07:37:55 1998
@@ -30,12 +30,15 @@
 	ficompl (%esp)
 	addl $4,%esp
 	fnstsw %ax
-	seta %al
+	andb $69,%ah
+	sete %al
 	movzbl %al,%edx
 	fldl .LC1
 	fcompp
 	fnstsw %ax
-	setb %al
+	andb $69,%ah
+	cmpb $1,%ah
+	sete %al
 	movb %al,-20(%ebp)
 	movzbl -20(%ebp),%eax
 	orl %eax,%edx

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019