on master help sign in
SIMD comparison primitives
commit702141b826d6565ebfff5cbefc3d606c147385d7 authorBenjamin Saunders <besaunde@sfu.ca> dateFri 21 Jun 2013, 17:05 (13 years ago) parent86b5a5b
1 file changed+28−9
src/Idris/Primitives.hs+28−9
src/Idris/Primitives.hs+28−9
@@ -183,11 +183,11 @@ intOps ity = intCmps ity ++ intArith ity ++ intConv ity
183183
184184intCmps :: IntTy -> [Prim]
185185intCmps ity =
186− [ iCmp ity "lt" (bCmp ity (<)) (LLt . ATInt) total
187− , iCmp ity "lte" (bCmp ity (<=)) (LLe . ATInt) total
188− , iCmp ity "eq" (bCmp ity (==)) (LEq . ATInt) total
189− , iCmp ity "gte" (bCmp ity (>=)) (LGe . ATInt) total
190− , iCmp ity "gt" (bCmp ity (>)) (LGt . ATInt) total
186+ [ iCmp ity "lt" False (bCmp ity (<)) (LLt . ATInt) total
187+ , iCmp ity "lte" False (bCmp ity (<=)) (LLe . ATInt) total
188+ , iCmp ity "eq" False (bCmp ity (==)) (LEq . ATInt) total
189+ , iCmp ity "gte" False (bCmp ity (>=)) (LGe . ATInt) total
190+ , iCmp ity "gt" False (bCmp ity (>)) (LGt . ATInt) total
191191 ]
192192
193193intArith :: IntTy -> [Prim]
@@ -220,6 +220,15 @@ intConv ity =
220220 (1, LFloatInt ity) total
221221 ]
222222
223+vecCmps :: IntTy -> [Prim]
224+vecCmps ity =
225+ [ iCmp ity "lt" True (bCmp ity (<)) (LLt . ATInt) total
226+ , iCmp ity "lte" True (bCmp ity (<=)) (LLe . ATInt) total
227+ , iCmp ity "eq" True (bCmp ity (==)) (LEq . ATInt) total
228+ , iCmp ity "gte" True (bCmp ity (>=)) (LGe . ATInt) total
229+ , iCmp ity "gt" True (bCmp ity (>)) (LGt . ATInt) total
230+ ]
231+
223232vecOps :: IntTy -> [Prim]
224233vecOps ity@(ITVec elem count) =
225234 [ Prim (UN $ "prim__mk" ++ intTyName ity)
@@ -232,7 +241,7 @@ vecOps ity@(ITVec elem count) =
232241 (ty [AType . ATInt $ ity, AType (ATInt (ITFixed IT32)), AType . ATInt . ITFixed $ elem]
233242 (AType . ATInt $ ity))
234243 3 (mkVecUpdate elem count) (3, LUpdateVec elem count) partial -- TODO: Ensure this reduces
235− ] ++ intArith ity
244+ ] ++ intArith ity ++ vecCmps ity
236245
237246mkVecCon :: NativeTy -> Int -> [Const] -> Maybe Const
238247mkVecCon ity count args
@@ -269,11 +278,13 @@ intTyName ITBig = "BigInt"
269278intTyName (ITFixed sized) = "B" ++ show (nativeTyWidth sized)
270279intTyName (ITVec ity count) = "B" ++ show (nativeTyWidth ity) ++ "x" ++ show count
271280
272−iCmp, iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
273−iCmp ity op impl irop totality
281+iCmp :: IntTy -> String -> Bool -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
282+iCmp ity op self impl irop totality
274283 = Prim (UN $ "prim__" ++ op ++ intTyName ity)
275− (ty (replicate 2 . AType . ATInt $ ity) (AType (ATInt ITNative)))
284+ (ty (replicate 2 . AType . ATInt $ ity) (AType (ATInt (if self then ity else ITNative))))
276285 2 impl (2, irop ity) totality
286+
287+iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
277288iBinOp ity op impl irop totality
278289 = Prim (UN $ "prim__" ++ op ++ intTyName ity)
279290 (ty (replicate 2 . AType . ATInt $ ity) (AType . ATInt $ ity))
@@ -417,6 +428,14 @@ bCmp (ITFixed IT32) op [B32 x, B32 y] = Just $ I (if (op x y) then 1 else 0)
417428bCmp (ITFixed IT64) op [B64 x, B64 y] = Just $ I (if (op x y) then 1 else 0)
418429bCmp ITBig op [BI x, BI y] = Just $ I (if (op x y) then 1 else 0)
419430bCmp ITNative op [I x, I y] = Just $ I (if (op x y) then 1 else 0)
431+bCmp (ITVec IT8 _) op [B8V x, B8V y]
432+ = Just . B8V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
433+bCmp (ITVec IT16 _) op [B16V x, B16V y]
434+ = Just . B16V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
435+bCmp (ITVec IT32 _) op [B32V x, B32V y]
436+ = Just . B32V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
437+bCmp (ITVec IT64 _) op [B64V x, B64V y]
438+ = Just . B64V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
420439bCmp _ _ _ = Nothing
421440
422441toInt :: Integral a => IntTy -> a -> Const