[Haskell-cafe] faster faster faster but not uglier (how to make nice code AND nice core)?
lemming at henning-thielemann.de
Wed May 19 21:12:55 UTC 2021
On Wed, 19 May 2021, Johannes Waldmann wrote:
> I wanted a really fast implementation of a vector addition system
> where the "vector" contains small numbers only.
With integer elements?
> and I want it packed into a machine word
> (and finally put these into Data.IntSet).
Why not using Integer? With a bit of bit tricks you can implement a vector
add via Integer addition.
E.g. like this
vectorAdd x y =
maskOddElements (maskOddElements x + maskOddElements y)
maskEvenElements (maskEvenElements x + maskEvenElements y)
But I suspect that larger Integers are not hold in registers.
Chances are better for a record of Word8's, Word16's ...
Maybe if they are put in a compact region:
Or you use the CPU vector types that GHC provides.
There seem to be some packages for small vectors:
More information about the Haskell-Cafe