@@ -134,6 +134,7 @@ initDefs tgt =
134 , exfun "__gmpz_init" VoidType [pmpz] False
134 , exfun "__gmpz_init" VoidType [pmpz] False
135 , exfun "__gmpz_init_set_str" (IntegerType 32) [pmpz, ptrI8, IntegerType 32] False
135 , exfun "__gmpz_init_set_str" (IntegerType 32) [pmpz, ptrI8, IntegerType 32] False
136 , exfun "__gmpz_get_str" ptrI8 [ptrI8, IntegerType 32, pmpz] False
136 , exfun "__gmpz_get_str" ptrI8 [ptrI8, IntegerType 32, pmpz] False
137+ , exfun "__gmpz_cmp" (IntegerType 32) [pmpz, pmpz] False
137 , GlobalDefinition mainDef
138 , GlobalDefinition mainDef
138 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
139 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
@@ -731,14 +732,19 @@ ftyToTy FDouble = FloatingPointType 64 IEEE
731ftyToTy FAny = valueType
732ftyToTy FAny = valueType
733cgOp :: PrimFn -> [Operand] -> Codegen Operand
734cgOp :: PrimFn -> [Operand] -> Codegen Operand
735+cgOp (LLt ITBig) [x,y] = mpzCmp IPred.SLT x y
736+cgOp (LLe ITBig) [x,y] = mpzCmp IPred.SLE x y
737+cgOp (LEq ITBig) [x,y] = mpzCmp IPred.EQ x y
738+cgOp (LGe ITBig) [x,y] = mpzCmp IPred.SGE x y
739+cgOp (LGt ITBig) [x,y] = mpzCmp IPred.SGT x y
734−cgOp (LPlus ITBig) [x,y] = mpzBin "__gmpz_add" x y
740+cgOp (LPlus ITBig) [x,y] = mpzBin "add" x y
735−cgOp (LMinus ITBig) [x,y] = mpzBin "__gmpz_sub" x y
741+cgOp (LMinus ITBig) [x,y] = mpzBin "sub" x y
736−cgOp (LTimes ITBig) [x,y] = mpzBin "__gmpz_mul" x y
742+cgOp (LTimes ITBig) [x,y] = mpzBin "mul" x y
737−cgOp (LSDiv ITBig) [x,y] = mpzBin "__gmpz_fdiv_q" x y
743+cgOp (LSDiv ITBig) [x,y] = mpzBin "fdiv_q" x y
738−cgOp (LSRem ITBig) [x,y] = mpzBin "__gmpz_fdiv_r" x y
744+cgOp (LSRem ITBig) [x,y] = mpzBin "fdiv_r" x y
739−cgOp (LAnd ITBig) [x,y] = mpzBin "__gmpz_and" x y
745+cgOp (LAnd ITBig) [x,y] = mpzBin "and" x y
740−cgOp (LOr ITBig) [x,y] = mpzBin "__gmpz_ior" x y
746+cgOp (LOr ITBig) [x,y] = mpzBin "ior" x y
741−cgOp (LXOr ITBig) [x,y] = mpzBin "__gmpz_xor" x y
747+cgOp (LXOr ITBig) [x,y] = mpzBin "xor" x y
743cgOp (LPlus ity) [x,y] = ibin ity x y (Add False False)
749cgOp (LPlus ity) [x,y] = ibin ity x y (Add False False)
744cgOp (LMinus ity) [x,y] = ibin ity x y (Sub False False)
750cgOp (LMinus ity) [x,y] = ibin ity x y (Sub False False)
@@ -805,9 +811,18 @@ mpzBin name x y = do
805 ny <- unbox (FInt ITBig) y
811 ny <- unbox (FInt ITBig) y
806 nz <- alloc mpzTy
812 nz <- alloc mpzTy
807 inst' $ simpleCall "__gmpz_init" [nz]
813 inst' $ simpleCall "__gmpz_init" [nz]
808− inst' $ simpleCall name [nz, nx, ny]
814+ inst' $ simpleCall ("__gmpz_" ++ name) [nz, nx, ny]
809 box (FInt ITBig) nz
815 box (FInt ITBig) nz
817+mpzCmp :: IPred.IntegerPredicate -> Operand -> Operand -> Codegen Operand
819+ nx <- unbox (FInt ITBig) x
820+ ny <- unbox (FInt ITBig) y
821+ cmp <- inst $ simpleCall "__gmpz_cmp" [nx, ny]
822+ result <- inst $ ICmp pred cmp (ConstantOperand (C.Int 32 0)) []
823+ i <- inst $ ZExt result (IntegerType 32) []
811simpleCall :: String -> [Operand] -> Instruction
826simpleCall :: String -> [Operand] -> Instruction
812simpleCall name args =
827simpleCall name args =
813 Call { isTailCall = False
828 Call { isTailCall = False