Math functions takes more cycles after running any intel AVX function

Viewed 391

I've noticed that math functions (like ceil, round, ...) take more CPU cycles after running any intel AVX function.

See following example:

#include <stdio.h>
#include <math.h>
#include <immintrin.h>


static unsigned long int get_rdtsc(void)
{
        unsigned int a, d;
        asm volatile("rdtsc" : "=a" (a), "=d" (d));
        return (((unsigned long int)a) | (((unsigned long int)d) << 32));
}

#define NUM_ITERATIONS 10000000

void run_round()
{
    unsigned long int t1, t2, res, i;
    double d = 3.2;

    t1 = get_rdtsc();
    for (i = 0 ; i < NUM_ITERATIONS ; ++i) {
        res = round(d*i);
    }
    t2 = get_rdtsc();

    printf("round res %lu total cycles %lu CPI %lu\n", res, t2 - t1, (t2 - t1) / NUM_ITERATIONS);
 }

int main ()
{
    __m256d a;

    run_round();

    a = _mm256_set1_pd(1);

    run_round();

    return 0;
}

compile with: gcc -Wall -lm -mavx foo.c

The output is:

round res 31999997 total cycles 224725952 CPI 22

round res 31999997 total cycles 1900864520 CPI 190

Please advise.

1 Answers
Related