diff options
author | Geoffrey Mainland <gmainlan@microsoft.com> | 2012-10-19 09:06:17 +0100 |
---|---|---|
committer | Geoffrey Mainland <gmainlan@microsoft.com> | 2013-02-01 22:00:24 +0000 |
commit | 4af62075bbe9e96a3678fc90288496e0c4c7c17d (patch) | |
tree | 3df4fa03089310cd66678681a4ce78dd39bea25f /compiler/prelude | |
parent | 6480a35c15717025c169980b1cc763a7e6f36056 (diff) | |
download | haskell-4af62075bbe9e96a3678fc90288496e0c4c7c17d.tar.gz |
Add the Float32X4# primitive type and associated primops.
This patch lays the groundwork needed for primop support for SIMD vectors. In
addition to the groundwork, we add support for the FloatX4# primitive type and
associated primops.
* Add the FloatX4# primitive type and associated primops.
* Add CodeGen support for Float vectors.
* Compile vector operations to LLVM vector operations in the LLVM code
generator.
* Make the x86 native backend fail gracefully when encountering vector primops.
* Only generate primop wrappers for vector primops when using LLVM.
Diffstat (limited to 'compiler/prelude')
-rw-r--r-- | compiler/prelude/PrelNames.lhs | 5 | ||||
-rw-r--r-- | compiler/prelude/TysPrim.lhs | 23 | ||||
-rw-r--r-- | compiler/prelude/primops.txt.pp | 95 |
3 files changed, 121 insertions, 2 deletions
diff --git a/compiler/prelude/PrelNames.lhs b/compiler/prelude/PrelNames.lhs index 261d10295f..961a823436 100644 --- a/compiler/prelude/PrelNames.lhs +++ b/compiler/prelude/PrelNames.lhs @@ -1420,6 +1420,11 @@ typeNatAddTyFamNameKey = mkPreludeTyConUnique 162 typeNatMulTyFamNameKey = mkPreludeTyConUnique 163 typeNatExpTyFamNameKey = mkPreludeTyConUnique 164 +-- SIMD vector types (Unique keys) +floatX4PrimTyConKey :: Unique + +floatX4PrimTyConKey = mkPreludeTyConUnique 170 + ---------------- Template Haskell ------------------- -- USES TyConUniques 200-299 ----------------------------------------------------- diff --git a/compiler/prelude/TysPrim.lhs b/compiler/prelude/TysPrim.lhs index 44ba035dc0..960a27b276 100644 --- a/compiler/prelude/TysPrim.lhs +++ b/compiler/prelude/TysPrim.lhs @@ -73,7 +73,10 @@ module TysPrim( eqPrimTyCon, -- ty1 ~# ty2 -- * Any - anyTy, anyTyCon, anyTypeOfKind + anyTy, anyTyCon, anyTypeOfKind, + + -- * SIMD + floatX4PrimTyCon, floatX4PrimTy ) where #include "HsVersions.h" @@ -135,6 +138,8 @@ primTyCons , constraintKindTyCon , superKindTyCon , anyKindTyCon + + , floatX4PrimTyCon ] mkPrimTc :: FastString -> Unique -> TyCon -> Name @@ -144,7 +149,7 @@ mkPrimTc fs unique tycon (ATyCon tycon) -- Relevant TyCon UserSyntax -- None are built-in syntax -charPrimTyConName, intPrimTyConName, int32PrimTyConName, int64PrimTyConName, wordPrimTyConName, word32PrimTyConName, word64PrimTyConName, addrPrimTyConName, floatPrimTyConName, doublePrimTyConName, statePrimTyConName, realWorldTyConName, arrayPrimTyConName, arrayArrayPrimTyConName, byteArrayPrimTyConName, mutableArrayPrimTyConName, mutableByteArrayPrimTyConName, mutableArrayArrayPrimTyConName, mutVarPrimTyConName, mVarPrimTyConName, tVarPrimTyConName, stablePtrPrimTyConName, stableNamePrimTyConName, bcoPrimTyConName, weakPrimTyConName, threadIdPrimTyConName, eqPrimTyConName :: Name +charPrimTyConName, intPrimTyConName, int32PrimTyConName, int64PrimTyConName, wordPrimTyConName, word32PrimTyConName, word64PrimTyConName, addrPrimTyConName, floatPrimTyConName, doublePrimTyConName, statePrimTyConName, realWorldTyConName, arrayPrimTyConName, arrayArrayPrimTyConName, byteArrayPrimTyConName, mutableArrayPrimTyConName, mutableByteArrayPrimTyConName, mutableArrayArrayPrimTyConName, mutVarPrimTyConName, mVarPrimTyConName, tVarPrimTyConName, stablePtrPrimTyConName, stableNamePrimTyConName, bcoPrimTyConName, weakPrimTyConName, threadIdPrimTyConName, eqPrimTyConName, floatX4PrimTyConName :: Name charPrimTyConName = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon intPrimTyConName = mkPrimTc (fsLit "Int#") intPrimTyConKey intPrimTyCon int32PrimTyConName = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon @@ -172,6 +177,7 @@ stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyC bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon +floatX4PrimTyConName = mkPrimTc (fsLit "FloatX4#") floatX4PrimTyConKey floatX4PrimTyCon \end{code} %************************************************************************ @@ -729,3 +735,16 @@ anyTyCon = mkSynTyCon anyTyConName kind [kKiVar] anyTypeOfKind :: Kind -> Type anyTypeOfKind kind = mkNakedTyConApp anyTyCon [kind] \end{code} + +%************************************************************************ +%* * +\subsection{SIMD vector type} +%* * +%************************************************************************ + +\begin{code} +floatX4PrimTy :: Type +floatX4PrimTy = mkTyConTy floatX4PrimTyCon +floatX4PrimTyCon :: TyCon +floatX4PrimTyCon = pcPrimTyCon0 floatX4PrimTyConName (VecRep 4 FloatElemRep) +\end{code} diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 6d551d90e5..9cdda0ec8f 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -2202,6 +2202,101 @@ primop TraceMarkerOp "traceMarker#" GenPrimOp ------------------------------------------------------------------------ +section "Float SIMD Vectors" + {Operations on SIMD vectors of 4 single-precision (32-bit) + floating-point numbers.} +------------------------------------------------------------------------ + +primtype FloatX4# + +primop FloatToFloatX4Op "floatToFloatX4#" GenPrimOp + Float# -> FloatX4# + +primop FloatX4PackOp "packFloatX4#" GenPrimOp + Float# -> Float# -> Float# -> Float# -> FloatX4# + +primop FloatX4UnpackOp "unpackFloatX4#" GenPrimOp + FloatX4# -> (# Float#, Float#, Float#, Float# #) + +primop FloatX4InsertOp "insertFloatX4#" GenPrimOp + FloatX4# -> Float# -> Int# -> FloatX4# + with can_fail = True + +primop FloatX4AddOp "plusFloatX4#" Dyadic + FloatX4# -> FloatX4# -> FloatX4# + with commutable = True + +primop FloatX4SubOp "minusFloatX4#" Dyadic + FloatX4# -> FloatX4# -> FloatX4# + +primop FloatX4MulOp "timesFloatX4#" Dyadic + FloatX4# -> FloatX4# -> FloatX4# + with commutable = True + +primop FloatX4DivOp "divideFloatX4#" Dyadic + FloatX4# -> FloatX4# -> FloatX4# + with can_fail = True + +primop FloatX4NegOp "negateFloatX4#" Monadic + FloatX4# -> FloatX4# + +primop IndexByteArrayOp_FloatX4 "indexFloatX4Array#" GenPrimOp + ByteArray# -> Int# -> FloatX4# + with can_fail = True + +primop ReadByteArrayOp_FloatX4 "readFloatX4Array#" GenPrimOp + MutableByteArray# s -> Int# -> State# s -> (# State# s, FloatX4# #) + with has_side_effects = True + can_fail = True + +primop WriteByteArrayOp_FloatX4 "writeFloatX4Array#" GenPrimOp + MutableByteArray# s -> Int# -> FloatX4# -> State# s -> State# s + with has_side_effects = True + can_fail = True + +primop IndexOffAddrOp_FloatX4 "indexFloatX4OffAddr#" GenPrimOp + Addr# -> Int# -> FloatX4# + with can_fail = True + +primop ReadOffAddrOp_FloatX4 "readFloatX4OffAddr#" GenPrimOp + Addr# -> Int# -> State# s -> (# State# s, FloatX4# #) + with has_side_effects = True + can_fail = True + +primop WriteOffAddrOp_FloatX4 "writeFloatX4OffAddr#" GenPrimOp + Addr# -> Int# -> FloatX4# -> State# s -> State# s + with has_side_effects = True + can_fail = True + +primop IndexByteArrayOp_FloatAsFloatX4 "indexFloatArrayAsFloatX4#" GenPrimOp + ByteArray# -> Int# -> FloatX4# + with can_fail = True + +primop ReadByteArrayOp_FloatAsFloatX4 "readFloatArrayAsFloatX4#" GenPrimOp + MutableByteArray# s -> Int# -> State# s -> (# State# s, FloatX4# #) + with has_side_effects = True + can_fail = True + +primop WriteByteArrayOp_FloatAsFloatX4 "writeFloatArrayAsFloatX4#" GenPrimOp + MutableByteArray# s -> Int# -> FloatX4# -> State# s -> State# s + with has_side_effects = True + can_fail = True + +primop IndexOffAddrOp_FloatAsFloatX4 "indexFloatOffAddrAsFloatX4#" GenPrimOp + Addr# -> Int# -> FloatX4# + with can_fail = True + +primop ReadOffAddrOp_FloatAsFloatX4 "readFloatOffAddrAsFloatX4#" GenPrimOp + Addr# -> Int# -> State# s -> (# State# s, FloatX4# #) + with has_side_effects = True + can_fail = True + +primop WriteOffAddrOp_FloatAsFloatX4 "writeFloatOffAddrAsFloatX4#" GenPrimOp + Addr# -> Int# -> FloatX4# -> State# s -> State# s + with has_side_effects = True + can_fail = True + +------------------------------------------------------------------------ --- --- ------------------------------------------------------------------------ |