@@ -36,6 +36,7 @@ import Data.Word
36import Data.Set (Set)
36import Data.Set (Set)
37import qualified Data.Set as S
37import qualified Data.Set as S
38import qualified Data.Map as M
38import qualified Data.Map as M
39+import qualified Data.Vector.Unboxed as V
39import Control.Applicative
40import Control.Applicative
40import Control.Monad.RWS
41import Control.Monad.RWS
41import Control.Monad.Writer
42import Control.Monad.Writer
@@ -709,6 +710,11 @@ cgConst' (TT.B8 i) = C.Int 8 (fromIntegral i)
709cgConst' (TT.B16 i) = C.Int 16 (fromIntegral i)
710cgConst' (TT.B16 i) = C.Int 16 (fromIntegral i)
710cgConst' (TT.B32 i) = C.Int 32 (fromIntegral i)
711cgConst' (TT.B32 i) = C.Int 32 (fromIntegral i)
711cgConst' (TT.B64 i) = C.Int 64 (fromIntegral i)
712cgConst' (TT.B64 i) = C.Int 64 (fromIntegral i)
713+cgConst' (TT.B8V v) = C.Vector (map ((C.Int 8) . fromIntegral) . V.toList $ v)
714+cgConst' (TT.B16V v) = C.Vector (map ((C.Int 16) . fromIntegral) . V.toList $ v)
715+cgConst' (TT.B32V v) = C.Vector (map ((C.Int 32) . fromIntegral) . V.toList $ v)
716+cgConst' (TT.B64V v) = C.Vector (map ((C.Int 64) . fromIntegral) . V.toList $ v)
712cgConst' (TT.BI i) = C.Array (IntegerType 8) (map (C.Int 8 . fromIntegral . fromEnum) (show i) ++ [C.Int 8 0])
718cgConst' (TT.BI i) = C.Array (IntegerType 8) (map (C.Int 8 . fromIntegral . fromEnum) (show i) ++ [C.Int 8 0])
713cgConst' (TT.Fl f) = C.Float (F.Double f)
719cgConst' (TT.Fl f) = C.Float (F.Double f)
714cgConst' (TT.Ch c) = C.Int 32 . fromIntegral . fromEnum $ c
720cgConst' (TT.Ch c) = C.Int 32 . fromIntegral . fromEnum $ c
@@ -721,6 +727,10 @@ cgConst c@(TT.B8 _) = box (FArith (ATInt (ITFixed IT8))) (ConstantOperand $ cgC
721cgConst c@(TT.B16 _) = box (FArith (ATInt (ITFixed IT16))) (ConstantOperand $ cgConst' c)
727cgConst c@(TT.B16 _) = box (FArith (ATInt (ITFixed IT16))) (ConstantOperand $ cgConst' c)
722cgConst c@(TT.B32 _) = box (FArith (ATInt (ITFixed IT32))) (ConstantOperand $ cgConst' c)
728cgConst c@(TT.B32 _) = box (FArith (ATInt (ITFixed IT32))) (ConstantOperand $ cgConst' c)
723cgConst c@(TT.B64 _) = box (FArith (ATInt (ITFixed IT64))) (ConstantOperand $ cgConst' c)
729cgConst c@(TT.B64 _) = box (FArith (ATInt (ITFixed IT64))) (ConstantOperand $ cgConst' c)
730+cgConst c@(TT.B8V v) = box (FArith (ATInt (ITVec IT8 (V.length v)))) (ConstantOperand $ cgConst' c)
731+cgConst c@(TT.B16V v) = box (FArith (ATInt (ITVec IT16 (V.length v)))) (ConstantOperand $ cgConst' c)
732+cgConst c@(TT.B32V v) = box (FArith (ATInt (ITVec IT32 (V.length v)))) (ConstantOperand $ cgConst' c)
733+cgConst c@(TT.B64V v) = box (FArith (ATInt (ITVec IT64 (V.length v)))) (ConstantOperand $ cgConst' c)
724cgConst c@(TT.Fl _) = box (FArith ATFloat) (ConstantOperand $ cgConst' c)
734cgConst c@(TT.Fl _) = box (FArith ATFloat) (ConstantOperand $ cgConst' c)
725cgConst c@(TT.Ch _) = box FChar (ConstantOperand $ cgConst' c)
735cgConst c@(TT.Ch _) = box FChar (ConstantOperand $ cgConst' c)
726cgConst c@(TT.Str s) = do
736cgConst c@(TT.Str s) = do
@@ -782,6 +792,8 @@ ftyToTy :: FType -> Type
782ftyToTy (FArith (ATInt ITNative)) = IntegerType 32
792ftyToTy (FArith (ATInt ITNative)) = IntegerType 32
783ftyToTy (FArith (ATInt ITBig)) = PointerType mpzTy (AddrSpace 0)
793ftyToTy (FArith (ATInt ITBig)) = PointerType mpzTy (AddrSpace 0)
784ftyToTy (FArith (ATInt (ITFixed ty))) = IntegerType (fromIntegral $ nativeTyWidth ty)
794ftyToTy (FArith (ATInt (ITFixed ty))) = IntegerType (fromIntegral $ nativeTyWidth ty)
795+ftyToTy (FArith (ATInt (ITVec e c)))
796+ = VectorType (fromIntegral c) (IntegerType (fromIntegral $ nativeTyWidth e))
785ftyToTy FChar = IntegerType 32
797ftyToTy FChar = IntegerType 32
786ftyToTy FString = PointerType (IntegerType 8) (AddrSpace 0)
798ftyToTy FString = PointerType (IntegerType 8) (AddrSpace 0)
787ftyToTy FUnit = VoidType
799ftyToTy FUnit = VoidType
@@ -863,6 +875,27 @@ cgOp (LASHR ity) [x,y] = ibin ity x y (AShr False)
864cgOp LNoOp xs = return $ last xs
876cgOp LNoOp xs = return $ last xs
878+cgOp (LMkVec ety c) xs | c == length xs = do
879+ nxs <- mapM (unbox (FArith (ATInt (ITFixed ety)))) xs
880+ vec <- foldM (\v (e, i) -> inst $ InsertElement v e (ConstantOperand (C.Int 32 i)) [])
881+ (ConstantOperand $ C.Vector (replicate c (C.Undef (IntegerType . fromIntegral $ nativeTyWidth ety))))
883+ box (FArith (ATInt (ITVec ety c))) vec
885+cgOp (LIdxVec ety c) [v,i] = do
886+ nv <- unbox (FArith (ATInt (ITVec ety c))) v
887+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
888+ elt <- inst $ ExtractElement nv ni []
889+ box (FArith (ATInt (ITFixed ety))) elt
891+cgOp (LUpdateVec ety c) [v,i,e] = do
892+ let fty = FArith (ATInt (ITVec ety c))
894+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
895+ ne <- unbox (FArith (ATInt (ITFixed ety))) e
896+ nv' <- inst $ InsertElement nv ne ni []
866cgOp LStrEq [x,y] = do
899cgOp LStrEq [x,y] = do
867 x' <- unbox FString x
900 x' <- unbox FString x
868 y' <- unbox FString y
901 y' <- unbox FString y
@@ -1015,8 +1048,12 @@ iCmp ity pred x y = do
1015 nx <- unbox (FArith (ATInt ity)) x
1048 nx <- unbox (FArith (ATInt ity)) x
1016 ny <- unbox (FArith (ATInt ity)) y
1049 ny <- unbox (FArith (ATInt ity)) y
1017 nr <- inst $ ICmp pred nx ny []
1050 nr <- inst $ ICmp pred nx ny []
1018− nr' <- inst $ ZExt nr (IntegerType 32) []
1051+ nr' <- inst $ SExt nr (ftyToTy $ cmpResultTy ity) []
1052+ box (cmpResultTy ity) nr'
1054+cmpResultTy :: IntTy -> FType
1055+cmpResultTy v@(ITVec _ _) = FArith (ATInt v)
1019− box (FArith (ATInt (ITFixed IT32))) nr'
1056+cmpResultTy _ = FArith (ATInt (ITFixed IT32))
1021mpzBin :: String -> Operand -> Operand -> Codegen Operand
1058mpzBin :: String -> Operand -> Operand -> Codegen Operand
1022mpzBin name x y = do
1059mpzBin name x y = do