@@ -179,13 +179,20 @@ primitives =
179 ++ concatMap vecOps [ITVec IT8 16, ITVec IT16 8, ITVec IT32 4, ITVec IT64 2]
179 ++ concatMap vecOps [ITVec IT8 16, ITVec IT16 8, ITVec IT32 4, ITVec IT64 2]
181intOps :: IntTy -> [Prim]
181intOps :: IntTy -> [Prim]
182−intOps ity =
182+intOps ity = intCmps ity ++ intArith ity ++ intConv ity
184+intCmps :: IntTy -> [Prim]
183 [ iCmp ity "lt" (bCmp ity (<)) (LLt . ATInt) total
186 [ iCmp ity "lt" (bCmp ity (<)) (LLt . ATInt) total
184 , iCmp ity "lte" (bCmp ity (<=)) (LLe . ATInt) total
187 , iCmp ity "lte" (bCmp ity (<=)) (LLe . ATInt) total
185 , iCmp ity "eq" (bCmp ity (==)) (LEq . ATInt) total
188 , iCmp ity "eq" (bCmp ity (==)) (LEq . ATInt) total
186 , iCmp ity "gte" (bCmp ity (>=)) (LGe . ATInt) total
189 , iCmp ity "gte" (bCmp ity (>=)) (LGe . ATInt) total
187 , iCmp ity "gt" (bCmp ity (>)) (LGt . ATInt) total
190 , iCmp ity "gt" (bCmp ity (>)) (LGt . ATInt) total
193+intArith :: IntTy -> [Prim]
188− , iBinOp ity "add" (bitBin ity (+)) (LPlus . ATInt) total
195+ [ iBinOp ity "add" (bitBin ity (+)) (LPlus . ATInt) total
189 , iBinOp ity "sub" (bitBin ity (-)) (LMinus . ATInt) total
196 , iBinOp ity "sub" (bitBin ity (-)) (LMinus . ATInt) total
190 , iBinOp ity "mul" (bitBin ity (*)) (LTimes . ATInt) total
197 , iBinOp ity "mul" (bitBin ity (*)) (LTimes . ATInt) total
191 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
198 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
@@ -199,7 +206,11 @@ intOps ity =
199 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
206 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
200 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
207 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
201 , iUnOp ity "compl" (bUn ity complement) LCompl total
208 , iUnOp ity "compl" (bUn ity complement) LCompl total
211+intConv :: IntTy -> [Prim]
202− , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [AType . ATInt $ ity] StrType) 1 intToStr
213+ [ Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [AType . ATInt $ ity] StrType) 1 intToStr
203 (1, LIntStr ity) total
214 (1, LIntStr ity) total
204 , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (AType . ATInt $ ity)) 1 (strToInt ity)
215 , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (AType . ATInt $ ity)) 1 (strToInt ity)
205 (1, LStrInt ity) total
216 (1, LStrInt ity) total
@@ -209,12 +220,14 @@ intOps ity =
209 (1, LFloatInt ity) total
220 (1, LFloatInt ity) total
223+vecOps :: IntTy -> [Prim]
212vecOps ity@(ITVec elem count) =
224vecOps ity@(ITVec elem count) =
213 [ Prim (UN $ "prim__mk" ++ intTyName ity)
225 [ Prim (UN $ "prim__mk" ++ intTyName ity)
214 (ty (replicate count . AType . ATInt . ITFixed $ elem) (AType . ATInt $ ity))
226 (ty (replicate count . AType . ATInt . ITFixed $ elem) (AType . ATInt $ ity))
215 count (mkVecCon elem count) (count, LMkVec elem count) total
227 count (mkVecCon elem count) (count, LMkVec elem count) total
216− ]
228+ ] ++ intArith ity
230+mkVecCon :: IntTy -> Int -> [Const] -> Const
218mkVecCon ity count args = if length ints == count
231mkVecCon ity count args = if length ints == count
219 then Just (mkVec ity count ints)
232 then Just (mkVec ity count ints)
220 else error $ "Got: " ++ show args ++ " when expecting " ++ show count ++ " x " ++ show ity
233 else error $ "Got: " ++ show args ++ " when expecting " ++ show count ++ " x " ++ show ity
@@ -285,6 +298,18 @@ bsrem (ITFixed IT32) [B32 x, B32 y]
285bsrem (ITFixed IT64) [B64 x, B64 y]
298bsrem (ITFixed IT64) [B64 x, B64 y]
286 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
299 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
287bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
300bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
301+bsrem (ITVec IT8 _) [B8V x, B8V y]
303+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int8))) x y
304+bsrem (ITVec IT16 _) [B16V x, B16V y]
305+ = Just . VConstant . B16V $
306+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int16))) x y
307+bsrem (ITVec IT32 _) [B32V x, B32V y]
309+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int64))) x y
310+bsrem (ITVec IT64 _) [B64V x, B64V y]
312+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int64))) x y
288bsrem _ _ = Nothing
313bsrem _ _ = Nothing
290bsdiv :: IntTy -> [Const] -> Maybe Const
315bsdiv :: IntTy -> [Const] -> Maybe Const
@@ -297,6 +322,18 @@ bsdiv (ITFixed IT32) [B32 x, B32 y]
297bsdiv (ITFixed IT64) [B64 x, B64 y]
322bsdiv (ITFixed IT64) [B64 x, B64 y]
298 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
323 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
299bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
324bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
325+bsdiv (ITVec IT8 _) [B8V x, B8V y]
327+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int8))) x y
328+bsdiv (ITVec IT16 _) [B16V x, B16V y]
330+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int16))) x y
331+bsdiv (ITVec IT32 _) [B32V x, B32V y]
333+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int64))) x y
334+bsdiv (ITVec IT64 _) [B64V x, B64V y]
336+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int64))) x y
300bsdiv _ _ = Nothing
337bsdiv _ _ = Nothing
302bashr :: IntTy -> [Const] -> Maybe Const
339bashr :: IntTy -> [Const] -> Maybe Const
@@ -309,6 +346,18 @@ bashr (ITFixed IT32) [B32 x, B32 y]
309bashr (ITFixed IT64) [B64 x, B64 y]
346bashr (ITFixed IT64) [B64 x, B64 y]
310 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
347 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
311bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
348bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
349+bashr (ITVec IT8 _) [B8V x, B8V y]
351+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int8))) x y
352+bashr (ITVec IT16 _) [B16V x, B16V y]
354+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int16))) x y
355+bashr (ITVec IT32 _) [B32V x, B32V y]
357+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int64))) x y
358+bashr (ITVec IT64 _) [B64V x, B64V y]
360+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int64))) x y
312bashr _ _ = Nothing
361bashr _ _ = Nothing
314bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
363bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
@@ -318,6 +367,10 @@ bUn (ITFixed IT32) op [B32 x] = Just $ B32 (op x)
318bUn (ITFixed IT64) op [B64 x] = Just $ B64 (op x)
367bUn (ITFixed IT64) op [B64 x] = Just $ B64 (op x)
319bUn ITBig op [BI x] = Just $ BI (op x)
368bUn ITBig op [BI x] = Just $ BI (op x)
320bUn ITNative op [I x] = Just $ I (op x)
369bUn ITNative op [I x] = Just $ I (op x)
370+bUn (ITVec IT8 _) op [B8V x] = Just . B8V $ V.map op x
371+bUn (ITVec IT16 _) op [B16V x] = Just . B16V $ V.map op x
372+bUn (ITVec IT32 _) op [B32V x] = Just . B32V $ V.map op x
373+bUn (ITVec IT64 _) op [B64V x] = Just . B64V $ V.map op x
321bUn _ _ _ = Nothing
374bUn _ _ _ = Nothing
323bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Const] -> Maybe Const
376bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Const] -> Maybe Const
@@ -327,6 +380,10 @@ bitBin (ITFixed IT32) op [B32 x, B32 y] = Just $ B32 (op x y)
327bitBin (ITFixed IT64) op [B64 x, B64 y] = Just $ B64 (op x y)
380bitBin (ITFixed IT64) op [B64 x, B64 y] = Just $ B64 (op x y)
328bitBin ITBig op [BI x, BI y] = Just $ BI (op x y)
381bitBin ITBig op [BI x, BI y] = Just $ BI (op x y)
329bitBin ITNative op [I x, I y] = Just $ I (op x y)
382bitBin ITNative op [I x, I y] = Just $ I (op x y)
383+bitBin (ITVec IT8 _) op [B8V x, B8V y] = Just . B8V $ V.zipWith op x y
384+bitBin (ITVec IT16 _) op [B16V x, B16V y] = Just . B16V $ V.zipWith op x y
385+bitBin (ITVec IT32 _) op [B32V x, B32V y] = Just . B32V $ V.zipWith op x y
386+bitBin (ITVec IT64 _) op [B64V x, B64V y] = Just . B64V $ V.zipWith op x y
330bitBin _ _ _ = Nothing
387bitBin _ _ _ = Nothing
332bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Const] -> Maybe Const
389bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Const] -> Maybe Const