用 SIMD 指令重写 memcpy/memcmp/... 有意义吗? [英] Does rewriting memcpy/memcmp/... with SIMD instructions make sense?

查看:192
本文介绍了用 SIMD 指令重写 memcpy/memcmp/... 有意义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大型软件中用 SIMD 指令重写 memcpy/memcmp/... 有意义吗?

Does rewriting memcpy/memcmp/... with SIMD instructions make sense in a large scale software?

如果是这样,为什么 GCC 默认不为这些库函数生成 SIMD 指令?

If so, why doesn't GCC generate SIMD instructions for these library functions by default?

另外,SIMD还有什么可以改进的功能吗?

Also, are there any other functions can be possibly improved by SIMD?

推荐答案

是的,使用 SSE 指令,这些函数的速度要快得多.如果您的运行时库/编译器内在包含优化版本就好了,但这似乎并不普遍.

Yes, these functions are much faster with SSE instructions. It would be nice if your runtime library/compiler instrinsics would include optimized versions, but that doesn't seem to be pervasive.

我有一个自定义 SIMD memchr,它比库版本快很多.特别是当我找到 2 或 3 个字符中的第一个时(例如,我想知道这行文本中是否有等式,我搜索 = 中的第一个,\n, \r).

I have a custom SIMD memchr which is a hell-of-a-lot faster than the library version. Especially when I'm finding the first of 2 or 3 characters (example, I want to know if there's an equation in this line of text, I search for the first of =, \n, \r).

另一方面,库函数经过充分测试,因此只有在您经常调用它们并且分析器显示它们占 CPU 时间的很大一部分时才值得编写自己的函数.

On the other hand, the library functions are well tested, so it's only worth writing your own if you call them a lot and a profiler shows they're a significant fraction of your CPU time.

这篇关于用 SIMD 指令重写 memcpy/memcmp/... 有意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆