primitive-simd-0.1.0.0: SIMD data types and functions

Copyright(c) 2015 Anselm Jonas Scholl
LicenseBSD3
Maintaineranselm.scholl@tu-harburg.de
Stabilityexperimental
Portabilitynon-portable (uses GHC.Prim)
Safe HaskellNone
LanguageHaskell2010

Data.Primitive.SIMD

Contents

Description

SIMD data types and functions.

Synopsis

SIMD type classes

class (Num v, Real (Elem v)) => SIMDVector v where Source

This class provides basic operations to create and consume SIMD types. Numeric operations on members of this class should compile to single SIMD instructions although not all operations are (yet) supported by GHC (e.g. sqrt, it is currently implemented as mapVector sqrt which has to unpack the vector, compute the results and pack them again).

Associated Types

type Elem v Source

Type of the elements in the vector

type ElemTuple v Source

Type used to pack or unpack the vector

Methods

nullVector :: v Source

Vector with all elements initialized to zero.

vectorSize :: v -> Int Source

Number of components (scalar elements) in the vector. The argument is not evaluated.

elementSize :: v -> Int Source

Size of each (scalar) element in the vector in bytes. The argument is not evaluated.

broadcastVector :: Elem v -> v Source

Broadcast a scalar to all elements of a vector.

insertVector :: v -> Elem v -> Int -> v Source

Insert a scalar at the given position (starting from 0) in a vector. If the index is outside of the range an exception is thrown.

unsafeInsertVector :: v -> Elem v -> Int -> v Source

Insert a scalar at the given position (starting from 0) in a vector. If the index is outside of the range the behavior is undefined.

mapVector :: (Elem v -> Elem v) -> v -> v Source

Apply a function to each element of a vector. Be very careful not to map branching functions over a vector as they could lead to quite a bit of code bloat (or make sure they are tagged with NOINLINE).

zipVector :: (Elem v -> Elem v -> Elem v) -> v -> v -> v Source

Zip two vectors together using a combining function.

foldVector :: (Elem v -> Elem v -> Elem v) -> v -> Elem v Source

Fold the elements of a vector to a single value. The order in which the elements are combined is not specified.

sumVector :: v -> Elem v Source

Sum up the components of the vector. Equivalent to foldVector (+).

packVector :: ElemTuple v -> v Source

Pack some elements to a vector.

unpackVector :: v -> ElemTuple v Source

Unpack a vector.

SIMD data types

data Tuple64 a Source

The compiler only supports tuples up to 62 elements, so we have to use our own data type.

Constructors

Tuple64 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a