根据此页https://sourceware.org/glibc/wiki/libmvec ,我应该能够使用 libmvec 函数手动矢量化一些复杂的指令,例如余弦。但是,我不知道如何让 gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 识别它们。我是否缺少一些编译器标志或其他东西?如有任何帮助或建议,我们将不胜感激。
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <immintrin.h>
// gcc libmvectest.c -o libmvectest.bin -lm -O3 -Wall -ffast-math -march=msse4
int main(int argc, char **argv)
{
float input = 0.1;
float res[4];
__m128 m128 = _mm_set1_ps(input);
__m128 cosm128 = _ZGVbN4ua16vl_cosf(m128);
_mm_storeu_ps(res, cosm128);
printf("%.8f %.8f\n", cosf(input), res[0]);
}
我已经在谷歌上搜索了前缀函数的“隐式声明...”错误,但未能找到适合我的答案。我尝试了_ZGVbN4ua16vl_cos、_ZGVbN4ua16vl_cosf和其他尝试。有谁知道实际的函数名称在哪里列出?
最佳答案
感谢所有对此进行调查的人。问题的要点是使用这些内置函数进行手动矢量化,以便不依赖优化器,如果您执行的不仅仅是一个简单的函数循环,优化器很容易感到困惑。 Peter Cordes 的建议适用于我的系统,因此该代码现在可以成功编译并运行。
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <immintrin.h>
// gcc libmvectest.c -o libmvectest.bin -lm -O3 -Wall -ffast-math -march=msse4
extern __m128 _ZGVbN4v_cosf(__m128);
int main(int argc, char **argv)
{
float input = 0.1;
float res[4];
__m128 m128 = _mm_set1_ps(input);
__m128 cosm128 = _ZGVbN4v_cosf(m128);
_mm_storeu_ps(res, cosm128);
printf("%.8f %.8f\n", cosf(input), res[0]);
}
关于在 __m128 vector 上手动调用 libmvec 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76336648/