欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

AVX / AVX2 指令编程示例精选文章

最编程 2024-03-04 10:13:57
...

特别推荐: https://www.codeproject.com/Articles/874396/Crunching-Numbers-with-AVX-and-AVX

1. 查看自己cpu支持指令集:

直接去官网查:

https://ark.intel.com/content/www/cn/zh/ark.html#@Processors

比如这颗

https://ark.intel.com/content/www/cn/zh/ark/products/75131/intel-core-i7-4900mq-processor-8m-cache-up-to-3-80-ghz.html

2. 测试例子:

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

int main(int argc, char* argv[]) 
{

    __m256i first = _mm256_set_epi64x(10, 20, 30, 40);
    __m256i second = _mm256_set_epi64x(5, 5, 5, 5);
    __m256i result = _mm256_add_epi64(first, second);

    long int* values = (long int*) &result;
	printf("==%ld \n", sizeof(long int));
    for (int i = 0;i < 4; i++)
	{
        printf("%ld ", values[i]);
    }

    return 0;
}


_mm256_set_epi64x() _mm256_add_epi64() 等内建函数的含义和用法:

https://software.intel.com/sites/landingpage/IntrinsicsGuide

编译命令:

gcc -mavx2 -S -fverbose-asm fun.c  #看详细的汇编语言结果

gcc -mavx2 fun.c 

可能报错:

AVX vector return without AVX enabled changes the ABI    ——————————没有 -mavx2

inlining failed in call to always_inline 'xxx': target specific option mismatch —————— 架构不匹配,看看cpu是否支持 avx2

参考资料:

https://software.intel.com/content/www/cn/zh/develop/articles/introduction-to-intel-advanced-vector-extensions.html

https://zhuanlan.zhihu.com/p/94649418

https://www.codeproject.com/Articles/874396/Crunching-Numbers-with-AVX-and-AVX

https://software.intel.com/sites/landingpage/IntrinsicsGuid

原文地址:https://www.cnblogs.com/qmjc/p/13495708.html