在 __m128 vector 上手动调用 libmvec 函数?

标签 c simd sse glibc intrinsics

根据此页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/

相关文章:

c++ - 在 Visual Studio 2010/2012 和 Release 模式下使用 SSE 内部函数时结果不正确

c - 如何找到缓冲区溢出和内存损坏的地方?

在 C 中通过 fork() 创建子进程

c - 在c中交换反转链表

python - python进程之间的共享内存

linux - 使用 SSE 指令的 Memcpy

c - 使用 SSE 以最快的速度实现自然指数函数

c - 从 128 位 SSE vector 加载和提取 32 位整数值的最有效方法是什么?

arm - ARM和NEON可以并行工作吗?

c - 错误 : casting user defined data types in c