This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ math optimization problem...
- From: Benjamin Redelings I <bredelin at ucla dot edu>
- To: Richard Guenther <richard dot guenther at gmail dot com>
- Cc: gcc at gcc dot gnu dot org, dnovillo at redhat dot com, sstrasser at systemhaus-gruppe dot de, pinskia at physics dot uc dot edu
- Date: Thu, 24 Feb 2005 16:05:07 -0800
- Subject: Re: C++ math optimization problem...
- References: <421CCD17.3050402@ucla.edu> <84fc9c000502240229588aae8d@mail.gmail.com>
Hello,
Regarding the testcase I mentioned before, I have been checking out the
Intel compiler to see if it would generate better code. Interestingly
enough, it displays EXACTLY the same run-times as gcc for the two tests
(0.2s for math in if-block, 1.0s for math out of if-block).
So this is rather strange.
Shall I file a PR if it doesn't become clear what is going on?
thanks,
-BenRI
include <vector>
const int OUTER = 100000;
const int INNER = 1000;
using namespace std;
int main(int argn, char *argv[])
{
int s = atoi(argv[1]);
double result;
{
vector<double> d(INNER); // move outside of this scope to fix
// initialize d
for (int i = 0; i < INNER; i++)
d[i] = double(1+i) / INNER;
// calc result
result=0;
for (int i = 0; i < OUTER; ++i)
for (int j = 1; j < INNER; ++j)
result += d[j]*d[j-1] + d[j-1];
}
printf("result = %f\n",result);
return 0;
}
P.S. Um, is the gcc listserv intelligent enough not to send you all a
second copy of this e-mail?