llvm-extra-0.2.0.2: Utility functions for the llvm interface

LLVM.Extra.Vector

Synopsis

Documentation

size :: Pos n => Value (Vector n a) -> IntSource

replicate :: Access n a va => a -> CodeGenFunction r vaSource

Manually assemble a vector of equal values. Better use ScalarOrVector.replicate.

iterate :: Access n a va => (a -> CodeGenFunction r a) -> a -> CodeGenFunction r vaSource

assemble :: Access n a va => [a] -> CodeGenFunction r vaSource

construct a vector out of single elements

You must assert that the length of the list matches the vector size.

This can be considered the inverse of extractAll.

shuffle :: (Access m a ca, Access n a va) => va -> ConstValue (Vector m Word32) -> CodeGenFunction r caSource

Manually implement vector shuffling using insertelement and extractelement. In contrast to LLVM's built-in instruction it supports distinct vector sizes, but it allows only one input vector (or a tuple of vectors, but we cannot shuffle between them). For more complex shuffling we recommend extractAll and assemble.

rotateUp :: ShuffleMatch n v => v -> CodeGenFunction r vSource

Rotate one element towards the higher elements.

I don't want to call it rotateLeft or rotateRight, because there is no prefered layout for the vector elements. In Intel's instruction manual vector elements are indexed like the bits, that is from right to left. However, when working with Haskell list and enumeration syntax, the start index is left.

shiftUp :: Access n a v => a -> v -> CodeGenFunction r (a, v)Source

shiftDown :: Access n a v => a -> v -> CodeGenFunction r (a, v)Source

class (Pos n, Phi v, Undefined v) => ShuffleMatch n v | v -> n whereSource

Instances

(Pos n, IsPrimitive a) => ShuffleMatch n (Value (Vector n a)) 
(ShuffleMatch n v0, ShuffleMatch n v1) => ShuffleMatch n (v0, v1) 
(ShuffleMatch n v0, ShuffleMatch n v1, ShuffleMatch n v2) => ShuffleMatch n (v0, v1, v2) 

shuffleMatchAccess :: Access n a v => ConstValue (Vector n Word32) -> v -> CodeGenFunction r vSource

Implement the shuffleMatch method using the methods of the Access class.

class ShuffleMatch n v => Access n a v | v -> a n, a n -> v whereSource

Allow to work on records of vectors as if they are vectors of records. This is a reasonable approach for records of different element types since processor vectors can only be built from elements of the same type. But also say for chunked stereo signal this makes sense. In this case we would work on Stereo (Value a).

Instances

(Pos n, IsPrimitive a) => Access n (Value a) (Value (Vector n a)) 
(Access n a0 v0, Access n a1 v1) => Access n (a0, a1) (v0, v1) 
(Access n a0 v0, Access n a1 v1, Access n a2 v2) => Access n (a0, a1, a2) (v0, v1, v2) 

extractAll :: Access n a v => v -> CodeGenFunction r [a]Source

provide the elements of a vector as a list of individual virtual registers

This can be considered the inverse of assemble.

insertChunk :: (Access m a ca, Access n a va) => Int -> ca -> va -> CodeGenFunction r vaSource

modify :: Access n a va => Value Word32 -> (a -> CodeGenFunction r a) -> va -> CodeGenFunction r vaSource

map :: (Access n a va, Access n b vb) => (a -> CodeGenFunction r b) -> va -> CodeGenFunction r vbSource

mapChunks :: (Access m a ca, Access m b cb, Access n a va, Access n b vb) => (ca -> CodeGenFunction r cb) -> va -> CodeGenFunction r vbSource

zipChunksWith :: (Access m a ca, Access m b cb, Access m c cc, Access n a va, Access n b vb, Access n c vc) => (ca -> cb -> CodeGenFunction r cc) -> va -> vb -> CodeGenFunction r vcSource

chop :: (Access m a ca, Access n a va) => va -> [CodeGenFunction r ca]Source

If the target vector type is a native type then the chop operation produces no actual machine instruction. (nop) If the vector cannot be evenly divided into chunks the last chunk will be padded with undefined values.

concat :: (Access m a ca, Access n a va) => [ca] -> CodeGenFunction r vaSource

The target size is determined by the type. If the chunk list provides more data, the exceeding data is dropped. If the chunk list provides too few data, the target vector is filled with undefined elements.

select :: (IsFirstClass a, IsPrimitive a, Pos n, CmpRet a Bool) => Value (Vector n Bool) -> Value (Vector n a) -> Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

LLVM.select on boolean vectors cannot be translated to X86 code in LLVM-2.6, thus I code my own version that calls select on all elements. This is slow but works. When this issue is fixed, this function will be replaced by LLVM.select.

cumulate1 :: (IsArithmetic a, IsPrimitive a, Pos n) => Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

Needs (log n) vector additions

class (IsArithmetic a, IsPrimitive a) => Arithmetic a whereSource

The order of addition is chosen for maximum efficiency. We do not try to prevent cancelations.

Methods

sum :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value a)Source

sumToPair :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value a, Value a)Source

The first result value is the sum of all vector elements from 0 to div n 2 + 1 and the second result value is the sum of vector elements from div n 2 to n-1. n must be at least D2.

sumInterleavedToPair :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value a, Value a)Source

Treat the vector as concatenation of pairs and all these pairs are added. Useful for stereo signal processing. n must be at least D2.

cumulate :: Pos n => Value a -> Value (Vector n a) -> CodeGenFunction r (Value a, Value (Vector n a))Source

dotProduct :: Pos n => Value (Vector n a) -> Value (Vector n a) -> CodeGenFunction r (Value a)Source

mul :: Pos n => Value (Vector n a) -> Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

class (Arithmetic a, CmpRet a Bool, IsConst a) => Real a whereSource

Attention: The rounding and fraction functions only work for floating point values with maximum magnitude of maxBound :: Int32. This way we safe expensive handling of possibly seldom cases.

Methods

min :: Pos n => Value (Vector n a) -> Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

max :: Pos n => Value (Vector n a) -> Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

abs :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

truncate :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

fraction :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source

floor :: Pos n => Value (Vector n a) -> CodeGenFunction r (Value (Vector n a))Source