Re: -ffast-math in Ports and wrong generated code

From: Steve Kargl <sgk_at_troutmask.apl.washington.edu>
Date: Tue, 3 Apr 2012 06:43:00 -0700
On Tue, Apr 03, 2012 at 02:21:11PM +0300, Andrey Simonenko wrote:
> 
> I use one port from the Ports Collection, that works with FP.  Having
> reinstalled it (its version was not changed) I noticed that it started
> to work incorrectly.  After debugging and disassembling its code I found
> out that the -ffast-math option used for building was the result of
> wrongly generated code (I did not specify this option in /etc/make.conf).
> 
> At least finite() function call was eliminated from the result Assembler
> code when -ffast-math option is used, tested on 9.0-STABLE and 10.0-CURRENT.
> 
> Example test source code and generated code under 9.0-STABLE on amd64
> by gcc from the base system:
> 
> -----------------------------
> #include <math.h>
> #include <stdio.h>
> 
> void
> check_finite(double x)
> {
> 	printf("%d\n", finite(x));
> }
> -----------------------------
> 
> % gcc -Wall -O2 -S finite.c
> -----------------------------
> check_finite:
> .LFB3:
> 	subq	$8, %rsp
> .LCFI0:
> 	call	finite			<-- call to finite()
> 	movl	$.LC0, %edi
> 	movl	%eax, %esi
> 	addq	$8, %rsp
> 	xorl	%eax, %eax
> 	jmp	printf
> .LFE3:
> 	.size	check_finite, .-check_finite
> -----------------------------
> 
> % gcc -Wall -O2 -ffast-math -S finite.c
> -----------------------------
> check_finite:
> .LFB3:
> 	xorl	%esi, %esi		<-- fake result from finite()
> 	movl	$.LC0, %edi
> 	xorl	%eax, %eax
> 	jmp	printf
> .LFE3:
> 	.size	check_finite, .-check_finite
> -----------------------------
> 
> Can somebody comment this?

Read the man page for gcc.  With --fast-math,
gcc assumes that the result of any FP operation 
is finite.  So, the function call to finite()
is eliminated as it is always true. 

-- 
Steve
Received on Tue Apr 03 2012 - 11:43:30 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:25 UTC