[Haskell-cafe] vector-simd: some code available, and some questions
Nicolas Trangez
nicolas at incubaid.com
Sun Jul 8 00:21:40 CEST 2012
On Sat, 2012-07-07 at 21:59 +0200, Gábor Lehel wrote:
> An alternative solution is to encode all of the alignments in unary,
> which is more general; if they're all going to be a power of two you
> can "store" just the logarithm:
>
> data One
> data Twice n -- not practical to call it Double :)
>
> class AlignedToAtLeast n a
> instance AlignedToAtLeast One One
> instance AlignedToAtLeast One (Twice a)
> instance AlignedToAtLeast n a => AlignedToAtLeast (Twice n) (Twice a)
>
> type A1 = One
> type A4 = Twice (Twice A1)
> type A8 = Twice A4
> type A16 = Twice A8
> type A32 = Twice A16
>
> and you can apply the same private class thing from above if you
> want.
Very ingenious, thanks! I pushed this into [1], although export lists of
all modules most likely will need some love once things get into shape.
This also allows functions to become more general:
unsafeXorSSE42 :: (Storable a,
SV.AlignedToAtLeast SV.A16 o1, SV.Alignment o1,
SV.AlignedToAtLeast SV.A16 o2, SV.Alignment o2,
SV.AlignedToAtLeast SV.A16 o3, SV.Alignment o3) =>
SV.Vector o1 a -> SV.Vector o2 a -> SV.Vector o3 a
I wonder whether GHC's upcoming type-level numerals could be useful in
this situation as well.
Nicolas
[1]
https://github.com/NicolasT/vector-simd/commit/a4f13745eb24d87a3628af13109f3e1d8232c925
More information about the Haskell-Cafe
mailing list