haskell-works / hw-simd

Library of simd functions
BSD 3-Clause "New" or "Revised" License
16 stars 1 forks source link

[Q] Int, Double and Float comparisons? #17

Open ocramz opened 5 years ago

ocramz commented 5 years ago

Are there comparison operations for integer and floating point types, or how could they be implemented? Thanks!

newhoggy commented 5 years ago

These can be implemented 😁

newhoggy commented 5 years ago

For Int, it's isomorphic to Word64 on ghc on x64, so unsafe casting between those types will get you the comparison for Int.

newhoggy commented 5 years ago

Which one of these are you looking to expose from this library?

https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=765,767,802&text=cmp&techs=MMX,SSE,SSE2,SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2&cats=Compare

ocramz commented 5 years ago

Thank you for the link! I don't know which bindings might be needed yet, but some people say leveraging this should give us faster sorting code thanvector-algorithms. I would like to know more about this, could you briefly explain how are new instructions added ?

newhoggy commented 5 years ago

Unfortunately GHC doesn't support SIMD (yet).

There is ongoing work to improve SIMD support in GHC:

https://gist.github.com/Abhiroop/9a2600f24f8139b7fc0742a2b4585bb3

The work around (which is what this library does) is to write the relevant functions in C and then writing FFI wrappers to call the C functions.