-ansi flag slows down fma() operation

Martin Ettl ettl.martin@gmx.de
Sat Apr 11 15:14:00 GMT 2009


Hello friends,

i have made tests using the fma()-function and discovered an issue (see also this thread: http://gcc.gnu.org/ml/gcc-help/2009-04/msg00121.html). Brian Budge sent me a short benchmark programm to measure the execution time on my machine. Finally the fma() operation was faster than the a*b+c operation, but:

If you use the -ansi flag to compile, then the fma()-operation takes 4-5-times longer, as without.

So, now my question: Is this a known issue or an intendet behaviour? If yes, what other flags slow down such functions? Has anybody experienced a similiar case? 

Sorry for my bad english and the boring questions:-).

Here is the benchmark, Brian sent me:

#include <time.h>
#include <math.h>
#include <iostream>

using namespace std;

static const size_t N = 1<<28;

int main() {
#if defined(CLOCK_REALTIME_HR)
    clockid_t cid(CLOCK_REALTIME_HR);
#else
    clockid_t cid(CLOCK_REALTIME);
#endif
    timespec  start, stop;
    
    double acc = 0.0, a = 10.0, b = 50.0, c = -0.235, seconds = 0.0;
    clock_gettime(cid, &start);
    
    for(size_t i = 0; i < N; i += 8) {
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
        acc += a * b + c;
    }
    clock_gettime(cid, &stop);

    seconds += stop.tv_sec - start.tv_sec;
    seconds += double(stop.tv_nsec-start.tv_nsec)*1e-9;

    cout << "ops: acc is " << acc << " in " << seconds << " seconds" << endl;
    acc = seconds = 0.0;

    clock_gettime(cid, &start);
    
    for(size_t i = 0; i < N; i += 8 ) {
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
        acc += fma(a, b, c);
    }
    clock_gettime(cid, &stop);

    seconds += stop.tv_sec - start.tv_sec;
    seconds += double(stop.tv_nsec-start.tv_nsec)*1e-9;

    cout << "fma: acc is " << acc << " in " << seconds << " seconds" << endl;

    return 0;
}

Thanks in advance!

Best regards

Martin
 
-- 
Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a



More information about the Gcc-help mailing list