Generate vector code from Haskell?

╄→гoц情女王★ 提交于 2019-12-21 20:28:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1452309/generate-vector-code-from-haskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!