从 Haskell 生成矢量代码?

发布于 2024-08-05 18:17:10 字数 332 浏览 3 评论 0原文

是否有可能让 GHC 为各个 SSE 代生成 SIMD 代码?

例如。得到这样的程序,

import Data.Array.Vector
main = print . sumU $ (enumFromToFracU 1 10000000 :: UArr Double)

我可以看到生成的代码(为 64 位 x86 编译)在标量模式下使用 SSE 指令(C 和 asm 后端)。所以addsd而不是addpd。对于我所从事的程序类型,向量指令的使用对于性能非常重要。对于像我这样的新手来说,有没有一种简单的方法可以让 GHC 使用 SSE 对代码进行 SIMDize?

Is it possible to get GHC to produce SIMD code for the various SSE generations?

Eg. got a program like this

import Data.Array.Vector
main = print . sumU $ (enumFromToFracU 1 10000000 :: UArr Double)

I can see the generated code (compiled for 64 bit x86) use SSE instructions in scalar mode (both C and asm backends). So addsd rather than addpd. For the types of programs I work on the use of vector instructions is important for performance. Is there an easy way for a newbie such as myself to get GHC to SIMDize the code using SSE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轻拂→两袖风尘 2024-08-12 18:17:10

是的,这是可能的,通过 C 后端,但这是反复试验。
我使用的标志:

 gcc -O2 -funbox-strict-fields -fvia-C -optc-O3 -march=native -optc-msse4

然后希望 GCC 发现 GHC 通过 uvector 代码生成的紧密循环,并意识到存在 SIMD 潜力。

Yes, it is possible, via the C backend, but it is trial and error.
The flags I use:

 gcc -O2 -funbox-strict-fields -fvia-C -optc-O3 -march=native -optc-msse4

Then hope GCC spots the tight loop GHC generates via the uvector code, and realises there is SIMD potential.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文