数学函数运行任何英特尔AVX功能后,需要更多的周期 [英] Math functions takes more cycles after running any intel AVX function
本文介绍了数学函数运行任何英特尔AVX功能后,需要更多的周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到,数学函数(如CEIL,圆形,...)运行任何英特尔AVX功能之后采取更多的CPU周期。
I've noticed that math functions (like ceil, round, ...) take more CPU cycles after running any intel AVX function.
请参阅下面的例子:
#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;
}
与编译:gcc的-lm -Wall文件foo.c -mavx
compile with: gcc -Wall -lm -mavx foo.c
输出是:
一轮资源31999997总周期224725952 CPI 22
round res 31999997 total cycles 224725952 CPI 22
一轮资源31999997总周期1900864520 CPI 190
round res 31999997 total cycles 1900864520 CPI 190
请指教。
推荐答案
拆卸产生code。
我的猜测是,有更多的寄存器保存/恢复的事情,或者类似的东西。
My guess would be that there is additional register saving/restoring going on, or something like that.
这篇关于数学函数运行任何英特尔AVX功能后,需要更多的周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文