This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Floating point optimization?
- To: egcs at egcs dot cygnus dot com
- Subject: Floating point optimization?
- From: Sam Lantinga <slouken at devolution dot com>
- Date: Fri, 30 Apr 1999 02:08:50 -0700
- Cc: slouken at devolution dot com, highlander at lokigames dot com, smariotti at activision dot com, rmyers at activision dot com
There appears to be an inconsistency in the way floating point
values are handled under Intel egcs with and without optimization:
j.c --------
float new_past_cost = 899.999878, new_entry_cost = 33.3333359, m_future_cost = 1140;
float m_total_cost = 2073.33325;
------------
t.c --------
extern float new_past_cost, new_entry_cost, m_future_cost;
extern float m_total_cost;
main()
{
float new_total_cost;
new_total_cost = new_past_cost + new_entry_cost + m_future_cost;
/* new_total_cost = 2073.333214, m_total_cost = 2073.333252 */
if ( new_total_cost < m_total_cost ) {
printf("New total cost is less than total cost\n");
}
printf("Done!\n");
}
------------
Output with egcs 1.1.1 and 1.1.2 on Linux i686 with -O0:
--
Done!
Output with egcs 1.1.1 and 1.1.2 on Linux i686 with -O1 or -O2:
--
New total cost is less than total cost
Done!
Why are they different?
An analysis of the assembly output shows that the -O0 version has
fstps -4(%ebp)
flds -4(%ebp)
between the floating point adds and the floating point compare.
I don't know assembly well enough to know what these are doing.
The result, however, is that non-optimized code results a different
branch of the logic being taken from the optimized code.
Comments?
-Sam Lantinga (slouken@devolution.com)
Lead Programmer, Loki Entertainment Software
--
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/
--