@@ -134,6 +134,7 @@ initDefs tgt =
134134 , exfun "__gmpz_init" VoidType [pmpz] False
135135 , exfun "__gmpz_init_set_str" (IntegerType 32) [pmpz, ptrI8, IntegerType 32] False
136136 , exfun "__gmpz_get_str" ptrI8 [ptrI8, IntegerType 32, pmpz] False
137+ , exfun "__gmpz_cmp" (IntegerType 32) [pmpz, pmpz] False
137138 , GlobalDefinition mainDef
138139 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
139140 where
@@ -731,14 +732,19 @@ ftyToTy FDouble = FloatingPointType 64 IEEE
731732ftyToTy FAny = valueType
732733
733734cgOp :: PrimFn -> [Operand] -> Codegen Operand
734−cgOp (LPlus ITBig) [x,y] = mpzBin "__gmpz_add" x y
735−cgOp (LMinus ITBig) [x,y] = mpzBin "__gmpz_sub" x y
736−cgOp (LTimes ITBig) [x,y] = mpzBin "__gmpz_mul" x y
737−cgOp (LSDiv ITBig) [x,y] = mpzBin "__gmpz_fdiv_q" x y
738−cgOp (LSRem ITBig) [x,y] = mpzBin "__gmpz_fdiv_r" x y
739−cgOp (LAnd ITBig) [x,y] = mpzBin "__gmpz_and" x y
740−cgOp (LOr ITBig) [x,y] = mpzBin "__gmpz_ior" x y
741−cgOp (LXOr ITBig) [x,y] = mpzBin "__gmpz_xor" x y
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
740+cgOp (LPlus ITBig) [x,y] = mpzBin "add" x y
741+cgOp (LMinus ITBig) [x,y] = mpzBin "sub" x y
742+cgOp (LTimes ITBig) [x,y] = mpzBin "mul" x y
743+cgOp (LSDiv ITBig) [x,y] = mpzBin "fdiv_q" x y
744+cgOp (LSRem ITBig) [x,y] = mpzBin "fdiv_r" x y
745+cgOp (LAnd ITBig) [x,y] = mpzBin "and" x y
746+cgOp (LOr ITBig) [x,y] = mpzBin "ior" x y
747+cgOp (LXOr ITBig) [x,y] = mpzBin "xor" x y
742748
743749cgOp (LPlus ity) [x,y] = ibin ity x y (Add False False)
744750cgOp (LMinus ity) [x,y] = ibin ity x y (Sub False False)
@@ -805,9 +811,18 @@ mpzBin name x y = do
805811 ny <- unbox (FInt ITBig) y
806812 nz <- alloc mpzTy
807813 inst' $ simpleCall "__gmpz_init" [nz]
808− inst' $ simpleCall name [nz, nx, ny]
814+ inst' $ simpleCall ("__gmpz_" ++ name) [nz, nx, ny]
809815 box (FInt ITBig) nz
810816
817+mpzCmp :: IPred.IntegerPredicate -> Operand -> Operand -> Codegen Operand
818+mpzCmp pred x y = do
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) []
824+ box (FInt IT32) i
825+
811826simpleCall :: String -> [Operand] -> Instruction
812827simpleCall name args =
813828 Call { isTailCall = False