我正在尝试学习AVX指令,并且在运行我收到的基本代码时
非法指令(核心已转储)
该代码在下面提到,我正在使用它进行编译
g ++ -mavx512f 1.cpp
问题到底是什么?如何解决?谢谢!
#include <immintrin.h>
#include<iostream>
using namespace std;
void add(const float a[], const float b[], float res[], int n)
{
int i = 0;
for(; i < (n&(~0x31)) ; i+=32 )
{
__m512 x = _mm512_loadu_ps( &a[i] );
__m512 y = _mm512_loadu_ps( &b[i] );
__m512 z = _mm512_add_ps(x,y);
_mm512_stream_ps(&res[i],z);
}
for(; i<n; i++) res[i] = a[i] + b[i];
}
int main()
{
int n = 100000;
float a[n], b[n], res[n];
for(int i = 0;i …
Run Code Online (Sandbox Code Playgroud) 我正在寻找将压缩的 64 位整数饱和为 8 位整数的解决方案。看着_mm256_cvtepi64_epi8
但不是饱和,它截断了导致不需要的输出。
我的程序如下:
int main()
{
__m256i a, b, c;
__m128i d;
a = _mm256_set1_epi64x(127);
b = _mm256_set1_epi64x(1);
c = _mm256_add_epi64x(a, b);
d = _mm256_cvtepi64_epi8(c);
}
Run Code Online (Sandbox Code Playgroud)
我希望输出 (d) 包含四个127
(饱和),但是程序产生四个-128
元素(从 截断128
)。
我正在尝试可视化合并 AVX2 和 AVX512 的加速
#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>
#include <omp.h>
#include <time.h>
int main()
{
long i, N = 160000000;
int * A = (int *)aligned_alloc(sizeof(__m256), sizeof(int) * N);
int * B = (int *)aligned_alloc(sizeof(__m256), sizeof(int) * N);
int * C = (int *)aligned_alloc(sizeof(__m256), sizeof(int) * N);
int * E = (int *)aligned_alloc(sizeof(__m512), sizeof(int) * N);
int * F = (int *)aligned_alloc(sizeof(__m512), sizeof(int) * N);
int * G = (int *)aligned_alloc(sizeof(__m512), sizeof(int) * N);
srand(time(0));
for(i=0;i<N;i++)
{ …
Run Code Online (Sandbox Code Playgroud) 我的 CPU 支持各种功能
-march=CPU[,+EXTENSION...]
generate code for CPU and EXTENSION, CPU is one of:
generic32, generic64, i386, i486, i586, i686,
pentium, pentiumpro, pentiumii, pentiumiii, pentium4,
prescott, nocona, core, core2, corei7, l1om, k1om,
iamcu, k6, k6_2, athlon, opteron, k8, amdfam10,
bdver1, bdver2, bdver3, bdver4, znver1, btver1,
btver2
EXTENSION is combination of:
8087, 287, 387, 687, mmx, sse, sse2, sse3, ssse3,
sse4.1, sse4.2, sse4, avx, avx2, avx512f, avx512cd,
avx512er, avx512pf, avx512dq, avx512bw, avx512vl,
vmx, vmfunc, smx, xsave, xsaveopt, xsavec, xsaves,
aes, pclmul, …
Run Code Online (Sandbox Code Playgroud)