微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运行任何英特尔AVX函数后,数学函数需要更多周期

参见英文答案 > Using AVX instructions disables exp() optimization?                                    1个
我注意到运行任何英特尔AVX功能后,数学函数(如ceil,round,…)需要更多的cpu周期.

请参阅以下示例:

#include dio.h>
#include teraTIONS 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",t2 - t1,(t2 - t1) / NUM_IteraTIONS);
 }

int main ()
{
    __m256d a;

    run_round();

    a = _mm256_set1_pd(1);

    run_round();

    return 0;
}

编译:gcc -Wall -lm -mavx foo.c

输出是:

round res 31999997总周期224725952 CPI 22

round res 31999997 total cycles 1900864520 CPI 190

请指教.

最佳答案
反汇编生成代码.

我的猜测是会有额外的寄存器保存/恢复,或类似的东西.

原文地址:https://www.jb51.cc/linux/440859.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐