This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Optimizer is putting result of a log into the wrong reg



I am enclosing a little source file which does call to log and gets a
NaN when this is clearly wrong. Upon looking at the disassembly it
looks like the optimizer is putting the result in the wrong
register. I am enclosing the source file and here is the output:

gromit:singhki$ gcc -v
Reading specs from /local/packages/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
gromit:singhki$ gcc -O foo.c -o foo -lm
gromit:singhki$ ./foo
Arghhhhhh!

gromit:singhki$ gcc -v
Reading specs from /local/packages/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
gromit:singhki$ gcc foo.c -o foo -lm

Notice that it doesn't print out Arghhhhhh! if it is compiled without
optimization.

Thanks!

-Kirat

foo.c
=================================================================================
#include <math.h>
#include <stdio.h>

int FuncA (
	double		Spot,
	double		Strike,
	double		SpotYield,
	int			Type,
	double		TimeToExpiration,
	double		Volatility,
	void		*CashFlows,
	long		CoupTenor,
	int			CoupBasis,
	long		SpotDate,
	long		Accrual,
	long		FirstCpn,
	double		*Premium,
	double		*Delta
)
{
	return 1;
}

void FuncB(
	int			callPut,
	int	  	 	euroAmer,
	int	 	  	underType,
	int	   		markToMkt,
	double		spot,
	double		strike,
	double		vol,
	double		timeToExp,
	double		timeToSettle,
	double		ccRd,
	double		ccRf,
	double		*premRet,
	double		*deltaRet
)
{
	if( isnan( ccRd ) || isnan( ccRf ))
		fprintf( stderr, "arghhh!\n" );
}

double FuncC(
	int			Type,					
	int			Style,					
	double		SpotSpotPrice,			
	double		SpotQuotedPrice,		
	double		SpotYield,				
	double		ForwardSpotPrice,		
	double		ForwardQuotedPrice,		
	double		ForwardYield,			
	double		Strike,					
	double		AdjustedStrike,			
	double		YieldVolatility,		
	double		PriceVolatilityFactor,	
	double		TimeToExpiration,		
	double		TimeToSettlement,		
	double		DiscountFactor,			
	void		*CashFlows,				
	long		CoupTenor,				
	int			CoupBasis,				
	long		AccrualDate,			
	long		NextCpnDate,			
	long		SpotDate				
)
{
	double	Premium,
			Delta,
			AmerPremium,
			AmerDelta,
			EuroPremium,
			EuroDelta,
			FornRate,
			DiscRate,
			GrthRate,
			PriceVol;


	DiscRate = -log( DiscountFactor ) / TimeToSettlement;
	GrthRate =  log( ForwardQuotedPrice / SpotQuotedPrice ) / TimeToSettlement;
	FornRate = DiscRate - GrthRate;
	PriceVol = PriceVolatilityFactor * YieldVolatility;

	if( FuncA(
			ForwardSpotPrice,
			AdjustedStrike,
			ForwardYield,

			Type,
			TimeToExpiration,
			YieldVolatility,

			CashFlows,
			CoupTenor,
			CoupBasis,
			SpotDate,
			AccrualDate,
			NextCpnDate,

			&Premium,
			&Delta
		))
		Premium *= DiscountFactor;

	if( isnan( DiscRate ))
		fprintf( stderr, "Arghhhhhh!\n" );

	return Premium;
}

main()
{
	FuncC( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NULL, 1, 1, 1, 1, 1 );
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]