Commit 821585f5 authored by rl@cse.unsw.edu.au's avatar rl@cse.unsw.edu.au
Browse files

More vectorisation-related built-ins

parent 51ad52d4
......@@ -6,7 +6,7 @@
-- for details
module VectBuiltIn (
Builtins(..), sumTyCon, prodTyCon,
Builtins(..), sumTyCon, prodTyCon, combinePAVar,
initBuiltins, initBuiltinTyCons, initBuiltinPAs, initBuiltinPRs,
primMethod, primPArray
......@@ -45,6 +45,9 @@ mAX_NDP_PROD = 3
mAX_NDP_SUM :: Int
mAX_NDP_SUM = 3
mAX_NDP_COMBINE :: Int
mAX_NDP_COMBINE = 2
mkNDPModule :: FastString -> Module
mkNDPModule m = mkModule ndpPackageId (mkModuleNameFS m)
......@@ -81,7 +84,7 @@ data Builtins = Builtins {
, replicatePAVar :: Var
, emptyPAVar :: Var
, packPAVar :: Var
-- , combinePAVar :: Var
, combinePAVars :: Array Int Var
, liftingContext :: Var
}
......@@ -96,6 +99,11 @@ prodTyCon n bi
| n >= 0 && n <= mAX_NDP_PROD = tupleTyCon Boxed n
| otherwise = pprPanic "prodTyCon" (ppr n)
combinePAVar :: Int -> Builtins -> Var
combinePAVar n bi
| n >= 2 && n <= mAX_NDP_COMBINE = combinePAVars bi ! n
| otherwise = pprPanic "combinePAVar" (ppr n)
initBuiltins :: DsM Builtins
initBuiltins
= do
......@@ -130,7 +138,11 @@ initBuiltins
replicatePAVar <- externalVar nDP_PARRAY FSLIT("replicatePA")
emptyPAVar <- externalVar nDP_PARRAY FSLIT("emptyPA")
packPAVar <- externalVar nDP_PARRAY FSLIT("packPA")
-- combinePAVar <- dsLookupGlobalId combinePAName
combines <- mapM (externalVar nDP_PARRAY)
[mkFastString ("combine" ++ show i ++ "PA")
| i <- [2..mAX_NDP_COMBINE]]
let combinePAVars = listArray (2, mAX_NDP_COMBINE) combines
liftingContext <- liftM (\u -> mkSysLocal FSLIT("lc") u intPrimTy)
newUnique
......@@ -162,7 +174,7 @@ initBuiltins
, replicatePAVar = replicatePAVar
, emptyPAVar = emptyPAVar
, packPAVar = packPAVar
-- , combinePAVar = combinePAVar
, combinePAVars = combinePAVars
, liftingContext = liftingContext
}
......
......@@ -14,7 +14,7 @@ module VectMonad (
cloneName, cloneId, cloneVar,
newExportedVar, newLocalVar, newDummyVar, newTyVar,
Builtins(..), sumTyCon, prodTyCon,
Builtins(..), sumTyCon, prodTyCon, combinePAVar,
builtin, builtins,
GlobalEnv(..),
......
......@@ -18,7 +18,7 @@ module VectUtils (
parrayReprTyCon, parrayReprDataCon, mkVScrut,
prDFunOfTyCon,
paDictArgType, paDictOfType, paDFunType,
paMethod, mkPR, lengthPA, replicatePA, emptyPA, packPA, liftPA,
paMethod, mkPR, lengthPA, replicatePA, emptyPA, packPA, combinePA, liftPA,
polyAbstract, polyApply, polyVApply,
hoistBinding, hoistExpr, hoistPolyVExpr, takeHoisted,
buildClosure, buildClosures,
......@@ -262,6 +262,14 @@ packPA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> VM CoreExpr
packPA ty xs len sel = liftM (`mkApps` [len, sel])
(paMethod pa_pack ty)
combinePA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> [CoreExpr]
-> VM CoreExpr
combinePA ty len sel is xs
= liftM (`mkApps` (len : sel : is : xs))
(paMethod (combinePAVar n, "combine" ++ show n ++ "PA") ty)
where
n = length xs
liftPA :: CoreExpr -> VM CoreExpr
liftPA x
= do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment