
Andreas Klebinger pushed to branch wip/andreask/interpreter_primops at Glasgow Haskell Compiler / GHC Commits: 1add43cb by Andreas Klebinger at 2025-05-19T17:18:07+02:00 Interpreter: Add limited support for direct primop evaluation. This commit adds support for a number of primops directly to the interpreter. This avoids the indirection of going through the primop wrapper for those primops speeding interpretation of optimized code up massively. Code involving IntSet runs about 25% faster with optimized core and these changes. For core without breakpoints it's even more pronouced and I saw reductions in runtime by up to 50%. Running GHC itself in the interpreter was sped up by ~15% through this change. Additionally this comment does a few other related changes: testsuite: * Run foundation test in ghci and ghci-opt ways to test these primops. * Vastly expand the foundation test to cover all basic primops by comparing result with the result of calling the wrapper. Interpreter: * When pushing arguments for interpreted primops extend each argument to at least word with when pushing. This avoids some issues with big endian. We can revisit this if it causes performance issues. * Restructure the stack chunk check logic. There are now macros for read accesses which might cross stack chunk boundries and macros which omit the checks which are used when we statically know we access an address in the current stack chunk. - - - - - 17 changed files: - compiler/GHC/Builtin/primops.txt.pp - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/Instr.hs - compiler/GHC/StgToByteCode.hs - rts/Disassembler.c - rts/Interpreter.c - rts/include/rts/Bytecodes.h - testsuite/tests/codeGen/should_run/all.T - + testsuite/tests/ghci/all.T - + testsuite/tests/ghci/ghci-mem-primops.hs - + testsuite/tests/ghci/ghci-mem-primops.script - + testsuite/tests/ghci/ghci-mem-primops.stdout - testsuite/tests/numeric/should_run/all.T - testsuite/tests/numeric/should_run/foundation.hs - testsuite/tests/numeric/should_run/foundation.stdout - utils/genprimopcode/Main.hs - utils/genprimopcode/Syntax.hs Changes: ===================================== compiler/GHC/Builtin/primops.txt.pp ===================================== @@ -147,6 +147,7 @@ defaults fixity = Nothing vector = [] deprecated_msg = {} -- A non-empty message indicates deprecation + div_like = False -- Second argument expected to be non zero - used for tests -- Note [When do out-of-line primops go in primops.txt.pp] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -296,14 +297,18 @@ primop Int8MulOp "timesInt8#" GenPrimOp Int8# -> Int8# -> Int8# primop Int8QuotOp "quotInt8#" GenPrimOp Int8# -> Int8# -> Int8# with effect = CanFail + div_like = True primop Int8RemOp "remInt8#" GenPrimOp Int8# -> Int8# -> Int8# with effect = CanFail + div_like = True + primop Int8QuotRemOp "quotRemInt8#" GenPrimOp Int8# -> Int8# -> (# Int8#, Int8# #) with effect = CanFail + div_like = True primop Int8SllOp "uncheckedShiftLInt8#" GenPrimOp Int8# -> Int# -> Int8# primop Int8SraOp "uncheckedShiftRAInt8#" GenPrimOp Int8# -> Int# -> Int8# @@ -342,14 +347,17 @@ primop Word8MulOp "timesWord8#" GenPrimOp Word8# -> Word8# -> Word8# primop Word8QuotOp "quotWord8#" GenPrimOp Word8# -> Word8# -> Word8# with effect = CanFail + div_like = True primop Word8RemOp "remWord8#" GenPrimOp Word8# -> Word8# -> Word8# with effect = CanFail + div_like = True primop Word8QuotRemOp "quotRemWord8#" GenPrimOp Word8# -> Word8# -> (# Word8#, Word8# #) with effect = CanFail + div_like = True primop Word8AndOp "andWord8#" GenPrimOp Word8# -> Word8# -> Word8# with commutable = True @@ -400,14 +408,17 @@ primop Int16MulOp "timesInt16#" GenPrimOp Int16# -> Int16# -> Int16# primop Int16QuotOp "quotInt16#" GenPrimOp Int16# -> Int16# -> Int16# with effect = CanFail + div_like = True primop Int16RemOp "remInt16#" GenPrimOp Int16# -> Int16# -> Int16# with effect = CanFail + div_like = True primop Int16QuotRemOp "quotRemInt16#" GenPrimOp Int16# -> Int16# -> (# Int16#, Int16# #) with effect = CanFail + div_like = True primop Int16SllOp "uncheckedShiftLInt16#" GenPrimOp Int16# -> Int# -> Int16# primop Int16SraOp "uncheckedShiftRAInt16#" GenPrimOp Int16# -> Int# -> Int16# @@ -446,14 +457,17 @@ primop Word16MulOp "timesWord16#" GenPrimOp Word16# -> Word16# -> Word16# primop Word16QuotOp "quotWord16#" GenPrimOp Word16# -> Word16# -> Word16# with effect = CanFail + div_like = True primop Word16RemOp "remWord16#" GenPrimOp Word16# -> Word16# -> Word16# with effect = CanFail + div_like = True primop Word16QuotRemOp "quotRemWord16#" GenPrimOp Word16# -> Word16# -> (# Word16#, Word16# #) with effect = CanFail + div_like = True primop Word16AndOp "andWord16#" GenPrimOp Word16# -> Word16# -> Word16# with commutable = True @@ -504,14 +518,17 @@ primop Int32MulOp "timesInt32#" GenPrimOp Int32# -> Int32# -> Int32# primop Int32QuotOp "quotInt32#" GenPrimOp Int32# -> Int32# -> Int32# with effect = CanFail + div_like = True primop Int32RemOp "remInt32#" GenPrimOp Int32# -> Int32# -> Int32# with effect = CanFail + div_like = True primop Int32QuotRemOp "quotRemInt32#" GenPrimOp Int32# -> Int32# -> (# Int32#, Int32# #) with effect = CanFail + div_like = True primop Int32SllOp "uncheckedShiftLInt32#" GenPrimOp Int32# -> Int# -> Int32# primop Int32SraOp "uncheckedShiftRAInt32#" GenPrimOp Int32# -> Int# -> Int32# @@ -550,14 +567,17 @@ primop Word32MulOp "timesWord32#" GenPrimOp Word32# -> Word32# -> Word32# primop Word32QuotOp "quotWord32#" GenPrimOp Word32# -> Word32# -> Word32# with effect = CanFail + div_like = True primop Word32RemOp "remWord32#" GenPrimOp Word32# -> Word32# -> Word32# with effect = CanFail + div_like = True primop Word32QuotRemOp "quotRemWord32#" GenPrimOp Word32# -> Word32# -> (# Word32#, Word32# #) with effect = CanFail + div_like = True primop Word32AndOp "andWord32#" GenPrimOp Word32# -> Word32# -> Word32# with commutable = True @@ -608,10 +628,12 @@ primop Int64MulOp "timesInt64#" GenPrimOp Int64# -> Int64# -> Int64# primop Int64QuotOp "quotInt64#" GenPrimOp Int64# -> Int64# -> Int64# with effect = CanFail + div_like = True primop Int64RemOp "remInt64#" GenPrimOp Int64# -> Int64# -> Int64# with effect = CanFail + div_like = True primop Int64SllOp "uncheckedIShiftL64#" GenPrimOp Int64# -> Int# -> Int64# primop Int64SraOp "uncheckedIShiftRA64#" GenPrimOp Int64# -> Int# -> Int64# @@ -650,10 +672,12 @@ primop Word64MulOp "timesWord64#" GenPrimOp Word64# -> Word64# -> Word64# primop Word64QuotOp "quotWord64#" GenPrimOp Word64# -> Word64# -> Word64# with effect = CanFail + div_like = True primop Word64RemOp "remWord64#" GenPrimOp Word64# -> Word64# -> Word64# with effect = CanFail + div_like = True primop Word64AndOp "and64#" GenPrimOp Word64# -> Word64# -> Word64# with commutable = True @@ -737,6 +761,7 @@ primop IntQuotOp "quotInt#" GenPrimOp zero. } with effect = CanFail + div_like = True primop IntRemOp "remInt#" GenPrimOp Int# -> Int# -> Int# @@ -744,11 +769,13 @@ primop IntRemOp "remInt#" GenPrimOp behavior is undefined if the second argument is zero. } with effect = CanFail + div_like = True primop IntQuotRemOp "quotRemInt#" GenPrimOp Int# -> Int# -> (# Int#, Int# #) {Rounds towards zero.} with effect = CanFail + div_like = True primop IntAndOp "andI#" GenPrimOp Int# -> Int# -> Int# {Bitwise "and".} @@ -886,19 +913,23 @@ primop WordMul2Op "timesWord2#" GenPrimOp primop WordQuotOp "quotWord#" GenPrimOp Word# -> Word# -> Word# with effect = CanFail + div_like = True primop WordRemOp "remWord#" GenPrimOp Word# -> Word# -> Word# with effect = CanFail + div_like = True primop WordQuotRemOp "quotRemWord#" GenPrimOp Word# -> Word# -> (# Word#, Word# #) with effect = CanFail + div_like = True primop WordQuotRem2Op "quotRemWord2#" GenPrimOp Word# -> Word# -> Word# -> (# Word#, Word# #) { Takes high word of dividend, then low word of dividend, then divisor. Requires that high word < divisor.} with effect = CanFail + div_like = True primop WordAndOp "and#" GenPrimOp Word# -> Word# -> Word# with commutable = True @@ -4166,6 +4197,7 @@ primop VecQuotOp "quot#" GenPrimOp Do not expect high performance. } with effect = CanFail vector = INT_VECTOR_TYPES + div_like = True primop VecRemOp "rem#" GenPrimOp VECTOR -> VECTOR -> VECTOR @@ -4175,6 +4207,8 @@ primop VecRemOp "rem#" GenPrimOp Do not expect high performance. } with effect = CanFail vector = INT_VECTOR_TYPES + div_like = True + primop VecNegOp "negate#" GenPrimOp VECTOR -> VECTOR ===================================== compiler/GHC/ByteCode/Asm.hs ===================================== @@ -732,6 +732,143 @@ assembleI platform i = case i of CCALL off m_addr i -> do np <- addr m_addr emit_ bci_CCALL [wOp off, Op np, SmallOp i] PRIMCALL -> emit_ bci_PRIMCALL [] + + OP_ADD w -> case w of + W64 -> emit_ bci_OP_ADD_64 [] + W32 -> emit_ bci_OP_ADD_32 [] + W16 -> emit_ bci_OP_ADD_16 [] + W8 -> emit_ bci_OP_ADD_08 [] + _ -> unsupported_width + OP_SUB w -> case w of + W64 -> emit_ bci_OP_SUB_64 [] + W32 -> emit_ bci_OP_SUB_32 [] + W16 -> emit_ bci_OP_SUB_16 [] + W8 -> emit_ bci_OP_SUB_08 [] + _ -> unsupported_width + OP_AND w -> case w of + W64 -> emit_ bci_OP_AND_64 [] + W32 -> emit_ bci_OP_AND_32 [] + W16 -> emit_ bci_OP_AND_16 [] + W8 -> emit_ bci_OP_AND_08 [] + _ -> unsupported_width + OP_XOR w -> case w of + W64 -> emit_ bci_OP_XOR_64 [] + W32 -> emit_ bci_OP_XOR_32 [] + W16 -> emit_ bci_OP_XOR_16 [] + W8 -> emit_ bci_OP_XOR_08 [] + _ -> unsupported_width + OP_OR w -> case w of + W64 -> emit_ bci_OP_OR_64 [] + W32 -> emit_ bci_OP_OR_32 [] + W16 -> emit_ bci_OP_OR_16 [] + W8 -> emit_ bci_OP_OR_08 [] + _ -> unsupported_width + OP_NOT w -> case w of + W64 -> emit_ bci_OP_NOT_64 [] + W32 -> emit_ bci_OP_NOT_32 [] + W16 -> emit_ bci_OP_NOT_16 [] + W8 -> emit_ bci_OP_NOT_08 [] + _ -> unsupported_width + OP_NEG w -> case w of + W64 -> emit_ bci_OP_NEG_64 [] + W32 -> emit_ bci_OP_NEG_32 [] + W16 -> emit_ bci_OP_NEG_16 [] + W8 -> emit_ bci_OP_NEG_08 [] + _ -> unsupported_width + OP_MUL w -> case w of + W64 -> emit_ bci_OP_MUL_64 [] + W32 -> emit_ bci_OP_MUL_32 [] + W16 -> emit_ bci_OP_MUL_16 [] + W8 -> emit_ bci_OP_MUL_08 [] + _ -> unsupported_width + OP_SHL w -> case w of + W64 -> emit_ bci_OP_SHL_64 [] + W32 -> emit_ bci_OP_SHL_32 [] + W16 -> emit_ bci_OP_SHL_16 [] + W8 -> emit_ bci_OP_SHL_08 [] + _ -> unsupported_width + OP_ASR w -> case w of + W64 -> emit_ bci_OP_ASR_64 [] + W32 -> emit_ bci_OP_ASR_32 [] + W16 -> emit_ bci_OP_ASR_16 [] + W8 -> emit_ bci_OP_ASR_08 [] + _ -> unsupported_width + OP_LSR w -> case w of + W64 -> emit_ bci_OP_LSR_64 [] + W32 -> emit_ bci_OP_LSR_32 [] + W16 -> emit_ bci_OP_LSR_16 [] + W8 -> emit_ bci_OP_LSR_08 [] + _ -> unsupported_width + + OP_NEQ w -> case w of + W64 -> emit_ bci_OP_NEQ_64 [] + W32 -> emit_ bci_OP_NEQ_32 [] + W16 -> emit_ bci_OP_NEQ_16 [] + W8 -> emit_ bci_OP_NEQ_08 [] + _ -> unsupported_width + OP_EQ w -> case w of + W64 -> emit_ bci_OP_EQ_64 [] + W32 -> emit_ bci_OP_EQ_32 [] + W16 -> emit_ bci_OP_EQ_16 [] + W8 -> emit_ bci_OP_EQ_08 [] + _ -> unsupported_width + + OP_U_LT w -> case w of + W64 -> emit_ bci_OP_U_LT_64 [] + W32 -> emit_ bci_OP_U_LT_32 [] + W16 -> emit_ bci_OP_U_LT_16 [] + W8 -> emit_ bci_OP_U_LT_08 [] + _ -> unsupported_width + OP_S_LT w -> case w of + W64 -> emit_ bci_OP_S_LT_64 [] + W32 -> emit_ bci_OP_S_LT_32 [] + W16 -> emit_ bci_OP_S_LT_16 [] + W8 -> emit_ bci_OP_S_LT_08 [] + _ -> unsupported_width + OP_U_GE w -> case w of + W64 -> emit_ bci_OP_U_GE_64 [] + W32 -> emit_ bci_OP_U_GE_32 [] + W16 -> emit_ bci_OP_U_GE_16 [] + W8 -> emit_ bci_OP_U_GE_08 [] + _ -> unsupported_width + OP_S_GE w -> case w of + W64 -> emit_ bci_OP_S_GE_64 [] + W32 -> emit_ bci_OP_S_GE_32 [] + W16 -> emit_ bci_OP_S_GE_16 [] + W8 -> emit_ bci_OP_S_GE_08 [] + _ -> unsupported_width + OP_U_GT w -> case w of + W64 -> emit_ bci_OP_U_GT_64 [] + W32 -> emit_ bci_OP_U_GT_32 [] + W16 -> emit_ bci_OP_U_GT_16 [] + W8 -> emit_ bci_OP_U_GT_08 [] + _ -> unsupported_width + OP_S_GT w -> case w of + W64 -> emit_ bci_OP_S_GT_64 [] + W32 -> emit_ bci_OP_S_GT_32 [] + W16 -> emit_ bci_OP_S_GT_16 [] + W8 -> emit_ bci_OP_S_GT_08 [] + _ -> unsupported_width + OP_U_LE w -> case w of + W64 -> emit_ bci_OP_U_LE_64 [] + W32 -> emit_ bci_OP_U_LE_32 [] + W16 -> emit_ bci_OP_U_LE_16 [] + W8 -> emit_ bci_OP_U_LE_08 [] + _ -> unsupported_width + OP_S_LE w -> case w of + W64 -> emit_ bci_OP_S_LE_64 [] + W32 -> emit_ bci_OP_S_LE_32 [] + W16 -> emit_ bci_OP_S_LE_16 [] + W8 -> emit_ bci_OP_S_LE_08 [] + _ -> unsupported_width + + OP_INDEX_ADDR w -> case w of + W64 -> emit_ bci_OP_INDEX_ADDR_64 [] + W32 -> emit_ bci_OP_INDEX_ADDR_32 [] + W16 -> emit_ bci_OP_INDEX_ADDR_16 [] + W8 -> emit_ bci_OP_INDEX_ADDR_08 [] + _ -> unsupported_width + BRK_FUN arr tick_mod tick_mod_id tickx info_mod info_mod_id infox cc -> do p1 <- ptr (BCOPtrBreakArray arr) tick_addr <- addr tick_mod @@ -753,6 +890,7 @@ assembleI platform i = case i of where + unsupported_width = panic "GHC.ByteCode.Asm: Unsupported Width" emit_ = emit word_size literal :: Literal -> m Word ===================================== compiler/GHC/ByteCode/Instr.hs ===================================== @@ -14,12 +14,15 @@ module GHC.ByteCode.Instr ( import GHC.Prelude import GHC.ByteCode.Types +import GHC.Cmm.Type (Width) import GHCi.RemoteTypes import GHCi.FFI (C_ffi_cif) import GHC.StgToCmm.Layout ( ArgRep(..) ) import GHC.Utils.Outputable +import GHC.Unit.Types (UnitId) import GHC.Types.Name import GHC.Types.Literal +import GHC.Types.Unique import GHC.Core.DataCon import GHC.Builtin.PrimOps import GHC.Runtime.Heap.Layout ( StgWord ) @@ -36,8 +39,6 @@ import GHC.Stack.CCS (CostCentre) import GHC.Stg.Syntax import GHCi.BreakArray (BreakArray) import Language.Haskell.Syntax.Module.Name (ModuleName) -import GHC.Types.Unique -import GHC.Unit.Types (UnitId) -- ---------------------------------------------------------------------------- -- Bytecode instructions @@ -220,6 +221,39 @@ data BCInstr | PRIMCALL + -- Primops - The actual interpreter instructions are flattened into 64/32/16/8 wide + -- instructions. But for generating code it's handy to have the width as argument + -- to avoid duplication. + | OP_ADD !Width + | OP_SUB !Width + | OP_AND !Width + | OP_XOR !Width + | OP_MUL !Width + | OP_SHL !Width + | OP_ASR !Width + | OP_LSR !Width + | OP_OR !Width + + | OP_NOT !Width + | OP_NEG !Width + + | OP_NEQ !Width + | OP_EQ !Width + + | OP_U_LT !Width + | OP_U_GE !Width + | OP_U_GT !Width + | OP_U_LE !Width + + | OP_S_LT !Width + | OP_S_GE !Width + | OP_S_GT !Width + | OP_S_LE !Width + + -- Always puts at least a machine word on the stack. + -- We zero extend the result we put on the stack according to host byte order. + | OP_INDEX_ADDR !Width + -- For doing magic ByteArray passing to foreign calls | SWIZZLE !WordOff -- to the ptr N words down the stack, !Int -- add M @@ -401,6 +435,32 @@ instance Outputable BCInstr where 0x2 -> text "(unsafe)" _ -> empty) ppr PRIMCALL = text "PRIMCALL" + + ppr (OP_ADD w) = text "OP_ADD_" <> ppr w + ppr (OP_SUB w) = text "OP_SUB_" <> ppr w + ppr (OP_AND w) = text "OP_AND_" <> ppr w + ppr (OP_XOR w) = text "OP_XOR_" <> ppr w + ppr (OP_OR w) = text "OP_OR_" <> ppr w + ppr (OP_NOT w) = text "OP_NOT_" <> ppr w + ppr (OP_NEG w) = text "OP_NEG_" <> ppr w + ppr (OP_MUL w) = text "OP_MUL_" <> ppr w + ppr (OP_SHL w) = text "OP_SHL_" <> ppr w + ppr (OP_ASR w) = text "OP_ASR_" <> ppr w + ppr (OP_LSR w) = text "OP_LSR_" <> ppr w + + ppr (OP_EQ w) = text "OP_EQ_" <> ppr w + ppr (OP_NEQ w) = text "OP_NEQ_" <> ppr w + ppr (OP_S_LT w) = text "OP_S_LT_" <> ppr w + ppr (OP_S_GE w) = text "OP_S_GE_" <> ppr w + ppr (OP_S_GT w) = text "OP_S_GT_" <> ppr w + ppr (OP_S_LE w) = text "OP_S_LE_" <> ppr w + ppr (OP_U_LT w) = text "OP_U_LT_" <> ppr w + ppr (OP_U_GE w) = text "OP_U_GE_" <> ppr w + ppr (OP_U_GT w) = text "OP_U_GT_" <> ppr w + ppr (OP_U_LE w) = text "OP_U_LE_" <> ppr w + + ppr (OP_INDEX_ADDR w) = text "OP_INDEX_ADDR_" <> ppr w + ppr (SWIZZLE stkoff n) = text "SWIZZLE " <+> text "stkoff" <+> ppr stkoff <+> text "by" <+> ppr n ppr ENTER = text "ENTER" @@ -509,6 +569,31 @@ bciStackUse RETURN{} = 1 -- pushes stg_ret_X for some X bciStackUse RETURN_TUPLE{} = 1 -- pushes stg_ret_t header bciStackUse CCALL{} = 0 bciStackUse PRIMCALL{} = 1 -- pushes stg_primcall +bciStackUse OP_ADD{} = 0 -- We overestimate, it's -1 actually ... +bciStackUse OP_SUB{} = 0 +bciStackUse OP_AND{} = 0 +bciStackUse OP_XOR{} = 0 +bciStackUse OP_OR{} = 0 +bciStackUse OP_NOT{} = 0 +bciStackUse OP_NEG{} = 0 +bciStackUse OP_MUL{} = 0 +bciStackUse OP_SHL{} = 0 +bciStackUse OP_ASR{} = 0 +bciStackUse OP_LSR{} = 0 + +bciStackUse OP_NEQ{} = 0 +bciStackUse OP_EQ{} = 0 +bciStackUse OP_S_LT{} = 0 +bciStackUse OP_S_GT{} = 0 +bciStackUse OP_S_LE{} = 0 +bciStackUse OP_S_GE{} = 0 +bciStackUse OP_U_LT{} = 0 +bciStackUse OP_U_GT{} = 0 +bciStackUse OP_U_LE{} = 0 +bciStackUse OP_U_GE{} = 0 + +bciStackUse OP_INDEX_ADDR{} = 0 + bciStackUse SWIZZLE{} = 0 bciStackUse BRK_FUN{} = 0 ===================================== compiler/GHC/StgToByteCode.hs ===================================== @@ -58,6 +58,7 @@ import GHC.Builtin.Uniques import GHC.Data.FastString import GHC.Utils.Panic import GHC.Utils.Exception (evaluate) +import GHC.CmmToAsm.Config (platformWordWidth) import GHC.StgToCmm.Closure ( NonVoid(..), fromNonVoid, idPrimRepU, addIdReps, addArgReps, assertNonVoidIds, assertNonVoidStgArgs ) @@ -582,8 +583,7 @@ returnUnboxedTuple d s p es = do -- Compile code to apply the given expression to the remaining args -- on the stack, returning a HNF. -schemeE - :: StackDepth -> Sequel -> BCEnv -> CgStgExpr -> BcM BCInstrList +schemeE :: StackDepth -> Sequel -> BCEnv -> CgStgExpr -> BcM BCInstrList schemeE d s p (StgLit lit) = returnUnliftedAtom d s p (StgLitArg lit) schemeE d s p (StgApp x []) | isUnliftedType (idType x) = returnUnliftedAtom d s p (StgVarArg x) @@ -734,8 +734,14 @@ schemeT d s p (StgOpApp (StgFCallOp (CCall ccall_spec) _ty) args result_ty) then generateCCall d s p ccall_spec result_ty args else unsupportedCConvException -schemeT d s p (StgOpApp (StgPrimOp op) args _ty) - = doTailCall d s p (primOpId op) (reverse args) +schemeT d s p (StgOpApp (StgPrimOp op) args _ty) = do + profile <- getProfile + let platform = profilePlatform profile + case doPrimOp platform op d s p args of + -- Can we do this right in the interpreter? + Just prim_code -> prim_code + -- Otherwise we have to do a call to the primop wrapper instead :( + _ -> doTailCall d s p (primOpId op) (reverse args) schemeT d s p (StgOpApp (StgPrimCallOp (PrimCall label unit)) args result_ty) = generatePrimCall d s p label (Just unit) result_ty args @@ -830,6 +836,300 @@ doTailCall init_d s p fn args = do (final_d, more_push_code) <- push_seq (d + sz) args return (final_d, push_code `appOL` more_push_code) +doPrimOp :: Platform + -> PrimOp + -> StackDepth + -> Sequel + -> BCEnv + -> [StgArg] + -> Maybe (BcM BCInstrList) +doPrimOp platform op init_d s p args = + case op of + IntAddOp -> sizedPrimOp OP_ADD + Int64AddOp -> only64bit $ sizedPrimOp OP_ADD + Int32AddOp -> sizedPrimOp OP_ADD + Int16AddOp -> sizedPrimOp OP_ADD + Int8AddOp -> sizedPrimOp OP_ADD + WordAddOp -> sizedPrimOp OP_ADD + Word64AddOp -> only64bit $ sizedPrimOp OP_ADD + Word32AddOp -> sizedPrimOp OP_ADD + Word16AddOp -> sizedPrimOp OP_ADD + Word8AddOp -> sizedPrimOp OP_ADD + AddrAddOp -> sizedPrimOp OP_ADD + + IntMulOp -> sizedPrimOp OP_MUL + Int64MulOp -> only64bit $ sizedPrimOp OP_MUL + Int32MulOp -> sizedPrimOp OP_MUL + Int16MulOp -> sizedPrimOp OP_MUL + Int8MulOp -> sizedPrimOp OP_MUL + WordMulOp -> sizedPrimOp OP_MUL + Word64MulOp -> only64bit $ sizedPrimOp OP_MUL + Word32MulOp -> sizedPrimOp OP_MUL + Word16MulOp -> sizedPrimOp OP_MUL + Word8MulOp -> sizedPrimOp OP_MUL + + IntSubOp -> sizedPrimOp OP_SUB + WordSubOp -> sizedPrimOp OP_SUB + Int64SubOp -> only64bit $ sizedPrimOp OP_SUB + Int32SubOp -> sizedPrimOp OP_SUB + Int16SubOp -> sizedPrimOp OP_SUB + Int8SubOp -> sizedPrimOp OP_SUB + Word64SubOp -> only64bit $ sizedPrimOp OP_SUB + Word32SubOp -> sizedPrimOp OP_SUB + Word16SubOp -> sizedPrimOp OP_SUB + Word8SubOp -> sizedPrimOp OP_SUB + AddrSubOp -> sizedPrimOp OP_SUB + + IntAndOp -> sizedPrimOp OP_AND + WordAndOp -> sizedPrimOp OP_AND + Word64AndOp -> only64bit $ sizedPrimOp OP_AND + Word32AndOp -> sizedPrimOp OP_AND + Word16AndOp -> sizedPrimOp OP_AND + Word8AndOp -> sizedPrimOp OP_AND + + IntNotOp -> sizedPrimOp OP_NOT + WordNotOp -> sizedPrimOp OP_NOT + Word64NotOp -> only64bit $ sizedPrimOp OP_NOT + Word32NotOp -> sizedPrimOp OP_NOT + Word16NotOp -> sizedPrimOp OP_NOT + Word8NotOp -> sizedPrimOp OP_NOT + + IntXorOp -> sizedPrimOp OP_XOR + WordXorOp -> sizedPrimOp OP_XOR + Word64XorOp -> only64bit $ sizedPrimOp OP_XOR + Word32XorOp -> sizedPrimOp OP_XOR + Word16XorOp -> sizedPrimOp OP_XOR + Word8XorOp -> sizedPrimOp OP_XOR + + IntOrOp -> sizedPrimOp OP_OR + WordOrOp -> sizedPrimOp OP_OR + Word64OrOp -> only64bit $ sizedPrimOp OP_OR + Word32OrOp -> sizedPrimOp OP_OR + Word16OrOp -> sizedPrimOp OP_OR + Word8OrOp -> sizedPrimOp OP_OR + + WordSllOp -> sizedPrimOp OP_SHL + Word64SllOp -> only64bit $ sizedPrimOp OP_SHL -- check 32bit platform + Word32SllOp -> sizedPrimOp OP_SHL + Word16SllOp -> sizedPrimOp OP_SHL + Word8SllOp -> sizedPrimOp OP_SHL + IntSllOp -> sizedPrimOp OP_SHL + Int64SllOp -> only64bit $ sizedPrimOp OP_SHL + Int32SllOp -> sizedPrimOp OP_SHL + Int16SllOp -> sizedPrimOp OP_SHL + Int8SllOp -> sizedPrimOp OP_SHL + + WordSrlOp -> sizedPrimOp OP_LSR + Word64SrlOp -> only64bit $ sizedPrimOp OP_LSR + Word32SrlOp -> sizedPrimOp OP_LSR + Word16SrlOp -> sizedPrimOp OP_LSR + Word8SrlOp -> sizedPrimOp OP_LSR + IntSrlOp -> sizedPrimOp OP_LSR + Int64SrlOp -> only64bit $ sizedPrimOp OP_LSR -- check 32bit platform + Int32SrlOp -> sizedPrimOp OP_LSR + Int16SrlOp -> sizedPrimOp OP_LSR + Int8SrlOp -> sizedPrimOp OP_LSR + + IntSraOp -> sizedPrimOp OP_ASR + Int64SraOp -> only64bit $ sizedPrimOp OP_ASR -- check 32bit platform + Int32SraOp -> sizedPrimOp OP_ASR + Int16SraOp -> sizedPrimOp OP_ASR + Int8SraOp -> sizedPrimOp OP_ASR + + + IntNeOp -> sizedPrimOp OP_NEQ + Int64NeOp -> only64bit $ sizedPrimOp OP_NEQ + Int32NeOp -> sizedPrimOp OP_NEQ + Int16NeOp -> sizedPrimOp OP_NEQ + Int8NeOp -> sizedPrimOp OP_NEQ + WordNeOp -> sizedPrimOp OP_NEQ + Word64NeOp -> only64bit $ sizedPrimOp OP_NEQ + Word32NeOp -> sizedPrimOp OP_NEQ + Word16NeOp -> sizedPrimOp OP_NEQ + Word8NeOp -> sizedPrimOp OP_NEQ + AddrNeOp -> sizedPrimOp OP_NEQ + + IntEqOp -> sizedPrimOp OP_EQ + Int64EqOp -> only64bit $ sizedPrimOp OP_EQ + Int32EqOp -> sizedPrimOp OP_EQ + Int16EqOp -> sizedPrimOp OP_EQ + Int8EqOp -> sizedPrimOp OP_EQ + WordEqOp -> sizedPrimOp OP_EQ + Word64EqOp -> only64bit $ sizedPrimOp OP_EQ + Word32EqOp -> sizedPrimOp OP_EQ + Word16EqOp -> sizedPrimOp OP_EQ + Word8EqOp -> sizedPrimOp OP_EQ + AddrEqOp -> sizedPrimOp OP_EQ + CharEqOp -> sizedPrimOp OP_EQ + + IntLtOp -> sizedPrimOp OP_S_LT + Int64LtOp -> only64bit $ sizedPrimOp OP_S_LT + Int32LtOp -> sizedPrimOp OP_S_LT + Int16LtOp -> sizedPrimOp OP_S_LT + Int8LtOp -> sizedPrimOp OP_S_LT + WordLtOp -> sizedPrimOp OP_U_LT + Word64LtOp -> only64bit $ sizedPrimOp OP_U_LT + Word32LtOp -> sizedPrimOp OP_U_LT + Word16LtOp -> sizedPrimOp OP_U_LT + Word8LtOp -> sizedPrimOp OP_U_LT + AddrLtOp -> sizedPrimOp OP_U_LT + CharLtOp -> sizedPrimOp OP_U_LT + + IntGeOp -> sizedPrimOp OP_S_GE + Int64GeOp -> only64bit $ sizedPrimOp OP_S_GE + Int32GeOp -> sizedPrimOp OP_S_GE + Int16GeOp -> sizedPrimOp OP_S_GE + Int8GeOp -> sizedPrimOp OP_S_GE + WordGeOp -> sizedPrimOp OP_U_GE + Word64GeOp -> only64bit $ sizedPrimOp OP_U_GE + Word32GeOp -> sizedPrimOp OP_U_GE + Word16GeOp -> sizedPrimOp OP_U_GE + Word8GeOp -> sizedPrimOp OP_U_GE + AddrGeOp -> sizedPrimOp OP_U_GE + CharGeOp -> sizedPrimOp OP_U_GE + + IntGtOp -> sizedPrimOp OP_S_GT + Int64GtOp -> only64bit $ sizedPrimOp OP_S_GT + Int32GtOp -> sizedPrimOp OP_S_GT + Int16GtOp -> sizedPrimOp OP_S_GT + Int8GtOp -> sizedPrimOp OP_S_GT + WordGtOp -> sizedPrimOp OP_U_GT + Word64GtOp -> only64bit $ sizedPrimOp OP_U_GT + Word32GtOp -> sizedPrimOp OP_U_GT + Word16GtOp -> sizedPrimOp OP_U_GT + Word8GtOp -> sizedPrimOp OP_U_GT + AddrGtOp -> sizedPrimOp OP_U_GT + CharGtOp -> sizedPrimOp OP_U_GT + + IntLeOp -> sizedPrimOp OP_S_LE + Int64LeOp -> only64bit $ sizedPrimOp OP_S_LE + Int32LeOp -> sizedPrimOp OP_S_LE + Int16LeOp -> sizedPrimOp OP_S_LE + Int8LeOp -> sizedPrimOp OP_S_LE + WordLeOp -> sizedPrimOp OP_U_LE + Word64LeOp -> only64bit $ sizedPrimOp OP_U_LE + Word32LeOp -> sizedPrimOp OP_U_LE + Word16LeOp -> sizedPrimOp OP_U_LE + Word8LeOp -> sizedPrimOp OP_U_LE + AddrLeOp -> sizedPrimOp OP_U_LE + CharLeOp -> sizedPrimOp OP_U_LE + + IntNegOp -> sizedPrimOp OP_NEG + Int64NegOp -> only64bit $ sizedPrimOp OP_NEG + Int32NegOp -> sizedPrimOp OP_NEG + Int16NegOp -> sizedPrimOp OP_NEG + Int8NegOp -> sizedPrimOp OP_NEG + + IntToWordOp -> mk_conv (platformWordWidth platform) + WordToIntOp -> mk_conv (platformWordWidth platform) + Int8ToWord8Op -> mk_conv W8 + Word8ToInt8Op -> mk_conv W8 + Int16ToWord16Op -> mk_conv W16 + Word16ToInt16Op -> mk_conv W16 + Int32ToWord32Op -> mk_conv W32 + Word32ToInt32Op -> mk_conv W32 + Int64ToWord64Op -> only64bit $ mk_conv W64 + Word64ToInt64Op -> only64bit $ mk_conv W64 + IntToAddrOp -> mk_conv (platformWordWidth platform) + AddrToIntOp -> mk_conv (platformWordWidth platform) + ChrOp -> mk_conv (platformWordWidth platform) -- Int# and Char# are rep'd the same + OrdOp -> mk_conv (platformWordWidth platform) + + -- Memory primops, expand the ghci-mem-primops test if you add more. + IndexOffAddrOp_Word8 -> primOpWithRep (OP_INDEX_ADDR W8) W8 + IndexOffAddrOp_Word16 -> primOpWithRep (OP_INDEX_ADDR W16) W16 + IndexOffAddrOp_Word32 -> primOpWithRep (OP_INDEX_ADDR W32) W32 + IndexOffAddrOp_Word64 -> only64bit $ primOpWithRep (OP_INDEX_ADDR W64) W64 + + _ -> Nothing + where + only64bit = if platformWordWidth platform == W64 then id else const Nothing + primArg1Width :: StgArg -> Width + primArg1Width arg + | rep <- (stgArgRepU arg) + = case rep of + AddrRep -> platformWordWidth platform + IntRep -> platformWordWidth platform + WordRep -> platformWordWidth platform + + Int64Rep -> W64 + Word64Rep -> W64 + + Int32Rep -> W32 + Word32Rep -> W32 + + Int16Rep -> W16 + Word16Rep -> W16 + + Int8Rep -> W8 + Word8Rep -> W8 + + FloatRep -> unexpectedRep + DoubleRep -> unexpectedRep + + BoxedRep{} -> unexpectedRep + VecRep{} -> unexpectedRep + where + unexpectedRep = panic "doPrimOp: Unexpected argument rep" + + + -- TODO: The slides for the result need to be two words on 32bit for 64bit ops. + mkNReturn width + | W64 <- width = RETURN L -- L works for 64 bit on any platform + | otherwise = RETURN N -- <64bit width, fits in word on all platforms + + mkSlideWords width = if platformWordWidth platform < width then 2 else 1 + + -- Push args, execute primop, slide, return_N + -- Decides width of operation based on first argument. + sizedPrimOp op_inst = Just $ do + let width = primArg1Width (head args) + prim_code <- mkPrimOpCode init_d s p (op_inst width) $ args + let slide = mkSlideW (mkSlideWords width) (bytesToWords platform $ init_d - s) `snocOL` mkNReturn width + return $ prim_code `appOL` slide + + -- primOpWithRep op w => operation @op@ resulting in result @w@ wide. + primOpWithRep :: BCInstr -> Width -> Maybe (BcM (OrdList BCInstr)) + primOpWithRep op_inst result_width = Just $ do + prim_code <- mkPrimOpCode init_d s p op_inst $ args + let slide = mkSlideW (mkSlideWords result_width) (bytesToWords platform $ init_d - s) `snocOL` mkNReturn result_width + return $ prim_code `appOL` slide + + -- Coerce the argument, requires them to be the same size + mk_conv :: Width -> Maybe (BcM (OrdList BCInstr)) + mk_conv target_width = Just $ do + let width = primArg1Width (head args) + massert (width == target_width) + (push_code, _bytes) <- pushAtom init_d p (head args) + let slide = mkSlideW (mkSlideWords target_width) (bytesToWords platform $ init_d - s) `snocOL` mkNReturn target_width + return $ push_code `appOL` slide + +-- Push the arguments on the stack and emit the given instruction +-- Pushes at least one word per non void arg. +mkPrimOpCode + :: StackDepth + -> Sequel + -> BCEnv + -> BCInstr -- The operator + -> [StgArg] -- Args, in *reverse* order (must be fully applied) + -> BcM BCInstrList +mkPrimOpCode orig_d _ p op_inst args = app_code + where + app_code = do + profile <- getProfile + let _platform = profilePlatform profile + + do_pushery :: StackDepth -> [StgArg] -> BcM BCInstrList + do_pushery !d (arg : args) = do + (push,arg_bytes) <- pushAtom d p arg + more_push_code <- do_pushery (d + arg_bytes) args + return (push `appOL` more_push_code) + do_pushery !_d [] = do + return (unitOL op_inst) + + -- Push on the stack in the reverse order. + do_pushery orig_d (reverse args) + -- v. similar to CgStackery.findMatch, ToDo: merge findPushSeq :: [ArgRep] -> (BCInstr, Int, [ArgRep]) findPushSeq (P: P: P: P: P: P: rest) ===================================== rts/Disassembler.c ===================================== @@ -62,6 +62,26 @@ disInstr ( StgBCO *bco, int pc ) #error Cannot cope with WORD_SIZE_IN_BITS being nether 32 nor 64 #endif #define BCO_GET_LARGE_ARG ((instr & bci_FLAG_LARGE_ARGS) ? BCO_READ_NEXT_WORD : BCO_NEXT) +// For brevity +#define BELCH_INSTR_NAME(OP_NAME) \ + case bci_ ## OP_NAME: \ + debugBelch("OP_NAME\n"); \ + break + +#define BELCH_INSTR_NAME_ALL_SIZES(OP_NAME) \ + case bci_ ## OP_NAME ## _64: \ + debugBelch("#OP_NAME" "_64\n"); \ + break; \ + case bci_ ## OP_NAME ## _32: \ + debugBelch("#OP_NAME" "_32\n"); \ + break; \ + case bci_ ## OP_NAME ## _16: \ + debugBelch("#OP_NAME" "_16\n"); \ + break; \ + case bci_ ## OP_NAME ## _08: \ + debugBelch("#OP_NAME" "_08\n"); \ + break; + switch (instr & 0xff) { case bci_BRK_FUN: @@ -419,38 +439,20 @@ disInstr ( StgBCO *bco, int pc ) debugBelch("TESTEQ_P %d, fail to %d\n", instrs[pc], instrs[pc+1]); pc += 2; break; - case bci_CASEFAIL: - debugBelch("CASEFAIL\n" ); - break; + BELCH_INSTR_NAME(CASEFAIL); case bci_JMP: debugBelch("JMP to %d\n", instrs[pc]); pc += 1; break; - case bci_ENTER: - debugBelch("ENTER\n"); - break; + BELCH_INSTR_NAME(ENTER); + BELCH_INSTR_NAME(RETURN_P); + BELCH_INSTR_NAME(RETURN_N); + BELCH_INSTR_NAME(RETURN_F); + BELCH_INSTR_NAME(RETURN_D); + BELCH_INSTR_NAME(RETURN_L); + BELCH_INSTR_NAME(RETURN_V); + BELCH_INSTR_NAME(RETURN_T); - case bci_RETURN_P: - debugBelch("RETURN_P\n" ); - break; - case bci_RETURN_N: - debugBelch("RETURN_N\n" ); - break; - case bci_RETURN_F: - debugBelch("RETURN_F\n" ); - break; - case bci_RETURN_D: - debugBelch("RETURN_D\n" ); - break; - case bci_RETURN_L: - debugBelch("RETURN_L\n" ); - break; - case bci_RETURN_V: - debugBelch("RETURN_V\n" ); - break; - case bci_RETURN_T: - debugBelch("RETURN_T\n "); - break; case bci_BCO_NAME: { const char *name = (const char*) literals[instrs[pc]]; @@ -459,6 +461,33 @@ disInstr ( StgBCO *bco, int pc ) break; } + BELCH_INSTR_NAME_ALL_SIZES(OP_ADD); + BELCH_INSTR_NAME_ALL_SIZES(OP_SUB); + BELCH_INSTR_NAME_ALL_SIZES(OP_AND); + BELCH_INSTR_NAME_ALL_SIZES(OP_XOR); + BELCH_INSTR_NAME_ALL_SIZES(OP_OR); + BELCH_INSTR_NAME_ALL_SIZES(OP_NOT); + BELCH_INSTR_NAME_ALL_SIZES(OP_NEG); + BELCH_INSTR_NAME_ALL_SIZES(OP_MUL); + BELCH_INSTR_NAME_ALL_SIZES(OP_SHL); + BELCH_INSTR_NAME_ALL_SIZES(OP_ASR); + BELCH_INSTR_NAME_ALL_SIZES(OP_LSR); + + BELCH_INSTR_NAME_ALL_SIZES(OP_NEQ); + BELCH_INSTR_NAME_ALL_SIZES(OP_EQ); + + BELCH_INSTR_NAME_ALL_SIZES(OP_U_GT); + BELCH_INSTR_NAME_ALL_SIZES(OP_U_LE); + BELCH_INSTR_NAME_ALL_SIZES(OP_U_GE); + BELCH_INSTR_NAME_ALL_SIZES(OP_U_LT); + + BELCH_INSTR_NAME_ALL_SIZES(OP_S_GT); + BELCH_INSTR_NAME_ALL_SIZES(OP_S_LE); + BELCH_INSTR_NAME_ALL_SIZES(OP_S_GE); + BELCH_INSTR_NAME_ALL_SIZES(OP_S_LT); + + BELCH_INSTR_NAME_ALL_SIZES(OP_INDEX_ADDR); + default: barf("disInstr: unknown opcode %u", (unsigned int) instr); } ===================================== rts/Interpreter.c ===================================== @@ -178,23 +178,35 @@ See also Note [Width of parameters] for some more motivation. #define Sp_plusB(n) ((void *)((StgWord8*)Sp + (ptrdiff_t)(n))) #define Sp_minusB(n) ((void *)((StgWord8*)Sp - (ptrdiff_t)(n))) -#define Sp_plusW(n) (Sp_plusB((ptrdiff_t)(n) * (ptrdiff_t)sizeof(W_))) -#define Sp_minusW(n) (Sp_minusB((ptrdiff_t)(n) * (ptrdiff_t)sizeof(W_))) +#define Sp_plusW(n) ((void*)Sp_plusB((ptrdiff_t)(n) * (ptrdiff_t)sizeof(W_))) +#define Sp_plusW64(n) ((void*)Sp_plusB((ptrdiff_t)(n) * (ptrdiff_t)sizeof(StgWord64))) +#define Sp_minusW(n) ((void*)Sp_minusB((ptrdiff_t)(n) * (ptrdiff_t)sizeof(W_))) #define Sp_addB(n) (Sp = Sp_plusB(n)) #define Sp_subB(n) (Sp = Sp_minusB(n)) #define Sp_addW(n) (Sp = Sp_plusW(n)) +#define Sp_addW64(n) (Sp = Sp_plusW64(n)) #define Sp_subW(n) (Sp = Sp_minusW(n)) -#define SpW(n) (*(StgWord*)(Sp_plusW(n))) -#define SpB(n) (*(StgWord*)(Sp_plusB(n))) +// Assumes stack location is within stack chunk bounds +#define SpW(n) (*(StgWord*)(Sp_plusW(n))) +#define SpW64(n) (*(StgWord*)(Sp_plusW64(n))) -#define WITHIN_CAP_CHUNK_BOUNDS(n) WITHIN_CHUNK_BOUNDS(n, cap->r.rCurrentTSO->stackobj) +#define WITHIN_CAP_CHUNK_BOUNDS_W(n) WITHIN_CHUNK_BOUNDS_W(n, cap->r.rCurrentTSO->stackobj) -#define WITHIN_CHUNK_BOUNDS(n, s) \ - (RTS_LIKELY((StgWord*)(Sp_plusW(n)) < ((s)->stack + (s)->stack_size - sizeofW(StgUnderflowFrame)))) +#define WITHIN_CHUNK_BOUNDS_W(n, s) \ + (RTS_LIKELY(((StgWord*) Sp_plusW(n)) < ((s)->stack + (s)->stack_size - sizeofW(StgUnderflowFrame)))) +#define W64_TO_WDS(n) ((n * sizeof(StgWord64) / sizeof(StgWord))) + +// Always safe to use - Return the value at the address +#define ReadSpW(n) (*((StgWord*) SafeSpWP(n))) +//Argument is offset in multiples of word64 +#define ReadSpW64(n) (*((StgWord64*) SafeSpWP(W64_TO_WDS(n)))) +// Perhaps confusingly this still reads a full word, merely the offset is in bytes. +#define ReadSpB(n) (*((StgWord*) SafeSpBP(n))) + /* Note [PUSH_L underflow] ~~~~~~~~~~~~~~~~~~~~~~~ BCOs can be nested, resulting in nested BCO stack frames where the inner most @@ -215,9 +227,9 @@ variables. If a stack overflow happens between the creation of the stack frame for BCO_1 and BCO_N the RTS might move BCO_N to a new stack chunk while leaving BCO_1 in place, invalidating a simple offset based reference to the outer stack frames. -Therefore `ReadSpW` first performs a bounds check to ensure that accesses onto +Therefore `SafeSpW` first performs a bounds check to ensure that accesses onto the stack will succeed. If the target address would not be a valid location for -the current stack chunk then `slow_spw` function is called, which dereferences +the current stack chunk then `slow_sp` function is called, which dereferences the underflow frame to adjust the offset before performing the lookup. ┌->--x | CHK_1 | @@ -229,14 +241,43 @@ the underflow frame to adjust the offset before performing the lookup. |---------| | PUSH_L <n> | BCO_ N | ->-┘ |---------| + +To keep things simpler all accesses to the stack which might go beyond the stack +chunk go through one of the ReadSP* or SafeSP* macros. +When writing to the stack there is no need for checks, we ensured we have space +in the current chunk ahead of time. So there we use SpW and it's variants which +omit the stack bounds check. + See ticket #25750 */ -#define ReadSpW(n) \ - ((WITHIN_CAP_CHUNK_BOUNDS(n)) ? SpW(n): slow_spw(Sp, cap->r.rCurrentTSO->stackobj, n)) +// Returns a pointer to the stack location. +#define SafeSpWP(n) \ + ( ((WITHIN_CAP_CHUNK_BOUNDS_W(n)) ? Sp_plusW(n) : slow_spw(Sp, cap->r.rCurrentTSO->stackobj, n))) +#define SafeSpBP(off_w) \ + ( (WITHIN_CAP_CHUNK_BOUNDS_W((1+(off_w))/sizeof(StgWord))) ? \ + Sp_plusB(off_w) : \ + (void*)((ptrdiff_t)((ptrdiff_t)(off_w) % (ptrdiff_t)sizeof(StgWord)) + (StgWord8*)slow_spw(Sp, cap->r.rCurrentTSO->stackobj, (off_w)/sizeof(StgWord))) \ + ) + +/* Note [Interpreter subword primops] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In general the interpreter stack is host-platform word aligned. +We keep with this convention when evaluating primops for simplicity. + +This means: + +* All arguments are pushed extended to word size. +* Results are written to the stack extended to word size. + +The only exception are constructor allocations where we push unaligned subwords +on the stack which are cleaned up by the PACK instruction afterwards. + +*/ + STATIC_INLINE StgPtr allocate_NONUPD (Capability *cap, int n_words) { @@ -392,11 +433,12 @@ StgClosure * copyPAP (Capability *cap, StgPAP *oldpap) // See Note [PUSH_L underflow] for in which situations this // slow lookup is needed -static StgWord -slow_spw(void *Sp, StgStack *cur_stack, StgWord offset){ - // 1. If in range, access the item from the current stack chunk - if (WITHIN_CHUNK_BOUNDS(offset, cur_stack)) { - return SpW(offset); +// Returns a pointer to the stack location. +static void* +slow_spw(void *Sp, StgStack *cur_stack, StgWord offset_words){ + // 1. If in range, simply return ptr+offset_words pointing into the current stack chunk + if (WITHIN_CHUNK_BOUNDS_W(offset_words, cur_stack)) { + return Sp_plusW(offset_words); } // 2. Not in this stack chunk, so access the underflow frame. else { @@ -420,21 +462,19 @@ slow_spw(void *Sp, StgStack *cur_stack, StgWord offset){ // How many words were on the stack stackWords = (StgWord *)frame - (StgWord *) Sp; - ASSERT(offset > stackWords); + ASSERT(offset_words > stackWords); // Recursive, in the very unlikely case we have to traverse two // stack chunks. - return slow_spw(new_stack->sp, new_stack, offset-stackWords); + return slow_spw(new_stack->sp, new_stack, offset_words-stackWords); } // 2b. Access the element if there is no underflow frame, it must be right // at the top of the stack. else { // Not actually in the underflow case - return SpW(offset); + return Sp_plusW(offset_words); } - } - } // Compute the pointer tag for the constructor and tag the pointer; @@ -883,7 +923,7 @@ do_return_nonpointer: // get the offset of the header of the next stack frame offset = stack_frame_sizeW((StgClosure *)Sp); - switch (get_itbl((StgClosure*)(Sp_plusW(offset)))->type) { + switch (get_itbl((StgClosure*)(SafeSpWP(offset)))->type) { case RET_BCO: // Returning to an interpreted continuation: pop the return frame @@ -1236,9 +1276,9 @@ run_BCO: #endif bci = BCO_NEXT; - /* We use the high 8 bits for flags, only the highest of which is - * currently allocated */ - ASSERT((bci & 0xFF00) == (bci & 0x8000)); + /* We use the high 8 bits for flags. The highest of which is + * currently allocated to LARGE_ARGS */ + ASSERT((bci & 0xFF00) == (bci & ( bci_FLAG_LARGE_ARGS ))); switch (bci & 0xFF) { @@ -1429,41 +1469,41 @@ run_BCO: case bci_PUSH8: { W_ off = BCO_GET_LARGE_ARG; Sp_subB(1); - *(StgWord8*)Sp = (StgWord8) *(StgWord*)(Sp_plusB(off+1)); + *(StgWord8*)Sp = (StgWord8) (ReadSpB(off+1)); goto nextInsn; } case bci_PUSH16: { W_ off = BCO_GET_LARGE_ARG; Sp_subB(2); - *(StgWord16*)Sp = (StgWord16) *(StgWord*)(Sp_plusB(off+2)); + *(StgWord16*)Sp = (StgWord16) (ReadSpB(off+2)); goto nextInsn; } case bci_PUSH32: { W_ off = BCO_GET_LARGE_ARG; Sp_subB(4); - *(StgWord32*)Sp = (StgWord32) *(StgWord*)(Sp_plusB(off+4)); + *(StgWord32*)Sp = (StgWord32) (ReadSpB(off+4)); goto nextInsn; } case bci_PUSH8_W: { W_ off = BCO_GET_LARGE_ARG; - *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord8) *(StgWord*)(Sp_plusB(off))); + *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord8) (ReadSpB(off))); Sp_subW(1); goto nextInsn; } case bci_PUSH16_W: { W_ off = BCO_GET_LARGE_ARG; - *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord16) *(StgWord*)(Sp_plusB(off))); + *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord16) (ReadSpB(off))); Sp_subW(1); goto nextInsn; } case bci_PUSH32_W: { W_ off = BCO_GET_LARGE_ARG; - *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord32) *(StgWord*)(Sp_plusB(off))); + *(StgWord*)(Sp_minusW(1)) = (StgWord) ((StgWord32) (ReadSpB(off))); Sp_subW(1); goto nextInsn; } @@ -1953,7 +1993,7 @@ run_BCO: case bci_TESTLT_I64: { int discr = BCO_GET_LARGE_ARG; int failto = BCO_GET_LARGE_ARG; - StgInt64 stackInt = (*(StgInt64*)Sp); + StgInt64 stackInt = ReadSpW64(0); if (stackInt >= BCO_LITI64(discr)) bciPtr = failto; goto nextInsn; @@ -1999,7 +2039,7 @@ run_BCO: case bci_TESTEQ_I64: { int discr = BCO_GET_LARGE_ARG; int failto = BCO_GET_LARGE_ARG; - StgInt64 stackInt = (*(StgInt64*)Sp); + StgInt64 stackInt = ReadSpW64(0); if (stackInt != BCO_LITI64(discr)) { bciPtr = failto; } @@ -2048,7 +2088,7 @@ run_BCO: case bci_TESTLT_W64: { int discr = BCO_GET_LARGE_ARG; int failto = BCO_GET_LARGE_ARG; - StgWord64 stackWord = (*(StgWord64*)Sp); + StgWord64 stackWord = ReadSpW64(0); if (stackWord >= BCO_LITW64(discr)) bciPtr = failto; goto nextInsn; @@ -2094,7 +2134,7 @@ run_BCO: case bci_TESTEQ_W64: { int discr = BCO_GET_LARGE_ARG; int failto = BCO_GET_LARGE_ARG; - StgWord64 stackWord = (*(StgWord64*)Sp); + StgWord64 stackWord = ReadSpW64(0); if (stackWord != BCO_LITW64(discr)) { bciPtr = failto; } @@ -2231,7 +2271,7 @@ run_BCO: case bci_SWIZZLE: { W_ stkoff = BCO_GET_LARGE_ARG; StgInt n = BCO_GET_LARGE_ARG; - (*(StgInt*)(Sp_plusW(stkoff))) += n; + (*(StgInt*)(SafeSpWP(stkoff))) += n; goto nextInsn; } @@ -2241,6 +2281,203 @@ run_BCO: RETURN_TO_SCHEDULER_NO_PAUSE(ThreadRunGHC, ThreadYielding); } +// op :: ty -> ty +#define UN_SIZED_OP(op,ty) \ + { \ + if(sizeof(ty) == 8) { \ + ty r = op ((ty) ReadSpW64(0)); \ + SpW64(0) = (StgWord64) r; \ + } else { \ + ty r = op ((ty) ReadSpW(0)); \ + SpW(0) = (StgWord) r; \ + } \ + goto nextInsn; \ + } + +// op :: ty -> ty -> ty +#define SIZED_BIN_OP(op,ty) \ + { \ + if(sizeof(ty) == 8) { \ + ty r = ((ty) ReadSpW64(0)) op ((ty) ReadSpW64(1)); \ + Sp_addW64(1); \ + SpW64(0) = (StgWord64) r; \ + } else { \ + ty r = ((ty) ReadSpW(0)) op ((ty) ReadSpW(1)); \ + Sp_addW(1); \ + SpW(0) = (StgWord) r; \ + }; \ + goto nextInsn; \ + } + +// op :: ty -> Int -> ty +#define SIZED_BIN_OP_TY_INT(op,ty) \ +{ \ + if(sizeof(ty) > sizeof(StgWord)) { \ + ty r = ((ty) ReadSpW64(0)) op ((ty) ReadSpW(2)); \ + Sp_addW(1); \ + SpW64(0) = (StgWord64) r; \ + } else { \ + ty r = ((ty) ReadSpW(0)) op ((ty) ReadSpW(1)); \ + Sp_addW(1); \ + SpW(0) = (StgWord) r; \ + }; \ + goto nextInsn; \ +} + +// op :: ty -> ty -> Int +#define SIZED_BIN_OP_TY_TY_INT(op,ty) \ +{ \ + if(sizeof(ty) > sizeof(StgWord)) { \ + ty r = ((ty) ReadSpW64(0)) op ((ty) ReadSpW64(1)); \ + Sp_addW(3); \ + SpW(0) = (StgWord) r; \ + } else { \ + ty r = ((ty) ReadSpW(0)) op ((ty) ReadSpW(1)); \ + Sp_addW(1); \ + SpW(0) = (StgWord) r; \ + }; \ + goto nextInsn; \ +} + + case bci_OP_ADD_64: SIZED_BIN_OP(+, StgInt64) + case bci_OP_SUB_64: SIZED_BIN_OP(-, StgInt64) + case bci_OP_AND_64: SIZED_BIN_OP(&, StgInt64) + case bci_OP_XOR_64: SIZED_BIN_OP(^, StgInt64) + case bci_OP_OR_64: SIZED_BIN_OP(|, StgInt64) + case bci_OP_MUL_64: SIZED_BIN_OP(*, StgInt64) + case bci_OP_SHL_64: SIZED_BIN_OP_TY_INT(<<, StgWord64) + case bci_OP_LSR_64: SIZED_BIN_OP_TY_INT(>>, StgWord64) + case bci_OP_ASR_64: SIZED_BIN_OP_TY_INT(>>, StgInt64) + + case bci_OP_NEQ_64: SIZED_BIN_OP_TY_TY_INT(!=, StgWord64) + case bci_OP_EQ_64: SIZED_BIN_OP_TY_TY_INT(==, StgWord64) + case bci_OP_U_GT_64: SIZED_BIN_OP_TY_TY_INT(>, StgWord64) + case bci_OP_U_GE_64: SIZED_BIN_OP_TY_TY_INT(>=, StgWord64) + case bci_OP_U_LT_64: SIZED_BIN_OP_TY_TY_INT(<, StgWord64) + case bci_OP_U_LE_64: SIZED_BIN_OP_TY_TY_INT(<=, StgWord64) + + case bci_OP_S_GT_64: SIZED_BIN_OP_TY_TY_INT(>, StgInt64) + case bci_OP_S_GE_64: SIZED_BIN_OP_TY_TY_INT(>=, StgInt64) + case bci_OP_S_LT_64: SIZED_BIN_OP_TY_TY_INT(<, StgInt64) + case bci_OP_S_LE_64: SIZED_BIN_OP_TY_TY_INT(<=, StgInt64) + + case bci_OP_NOT_64: UN_SIZED_OP(~, StgWord64) + case bci_OP_NEG_64: UN_SIZED_OP(-, StgInt64) + + + case bci_OP_ADD_32: SIZED_BIN_OP(+, StgInt32) + case bci_OP_SUB_32: SIZED_BIN_OP(-, StgInt32) + case bci_OP_AND_32: SIZED_BIN_OP(&, StgInt32) + case bci_OP_XOR_32: SIZED_BIN_OP(^, StgInt32) + case bci_OP_OR_32: SIZED_BIN_OP(|, StgInt32) + case bci_OP_MUL_32: SIZED_BIN_OP(*, StgInt32) + case bci_OP_SHL_32: SIZED_BIN_OP_TY_INT(<<, StgWord32) + case bci_OP_LSR_32: SIZED_BIN_OP_TY_INT(>>, StgWord32) + case bci_OP_ASR_32: SIZED_BIN_OP_TY_INT(>>, StgInt32) + + case bci_OP_NEQ_32: SIZED_BIN_OP_TY_TY_INT(!=, StgWord32) + case bci_OP_EQ_32: SIZED_BIN_OP_TY_TY_INT(==, StgWord32) + case bci_OP_U_GT_32: SIZED_BIN_OP_TY_TY_INT(>, StgWord32) + case bci_OP_U_GE_32: SIZED_BIN_OP_TY_TY_INT(>=, StgWord32) + case bci_OP_U_LT_32: SIZED_BIN_OP_TY_TY_INT(<, StgWord32) + case bci_OP_U_LE_32: SIZED_BIN_OP_TY_TY_INT(<=, StgWord32) + + case bci_OP_S_GT_32: SIZED_BIN_OP_TY_TY_INT(>, StgInt32) + case bci_OP_S_GE_32: SIZED_BIN_OP_TY_TY_INT(>=, StgInt32) + case bci_OP_S_LT_32: SIZED_BIN_OP_TY_TY_INT(<, StgInt32) + case bci_OP_S_LE_32: SIZED_BIN_OP_TY_TY_INT(<=, StgInt32) + + case bci_OP_NOT_32: UN_SIZED_OP(~, StgWord32) + case bci_OP_NEG_32: UN_SIZED_OP(-, StgInt32) + + + case bci_OP_ADD_16: SIZED_BIN_OP(+, StgInt16) + case bci_OP_SUB_16: SIZED_BIN_OP(-, StgInt16) + case bci_OP_AND_16: SIZED_BIN_OP(&, StgInt16) + case bci_OP_XOR_16: SIZED_BIN_OP(^, StgInt16) + case bci_OP_OR_16: SIZED_BIN_OP(|, StgInt16) + case bci_OP_MUL_16: SIZED_BIN_OP(*, StgInt16) + case bci_OP_SHL_16: SIZED_BIN_OP_TY_INT(<<, StgWord16) + case bci_OP_LSR_16: SIZED_BIN_OP_TY_INT(>>, StgWord16) + case bci_OP_ASR_16: SIZED_BIN_OP_TY_INT(>>, StgInt16) + + case bci_OP_NEQ_16: SIZED_BIN_OP_TY_TY_INT(!=, StgWord16) + case bci_OP_EQ_16: SIZED_BIN_OP_TY_TY_INT(==, StgWord16) + case bci_OP_U_GT_16: SIZED_BIN_OP_TY_TY_INT(>, StgWord16) + case bci_OP_U_GE_16: SIZED_BIN_OP_TY_TY_INT(>=, StgWord16) + case bci_OP_U_LT_16: SIZED_BIN_OP_TY_TY_INT(<, StgWord16) + case bci_OP_U_LE_16: SIZED_BIN_OP_TY_TY_INT(<=, StgWord16) + + case bci_OP_S_GT_16: SIZED_BIN_OP(>, StgInt16) + case bci_OP_S_GE_16: SIZED_BIN_OP(>=, StgInt16) + case bci_OP_S_LT_16: SIZED_BIN_OP(<, StgInt16) + case bci_OP_S_LE_16: SIZED_BIN_OP(<=, StgInt16) + + case bci_OP_NOT_16: UN_SIZED_OP(~, StgWord16) + case bci_OP_NEG_16: UN_SIZED_OP(-, StgInt16) + + + case bci_OP_ADD_08: SIZED_BIN_OP(+, StgInt8) + case bci_OP_SUB_08: SIZED_BIN_OP(-, StgInt8) + case bci_OP_AND_08: SIZED_BIN_OP(&, StgInt8) + case bci_OP_XOR_08: SIZED_BIN_OP(^, StgInt8) + case bci_OP_OR_08: SIZED_BIN_OP(|, StgInt8) + case bci_OP_MUL_08: SIZED_BIN_OP(*, StgInt8) + case bci_OP_SHL_08: SIZED_BIN_OP_TY_INT(<<, StgWord8) + case bci_OP_LSR_08: SIZED_BIN_OP_TY_INT(>>, StgWord8) + case bci_OP_ASR_08: SIZED_BIN_OP_TY_INT(>>, StgInt8) + + case bci_OP_NEQ_08: SIZED_BIN_OP_TY_TY_INT(!=, StgWord8) + case bci_OP_EQ_08: SIZED_BIN_OP_TY_TY_INT(==, StgWord8) + case bci_OP_U_GT_08: SIZED_BIN_OP_TY_TY_INT(>, StgWord8) + case bci_OP_U_GE_08: SIZED_BIN_OP_TY_TY_INT(>=, StgWord8) + case bci_OP_U_LT_08: SIZED_BIN_OP_TY_TY_INT(<, StgWord8) + case bci_OP_U_LE_08: SIZED_BIN_OP_TY_TY_INT(<=, StgWord8) + + case bci_OP_S_GT_08: SIZED_BIN_OP_TY_TY_INT(>, StgInt8) + case bci_OP_S_GE_08: SIZED_BIN_OP_TY_TY_INT(>=, StgInt8) + case bci_OP_S_LT_08: SIZED_BIN_OP_TY_TY_INT(<, StgInt8) + case bci_OP_S_LE_08: SIZED_BIN_OP_TY_TY_INT(<=, StgInt8) + + case bci_OP_NOT_08: UN_SIZED_OP(~, StgWord8) + case bci_OP_NEG_08: UN_SIZED_OP(-, StgInt8) + + case bci_OP_INDEX_ADDR_64: + { + StgWord64* addr = (StgWord64*) SpW(0); + StgInt offset = (StgInt) SpW(1); + if(sizeof(StgPtr) == sizeof(StgWord64)) { + Sp_addW(1); + } + SpW64(0) = *(addr+offset); + goto nextInsn; + } + + case bci_OP_INDEX_ADDR_32: + { + StgWord32* addr = (StgWord32*) SpW(0); + StgInt offset = (StgInt) SpW(1); + Sp_addW(1); + SpW(0) = (StgWord) *(addr+offset); + goto nextInsn; + } + case bci_OP_INDEX_ADDR_16: + { + StgWord16* addr = (StgWord16*) SpW(0); + StgInt offset = (StgInt) SpW(1); + Sp_addW(1); + SpW(0) = (StgWord) *(addr+offset); + goto nextInsn; + } + case bci_OP_INDEX_ADDR_08: + { + StgWord8* addr = (StgWord8*) SpW(0); + StgInt offset = (StgInt) SpW(1); + Sp_addW(1); + SpW(0) = (StgWord) *(addr+offset); + goto nextInsn; + } + case bci_CCALL: { void *tok; W_ stk_offset = BCO_GET_LARGE_ARG; ===================================== rts/include/rts/Bytecodes.h ===================================== @@ -114,6 +114,107 @@ #define bci_BCO_NAME 88 +#define bci_OP_ADD_64 90 +#define bci_OP_SUB_64 91 +#define bci_OP_AND_64 92 +#define bci_OP_XOR_64 93 +#define bci_OP_NOT_64 94 +#define bci_OP_NEG_64 95 +#define bci_OP_MUL_64 96 +#define bci_OP_SHL_64 97 +#define bci_OP_ASR_64 98 +#define bci_OP_LSR_64 99 +#define bci_OP_OR_64 100 + +#define bci_OP_NEQ_64 110 +#define bci_OP_EQ_64 111 +#define bci_OP_U_GE_64 112 +#define bci_OP_U_GT_64 113 +#define bci_OP_U_LT_64 114 +#define bci_OP_U_LE_64 115 +#define bci_OP_S_GE_64 116 +#define bci_OP_S_GT_64 117 +#define bci_OP_S_LT_64 118 +#define bci_OP_S_LE_64 119 + + +#define bci_OP_ADD_32 130 +#define bci_OP_SUB_32 131 +#define bci_OP_AND_32 132 +#define bci_OP_XOR_32 133 +#define bci_OP_NOT_32 134 +#define bci_OP_NEG_32 135 +#define bci_OP_MUL_32 136 +#define bci_OP_SHL_32 137 +#define bci_OP_ASR_32 138 +#define bci_OP_LSR_32 139 +#define bci_OP_OR_32 140 + +#define bci_OP_NEQ_32 150 +#define bci_OP_EQ_32 151 +#define bci_OP_U_GE_32 152 +#define bci_OP_U_GT_32 153 +#define bci_OP_U_LT_32 154 +#define bci_OP_U_LE_32 155 +#define bci_OP_S_GE_32 156 +#define bci_OP_S_GT_32 157 +#define bci_OP_S_LT_32 158 +#define bci_OP_S_LE_32 159 + + +#define bci_OP_ADD_16 170 +#define bci_OP_SUB_16 171 +#define bci_OP_AND_16 172 +#define bci_OP_XOR_16 173 +#define bci_OP_NOT_16 174 +#define bci_OP_NEG_16 175 +#define bci_OP_MUL_16 176 +#define bci_OP_SHL_16 177 +#define bci_OP_ASR_16 178 +#define bci_OP_LSR_16 179 +#define bci_OP_OR_16 180 + +#define bci_OP_NEQ_16 190 +#define bci_OP_EQ_16 191 +#define bci_OP_U_GE_16 192 +#define bci_OP_U_GT_16 193 +#define bci_OP_U_LT_16 194 +#define bci_OP_U_LE_16 195 +#define bci_OP_S_GE_16 196 +#define bci_OP_S_GT_16 197 +#define bci_OP_S_LT_16 198 +#define bci_OP_S_LE_16 199 + + +#define bci_OP_ADD_08 200 +#define bci_OP_SUB_08 201 +#define bci_OP_AND_08 202 +#define bci_OP_XOR_08 203 +#define bci_OP_NOT_08 204 +#define bci_OP_NEG_08 205 +#define bci_OP_MUL_08 206 +#define bci_OP_SHL_08 207 +#define bci_OP_ASR_08 208 +#define bci_OP_LSR_08 209 +#define bci_OP_OR_08 210 + +#define bci_OP_NEQ_08 220 +#define bci_OP_EQ_08 221 +#define bci_OP_U_GE_08 222 +#define bci_OP_U_GT_08 223 +#define bci_OP_U_LT_08 224 +#define bci_OP_U_LE_08 225 +#define bci_OP_S_GE_08 226 +#define bci_OP_S_GT_08 227 +#define bci_OP_S_LT_08 228 +#define bci_OP_S_LE_08 229 + +#define bci_OP_INDEX_ADDR_08 240 +#define bci_OP_INDEX_ADDR_16 241 +#define bci_OP_INDEX_ADDR_32 242 +#define bci_OP_INDEX_ADDR_64 243 + + /* If you need to go past 255 then you will run into the flags */ /* If you need to go below 0x0100 then you will run into the instructions */ ===================================== testsuite/tests/codeGen/should_run/all.T ===================================== @@ -226,7 +226,7 @@ test('T20640b', normal, compile_and_run, ['']) test('T22296',[only_ways(llvm_ways) ,unless(arch('x86_64') or arch('aarch64'), skip)],compile_and_run,['']) test('T22798', normal, compile_and_run, ['-fregs-graph']) -test('CheckBoundsOK', normal, compile_and_run, ['-fcheck-prim-bounds']) +test('CheckBoundsOK', normal, compile_and_run, ['-fcheck-prim-bounds -funoptimized-core-for-interpreter -O']) test('OrigThunkInfo', normal, compile_and_run, ['-forig-thunk-info']) test('T24809', req_profiling, compile_and_run, ['-forig-thunk-info -prof']) ===================================== testsuite/tests/ghci/all.T ===================================== @@ -0,0 +1,2 @@ +test('ghci-mem-primops', [ extra_ways(['ghci-opt']), only_ways(['ghci', 'ghci-opt']), + extra_hc_opts('-fno-unoptimized-core-for-interpreter -O')], ghci_script, ['ghci-mem-primops.script']) ===================================== testsuite/tests/ghci/ghci-mem-primops.hs ===================================== @@ -0,0 +1,30 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE ExtendedLiterals #-} + +module Main where + +-- Test memory primops interpreted in interpreter, extend if you add more. +import GHC.Word +import GHC.PrimOps +import GHC.IO +import Numeric (showHex) + +data Bytes = Bytes { byte_addr :: Addr# } + +bytes :: Bytes +bytes = Bytes "\0\1\2\3\4\5\6\7\8\0"# + +main = do + let val = 0x1122334455667788#Word64 + IO (\s -> case writeWord64OffAddr# (byte_addr bytes) 0# val s of s2 -> (# s2,() #)) + putStrLn . flip showHex "" $ W64# (indexWord64OffAddr# (byte_addr bytes) 0#) + + IO (\s -> case writeWord32OffAddr# (byte_addr bytes) 0# 0x11223344#Word32 s of s2 -> (# s2,() #)) + putStrLn . flip showHex "" $ W32# (indexWord32OffAddr# (byte_addr bytes) 0#) + + IO (\s -> case writeWord16OffAddr# (byte_addr bytes) 0# 0x1122#Word16 s of s2 -> (# s2,() #)) + putStrLn . flip showHex "" $ W16# (indexWord16OffAddr# (byte_addr bytes) 0#) + + IO (\s -> case writeWord8OffAddr# (byte_addr bytes) 0# 0x11#Word8 s of s2 -> (# s2,() #)) + putStrLn . flip showHex "" $ W8# (indexWord8OffAddr# (byte_addr bytes) 0#) \ No newline at end of file ===================================== testsuite/tests/ghci/ghci-mem-primops.script ===================================== @@ -0,0 +1,2 @@ +:l ghci-mem-primops +:main \ No newline at end of file ===================================== testsuite/tests/ghci/ghci-mem-primops.stdout ===================================== @@ -0,0 +1,4 @@ +1122334455667788 +11223344 +1122 +11 ===================================== testsuite/tests/numeric/should_run/all.T ===================================== @@ -82,7 +82,7 @@ test('IntegerToFloat', normal, compile_and_run, ['']) test('T20291', normal, compile_and_run, ['']) test('T22282', normal, compile_and_run, ['']) test('T22671', js_fragile(24259), compile_and_run, ['']) -test('foundation', [when(js_arch(), run_timeout_multiplier(2)), js_fragile(24259)], compile_and_run, ['-O -package transformers']) +test('foundation', [when(js_arch(), run_timeout_multiplier(2)), js_fragile(24259), extra_ways(['optasm','ghci','ghci-opt'])], compile_and_run, ['-package transformers -fno-break-points']) test('T24066', normal, compile_and_run, ['']) test('div01', normal, compile_and_run, ['']) test('T24245', normal, compile_and_run, ['']) ===================================== testsuite/tests/numeric/should_run/foundation.hs ===================================== @@ -1,3 +1,15 @@ +{- PARTS OF THIS FILE ARE SEMI-AUTOGENERATED. + You can re-generate them by invoking the genprimops utility with --foundation-tests + and then integrating the output in this file. + + This test compares the results of various primops between the + pre-compiled version (primop wrapper) and the implementation of + whatever the test is run with. + + This is particularly helpful when testing the interpreter as it allows us to + compare the result of the primop wrappers with the results of interpretation. +-} + {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -5,6 +17,9 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE UnboxedTuples #-} module Main ( main ) where @@ -16,6 +31,7 @@ import Data.Typeable import Data.Proxy import GHC.Int import GHC.Word +import GHC.Word import Data.Function import GHC.Prim import Control.Monad.Reader @@ -26,6 +42,13 @@ import Foreign.Ptr import Data.List (intercalate) import Data.IORef import Unsafe.Coerce +import GHC.Types +import Data.Char +import Data.Semigroup +import System.Exit + +import qualified GHC.Internal.PrimopWrappers as Wrapper +import qualified GHC.Internal.Prim as Primop newtype Gen a = Gen { runGen :: (ReaderT LCGGen IO a) } deriving newtype (Functor, Applicative, Monad) @@ -98,6 +121,17 @@ arbitraryWord64 = Gen $ do h <- ask liftIO (randomWord64 h) +nonZero :: (Arbitrary a, Num a, Eq a) => Gen (NonZero a) +nonZero = do + x <- arbitrary + if x == 0 then nonZero else pure $ NonZero x + +newtype NonZero a = NonZero { getNonZero :: a } + deriving (Eq,Ord,Bounded,Show) + +instance (Arbitrary a, Num a, Eq a) => Arbitrary (NonZero a) where + arbitrary = nonZero + instance Arbitrary Natural where arbitrary = integralDownsize . (`mod` 10000) . abs <$> arbitraryInt64 @@ -126,6 +160,13 @@ instance Arbitrary Int16 where instance Arbitrary Int8 where arbitrary = integralDownsize <$> arbitraryInt64 +instance Arbitrary Char where + arbitrary = do + let high = fromIntegral $ fromEnum (maxBound :: Char) :: Word + (x::Word) <- arbitrary + let x' = mod x high + return (chr $ fromIntegral x') + int64ToInt :: Int64 -> Int int64ToInt (I64# i) = I# (int64ToInt# i) @@ -134,7 +175,7 @@ word64ToWord :: Word64 -> Word word64ToWord (W64# i) = W# (word64ToWord# i) -data RunS = RunS { depth :: Int, rg :: LCGGen } +data RunS = RunS { depth :: Int, rg :: LCGGen, context :: [String] } newtype LCGGen = LCGGen { randomWord64 :: IO Word64 } @@ -148,43 +189,75 @@ newLCGGen LCGParams{..} = do runPropertyCheck (PropertyBinaryOp res desc s1 s2) = - if res then return True else (putMsg ("Failure: " ++ s1 ++ desc ++ s2) >> return False) -runPropertyCheck (PropertyAnd a1 a2) = (&&) <$> runPropertyCheck a1 <*> runPropertyCheck a2 - -runProperty :: Property -> ReaderT RunS IO () + if res then return Success + else do + ctx <- context <$> ask + let msg = "Failure: " ++ s1 ++ desc ++ s2 + putMsg msg + return (Failure [msg : ctx]) +runPropertyCheck (PropertyAnd a1 a2) = (<>) <$> runPropertyCheck a1 <*> runPropertyCheck a2 + +runProperty :: Property -> ReaderT RunS IO Result runProperty (Prop p) = do let iterations = 100 loop iterations iterations where - loop iterations 0 = putMsg ("Passed " ++ show iterations ++ " iterations") + loop iterations 0 = do + putMsg ("Passed " ++ show iterations ++ " iterations") + return Success loop iterations n = do h <- rg <$> ask p <- liftIO (runReaderT (runGen p) h) let (ss, pc) = getCheck p res <- runPropertyCheck pc - if res then loop iterations (n-1) - else putMsg ("With arguments " ++ intercalate ", " ss) + case res of + Success -> loop iterations (n-1) + Failure msgs -> do + let msg = ("With arguments " ++ intercalate ", " ss) + putMsg msg + return (Failure (map (msg :) msgs)) + +data Result = Success | Failure [[String]] + +instance Semigroup Result where + Success <> x = x + x <> Success = x + (Failure xs) <> (Failure ys) = Failure (xs ++ ys) + +instance Monoid Result where + mempty = Success putMsg s = do n <- depth <$> ask liftIO . putStrLn $ replicate (n * 2) ' ' ++ s -nest = local (\s -> s { depth = depth s + 1 }) -runTestInternal :: Test -> ReaderT RunS IO () +nest c = local (\s -> s { depth = depth s + 1, context = c : context s }) + +runTestInternal :: Test -> ReaderT RunS IO Result runTestInternal (Group name tests) = do - putMsg ("Group " ++ name) - nest (mapM_ runTestInternal tests) + let label = ("Group " ++ name) + putMsg label + nest label (mconcat <$> mapM runTestInternal tests) runTestInternal (Property name p) = do - putMsg ("Running " ++ name) - nest $ runProperty (property p) + let label = ("Running " ++ name) + putMsg label + nest label $ runProperty (property p) runTests :: Test -> IO () runTests t = do -- These params are the same ones as glibc uses. h <- newLCGGen (LCGParams { seed = 1238123213, m = 2^31, a = 1103515245, c = 12345 }) - runReaderT (runTestInternal t) (RunS 0 h) + res <- runReaderT (runTestInternal t) (RunS 0 h []) + case res of + Success -> return () + Failure tests -> do + putStrLn $ "These tests failed: \n" ++ intercalate " \n" (map (showStack 0 . reverse) tests) + exitFailure + +showStack _ [] = "" +showStack n (s:ss) = replicate n ' ' ++ s ++ "\n" ++ showStack (n + 2) ss ------------------------------------------------------------------------------- @@ -228,9 +301,8 @@ testMultiplicative _ = Group "Multiplicative" testDividible :: forall a . (Show a, Eq a, Integral a, Num a, Arbitrary a, Typeable a) => Proxy a -> Test testDividible _ = Group "Divisible" - [ Property "(x `div` y) * y + (x `mod` y) == x" $ \(a :: a) b -> - if b == 0 then True === True - else a === (a `div` b) * b + (a `mod` b) + [ Property "(x `div` y) * y + (x `mod` y) == x" $ \(a :: a) (NonZero b) -> + a === (a `div` b) * b + (a `mod` b) ] testOperatorPrecedence :: forall a . (Show a, Eq a, Prelude.Num a, Integral a, Num a, Arbitrary a, Typeable a) @@ -272,6 +344,590 @@ testNumberRefs = Group "ALL" , testNumber "Word32" (Proxy :: Proxy Word32) , testNumber "Word64" (Proxy :: Proxy Word64) ] +{- +test_binop :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep) a r' + (b :: TYPE r1) (r :: TYPE r2) . String -> (a -> b) -> (r -> r') + -> (b -> b -> r) + -> (b -> b -> r) + -> Test +test_binop name unwrap wrap primop wrapper = +-} +-- #define TEST_BINOP(name, unwrap, wrap, primop, wrapper) Property name $ \l r -> wrap (primop (unwrap l) (unwrap r)) === wrap (wrapper (unwrap l) (unwrap r)) + +wInt# :: Int# -> Int +wInt# = I# + +uInt# :: Int -> Int# +uInt# (I# x) = x + +wWord#:: Word# -> Word +wWord#= W# + +uWord# (W# w) = w +uWord8# (W8# w) = w +uWord16# (W16# w) = w +uWord32# (W32# w) = w +uWord64# (W64# w) = w +uChar# (C# c) = c +uInt8# (I8# w) = w +uInt16# (I16# w) = w +uInt32# (I32# w) = w +uInt64# (I64# w) = w + +wWord8# = W8# +wWord16# = W16# +wWord32# = W32# +wWord64# = W64# +wChar# = C# +wInt8# = I8# +wInt16# = I16# +wInt32# = I32# +wInt64# = I64# + +#define WTUP2(f, g, x) (case x of (# a, b #) -> (f a, g b)) +#define WTUP3(f, g, h, x) (case x of (# a, b, c #) -> (f a, g b, h c)) + + +class TestPrimop f where + testPrimop :: String -> f -> f -> Test + + testPrimopDivLike :: String -> f -> f -> Test + testPrimopDivLike _ _ _ = error "Div testing not supported for this type." + +{- +instance TestPrimop (Int# -> Int# -> Int#) where + testPrimop s l r = Property s $ \(uInt -> a1) (uInt -> a2) -> (wInt (l a1 a2)) === wInt (r a1 a2) + +instance TestPrimop (Word# -> Word# -> Int#) where + testPrimop s l r = Property s $ \(uWord -> a1) (uWord -> a2) -> (wInt (l a1 a2)) === wInt (r a1 a2) + +instance TestPrimop (Word# -> Int#) where + testPrimop s l r = Property s $ \(uWord -> a1) -> (wInt (l a1)) === wInt (r a1) + +instance TestPrimop (Word# -> Int# -> Word#) where + testPrimop s l r = Property s $ \(uWord -> a1) (uInt -> a2) -> (wWord (l a1 a2)) === wWord (r a1 a2) + -} + + +twoNonZero :: (a -> a -> b) -> a -> NonZero a -> b +twoNonZero f x (NonZero y) = f x y + +main = runTests (Group "ALL" [testNumberRefs, testPrimops]) + +-- Test an interpreted primop vs a compiled primop +testPrimops = Group "primop" + [ testPrimop "gtChar#" Primop.gtChar# Wrapper.gtChar# + , testPrimop "geChar#" Primop.geChar# Wrapper.geChar# + , testPrimop "eqChar#" Primop.eqChar# Wrapper.eqChar# + , testPrimop "neChar#" Primop.neChar# Wrapper.neChar# + , testPrimop "ltChar#" Primop.ltChar# Wrapper.ltChar# + , testPrimop "leChar#" Primop.leChar# Wrapper.leChar# + , testPrimop "ord#" Primop.ord# Wrapper.ord# + , testPrimop "int8ToInt#" Primop.int8ToInt# Wrapper.int8ToInt# + , testPrimop "intToInt8#" Primop.intToInt8# Wrapper.intToInt8# + , testPrimop "negateInt8#" Primop.negateInt8# Wrapper.negateInt8# + , testPrimop "plusInt8#" Primop.plusInt8# Wrapper.plusInt8# + , testPrimop "subInt8#" Primop.subInt8# Wrapper.subInt8# + , testPrimop "timesInt8#" Primop.timesInt8# Wrapper.timesInt8# + , testPrimopDivLike "quotInt8#" Primop.quotInt8# Wrapper.quotInt8# + , testPrimopDivLike "remInt8#" Primop.remInt8# Wrapper.remInt8# + , testPrimopDivLike "quotRemInt8#" Primop.quotRemInt8# Wrapper.quotRemInt8# + , testPrimop "uncheckedShiftLInt8#" Primop.uncheckedShiftLInt8# Wrapper.uncheckedShiftLInt8# + , testPrimop "uncheckedShiftRAInt8#" Primop.uncheckedShiftRAInt8# Wrapper.uncheckedShiftRAInt8# + , testPrimop "uncheckedShiftRLInt8#" Primop.uncheckedShiftRLInt8# Wrapper.uncheckedShiftRLInt8# + , testPrimop "int8ToWord8#" Primop.int8ToWord8# Wrapper.int8ToWord8# + , testPrimop "eqInt8#" Primop.eqInt8# Wrapper.eqInt8# + , testPrimop "geInt8#" Primop.geInt8# Wrapper.geInt8# + , testPrimop "gtInt8#" Primop.gtInt8# Wrapper.gtInt8# + , testPrimop "leInt8#" Primop.leInt8# Wrapper.leInt8# + , testPrimop "ltInt8#" Primop.ltInt8# Wrapper.ltInt8# + , testPrimop "neInt8#" Primop.neInt8# Wrapper.neInt8# + , testPrimop "word8ToWord#" Primop.word8ToWord# Wrapper.word8ToWord# + , testPrimop "wordToWord8#" Primop.wordToWord8# Wrapper.wordToWord8# + , testPrimop "plusWord8#" Primop.plusWord8# Wrapper.plusWord8# + , testPrimop "subWord8#" Primop.subWord8# Wrapper.subWord8# + , testPrimop "timesWord8#" Primop.timesWord8# Wrapper.timesWord8# + , testPrimopDivLike "quotWord8#" Primop.quotWord8# Wrapper.quotWord8# + , testPrimopDivLike "remWord8#" Primop.remWord8# Wrapper.remWord8# + , testPrimopDivLike "quotRemWord8#" Primop.quotRemWord8# Wrapper.quotRemWord8# + , testPrimop "andWord8#" Primop.andWord8# Wrapper.andWord8# + , testPrimop "orWord8#" Primop.orWord8# Wrapper.orWord8# + , testPrimop "xorWord8#" Primop.xorWord8# Wrapper.xorWord8# + , testPrimop "notWord8#" Primop.notWord8# Wrapper.notWord8# + , testPrimop "uncheckedShiftLWord8#" Primop.uncheckedShiftLWord8# Wrapper.uncheckedShiftLWord8# + , testPrimop "uncheckedShiftRLWord8#" Primop.uncheckedShiftRLWord8# Wrapper.uncheckedShiftRLWord8# + , testPrimop "word8ToInt8#" Primop.word8ToInt8# Wrapper.word8ToInt8# + , testPrimop "eqWord8#" Primop.eqWord8# Wrapper.eqWord8# + , testPrimop "geWord8#" Primop.geWord8# Wrapper.geWord8# + , testPrimop "gtWord8#" Primop.gtWord8# Wrapper.gtWord8# + , testPrimop "leWord8#" Primop.leWord8# Wrapper.leWord8# + , testPrimop "ltWord8#" Primop.ltWord8# Wrapper.ltWord8# + , testPrimop "neWord8#" Primop.neWord8# Wrapper.neWord8# + , testPrimop "int16ToInt#" Primop.int16ToInt# Wrapper.int16ToInt# + , testPrimop "intToInt16#" Primop.intToInt16# Wrapper.intToInt16# + , testPrimop "negateInt16#" Primop.negateInt16# Wrapper.negateInt16# + , testPrimop "plusInt16#" Primop.plusInt16# Wrapper.plusInt16# + , testPrimop "subInt16#" Primop.subInt16# Wrapper.subInt16# + , testPrimop "timesInt16#" Primop.timesInt16# Wrapper.timesInt16# + , testPrimopDivLike "quotInt16#" Primop.quotInt16# Wrapper.quotInt16# + , testPrimopDivLike "remInt16#" Primop.remInt16# Wrapper.remInt16# + , testPrimopDivLike "quotRemInt16#" Primop.quotRemInt16# Wrapper.quotRemInt16# + , testPrimop "uncheckedShiftLInt16#" Primop.uncheckedShiftLInt16# Wrapper.uncheckedShiftLInt16# + , testPrimop "uncheckedShiftRAInt16#" Primop.uncheckedShiftRAInt16# Wrapper.uncheckedShiftRAInt16# + , testPrimop "uncheckedShiftRLInt16#" Primop.uncheckedShiftRLInt16# Wrapper.uncheckedShiftRLInt16# + , testPrimop "int16ToWord16#" Primop.int16ToWord16# Wrapper.int16ToWord16# + , testPrimop "eqInt16#" Primop.eqInt16# Wrapper.eqInt16# + , testPrimop "geInt16#" Primop.geInt16# Wrapper.geInt16# + , testPrimop "gtInt16#" Primop.gtInt16# Wrapper.gtInt16# + , testPrimop "leInt16#" Primop.leInt16# Wrapper.leInt16# + , testPrimop "ltInt16#" Primop.ltInt16# Wrapper.ltInt16# + , testPrimop "neInt16#" Primop.neInt16# Wrapper.neInt16# + , testPrimop "word16ToWord#" Primop.word16ToWord# Wrapper.word16ToWord# + , testPrimop "wordToWord16#" Primop.wordToWord16# Wrapper.wordToWord16# + , testPrimop "plusWord16#" Primop.plusWord16# Wrapper.plusWord16# + , testPrimop "subWord16#" Primop.subWord16# Wrapper.subWord16# + , testPrimop "timesWord16#" Primop.timesWord16# Wrapper.timesWord16# + , testPrimopDivLike "quotWord16#" Primop.quotWord16# Wrapper.quotWord16# + , testPrimopDivLike "remWord16#" Primop.remWord16# Wrapper.remWord16# + , testPrimopDivLike "quotRemWord16#" Primop.quotRemWord16# Wrapper.quotRemWord16# + , testPrimop "andWord16#" Primop.andWord16# Wrapper.andWord16# + , testPrimop "orWord16#" Primop.orWord16# Wrapper.orWord16# + , testPrimop "xorWord16#" Primop.xorWord16# Wrapper.xorWord16# + , testPrimop "notWord16#" Primop.notWord16# Wrapper.notWord16# + , testPrimop "uncheckedShiftLWord16#" Primop.uncheckedShiftLWord16# Wrapper.uncheckedShiftLWord16# + , testPrimop "uncheckedShiftRLWord16#" Primop.uncheckedShiftRLWord16# Wrapper.uncheckedShiftRLWord16# + , testPrimop "word16ToInt16#" Primop.word16ToInt16# Wrapper.word16ToInt16# + , testPrimop "eqWord16#" Primop.eqWord16# Wrapper.eqWord16# + , testPrimop "geWord16#" Primop.geWord16# Wrapper.geWord16# + , testPrimop "gtWord16#" Primop.gtWord16# Wrapper.gtWord16# + , testPrimop "leWord16#" Primop.leWord16# Wrapper.leWord16# + , testPrimop "ltWord16#" Primop.ltWord16# Wrapper.ltWord16# + , testPrimop "neWord16#" Primop.neWord16# Wrapper.neWord16# + , testPrimop "int32ToInt#" Primop.int32ToInt# Wrapper.int32ToInt# + , testPrimop "intToInt32#" Primop.intToInt32# Wrapper.intToInt32# + , testPrimop "negateInt32#" Primop.negateInt32# Wrapper.negateInt32# + , testPrimop "plusInt32#" Primop.plusInt32# Wrapper.plusInt32# + , testPrimop "subInt32#" Primop.subInt32# Wrapper.subInt32# + , testPrimop "timesInt32#" Primop.timesInt32# Wrapper.timesInt32# + , testPrimopDivLike "quotInt32#" Primop.quotInt32# Wrapper.quotInt32# + , testPrimopDivLike "remInt32#" Primop.remInt32# Wrapper.remInt32# + , testPrimopDivLike "quotRemInt32#" Primop.quotRemInt32# Wrapper.quotRemInt32# + , testPrimop "uncheckedShiftLInt32#" Primop.uncheckedShiftLInt32# Wrapper.uncheckedShiftLInt32# + , testPrimop "uncheckedShiftRAInt32#" Primop.uncheckedShiftRAInt32# Wrapper.uncheckedShiftRAInt32# + , testPrimop "uncheckedShiftRLInt32#" Primop.uncheckedShiftRLInt32# Wrapper.uncheckedShiftRLInt32# + , testPrimop "int32ToWord32#" Primop.int32ToWord32# Wrapper.int32ToWord32# + , testPrimop "eqInt32#" Primop.eqInt32# Wrapper.eqInt32# + , testPrimop "geInt32#" Primop.geInt32# Wrapper.geInt32# + , testPrimop "gtInt32#" Primop.gtInt32# Wrapper.gtInt32# + , testPrimop "leInt32#" Primop.leInt32# Wrapper.leInt32# + , testPrimop "ltInt32#" Primop.ltInt32# Wrapper.ltInt32# + , testPrimop "neInt32#" Primop.neInt32# Wrapper.neInt32# + , testPrimop "word32ToWord#" Primop.word32ToWord# Wrapper.word32ToWord# + , testPrimop "wordToWord32#" Primop.wordToWord32# Wrapper.wordToWord32# + , testPrimop "plusWord32#" Primop.plusWord32# Wrapper.plusWord32# + , testPrimop "subWord32#" Primop.subWord32# Wrapper.subWord32# + , testPrimop "timesWord32#" Primop.timesWord32# Wrapper.timesWord32# + , testPrimopDivLike "quotWord32#" Primop.quotWord32# Wrapper.quotWord32# + , testPrimopDivLike "remWord32#" Primop.remWord32# Wrapper.remWord32# + , testPrimopDivLike "quotRemWord32#" Primop.quotRemWord32# Wrapper.quotRemWord32# + , testPrimop "andWord32#" Primop.andWord32# Wrapper.andWord32# + , testPrimop "orWord32#" Primop.orWord32# Wrapper.orWord32# + , testPrimop "xorWord32#" Primop.xorWord32# Wrapper.xorWord32# + , testPrimop "notWord32#" Primop.notWord32# Wrapper.notWord32# + , testPrimop "uncheckedShiftLWord32#" Primop.uncheckedShiftLWord32# Wrapper.uncheckedShiftLWord32# + , testPrimop "uncheckedShiftRLWord32#" Primop.uncheckedShiftRLWord32# Wrapper.uncheckedShiftRLWord32# + , testPrimop "word32ToInt32#" Primop.word32ToInt32# Wrapper.word32ToInt32# + , testPrimop "eqWord32#" Primop.eqWord32# Wrapper.eqWord32# + , testPrimop "geWord32#" Primop.geWord32# Wrapper.geWord32# + , testPrimop "gtWord32#" Primop.gtWord32# Wrapper.gtWord32# + , testPrimop "leWord32#" Primop.leWord32# Wrapper.leWord32# + , testPrimop "ltWord32#" Primop.ltWord32# Wrapper.ltWord32# + , testPrimop "neWord32#" Primop.neWord32# Wrapper.neWord32# + , testPrimop "int64ToInt#" Primop.int64ToInt# Wrapper.int64ToInt# + , testPrimop "intToInt64#" Primop.intToInt64# Wrapper.intToInt64# + , testPrimop "negateInt64#" Primop.negateInt64# Wrapper.negateInt64# + , testPrimop "plusInt64#" Primop.plusInt64# Wrapper.plusInt64# + , testPrimop "subInt64#" Primop.subInt64# Wrapper.subInt64# + , testPrimop "timesInt64#" Primop.timesInt64# Wrapper.timesInt64# + , testPrimopDivLike "quotInt64#" Primop.quotInt64# Wrapper.quotInt64# + , testPrimopDivLike "remInt64#" Primop.remInt64# Wrapper.remInt64# + , testPrimop "uncheckedIShiftL64#" Primop.uncheckedIShiftL64# Wrapper.uncheckedIShiftL64# + , testPrimop "uncheckedIShiftRA64#" Primop.uncheckedIShiftRA64# Wrapper.uncheckedIShiftRA64# + , testPrimop "uncheckedIShiftRL64#" Primop.uncheckedIShiftRL64# Wrapper.uncheckedIShiftRL64# + , testPrimop "int64ToWord64#" Primop.int64ToWord64# Wrapper.int64ToWord64# + , testPrimop "eqInt64#" Primop.eqInt64# Wrapper.eqInt64# + , testPrimop "geInt64#" Primop.geInt64# Wrapper.geInt64# + , testPrimop "gtInt64#" Primop.gtInt64# Wrapper.gtInt64# + , testPrimop "leInt64#" Primop.leInt64# Wrapper.leInt64# + , testPrimop "ltInt64#" Primop.ltInt64# Wrapper.ltInt64# + , testPrimop "neInt64#" Primop.neInt64# Wrapper.neInt64# + , testPrimop "word64ToWord#" Primop.word64ToWord# Wrapper.word64ToWord# + , testPrimop "wordToWord64#" Primop.wordToWord64# Wrapper.wordToWord64# + , testPrimop "plusWord64#" Primop.plusWord64# Wrapper.plusWord64# + , testPrimop "subWord64#" Primop.subWord64# Wrapper.subWord64# + , testPrimop "timesWord64#" Primop.timesWord64# Wrapper.timesWord64# + , testPrimopDivLike "quotWord64#" Primop.quotWord64# Wrapper.quotWord64# + , testPrimopDivLike "remWord64#" Primop.remWord64# Wrapper.remWord64# + , testPrimop "and64#" Primop.and64# Wrapper.and64# + , testPrimop "or64#" Primop.or64# Wrapper.or64# + , testPrimop "xor64#" Primop.xor64# Wrapper.xor64# + , testPrimop "not64#" Primop.not64# Wrapper.not64# + , testPrimop "uncheckedShiftL64#" Primop.uncheckedShiftL64# Wrapper.uncheckedShiftL64# + , testPrimop "uncheckedShiftRL64#" Primop.uncheckedShiftRL64# Wrapper.uncheckedShiftRL64# + , testPrimop "word64ToInt64#" Primop.word64ToInt64# Wrapper.word64ToInt64# + , testPrimop "eqWord64#" Primop.eqWord64# Wrapper.eqWord64# + , testPrimop "geWord64#" Primop.geWord64# Wrapper.geWord64# + , testPrimop "gtWord64#" Primop.gtWord64# Wrapper.gtWord64# + , testPrimop "leWord64#" Primop.leWord64# Wrapper.leWord64# + , testPrimop "ltWord64#" Primop.ltWord64# Wrapper.ltWord64# + , testPrimop "neWord64#" Primop.neWord64# Wrapper.neWord64# + , testPrimop "+#" (Primop.+#) (Wrapper.+#) + , testPrimop "-#" (Primop.-#) (Wrapper.-#) + , testPrimop "*#" (Primop.*#) (Wrapper.*#) + , testPrimop "timesInt2#" Primop.timesInt2# Wrapper.timesInt2# + , testPrimop "mulIntMayOflo#" Primop.mulIntMayOflo# Wrapper.mulIntMayOflo# + , testPrimopDivLike "quotInt#" Primop.quotInt# Wrapper.quotInt# + , testPrimopDivLike "remInt#" Primop.remInt# Wrapper.remInt# + , testPrimopDivLike "quotRemInt#" Primop.quotRemInt# Wrapper.quotRemInt# + , testPrimop "andI#" Primop.andI# Wrapper.andI# + , testPrimop "orI#" Primop.orI# Wrapper.orI# + , testPrimop "xorI#" Primop.xorI# Wrapper.xorI# + , testPrimop "notI#" Primop.notI# Wrapper.notI# + , testPrimop "negateInt#" Primop.negateInt# Wrapper.negateInt# + , testPrimop "addIntC#" Primop.addIntC# Wrapper.addIntC# + , testPrimop "subIntC#" Primop.subIntC# Wrapper.subIntC# + , testPrimop ">#" (Primop.>#) (Wrapper.>#) + , testPrimop ">=#" (Primop.>=#) (Wrapper.>=#) + , testPrimop "==#" (Primop.==#) (Wrapper.==#) + , testPrimop "/=#" (Primop./=#) (Wrapper./=#) + , testPrimop "<#" (Primop.<#) (Wrapper.<#) + , testPrimop "<=#" (Primop.<=#) (Wrapper.<=#) + , testPrimop "chr#" Primop.chr# Wrapper.chr# + , testPrimop "int2Word#" Primop.int2Word# Wrapper.int2Word# + , testPrimop "uncheckedIShiftL#" Primop.uncheckedIShiftL# Wrapper.uncheckedIShiftL# + , testPrimop "uncheckedIShiftRA#" Primop.uncheckedIShiftRA# Wrapper.uncheckedIShiftRA# + , testPrimop "uncheckedIShiftRL#" Primop.uncheckedIShiftRL# Wrapper.uncheckedIShiftRL# + , testPrimop "plusWord#" Primop.plusWord# Wrapper.plusWord# + , testPrimop "addWordC#" Primop.addWordC# Wrapper.addWordC# + , testPrimop "subWordC#" Primop.subWordC# Wrapper.subWordC# + , testPrimop "plusWord2#" Primop.plusWord2# Wrapper.plusWord2# + , testPrimop "minusWord#" Primop.minusWord# Wrapper.minusWord# + , testPrimop "timesWord#" Primop.timesWord# Wrapper.timesWord# + , testPrimop "timesWord2#" Primop.timesWord2# Wrapper.timesWord2# + , testPrimopDivLike "quotWord#" Primop.quotWord# Wrapper.quotWord# + , testPrimopDivLike "remWord#" Primop.remWord# Wrapper.remWord# + , testPrimopDivLike "quotRemWord#" Primop.quotRemWord# Wrapper.quotRemWord# + , testPrimop "and#" Primop.and# Wrapper.and# + , testPrimop "or#" Primop.or# Wrapper.or# + , testPrimop "xor#" Primop.xor# Wrapper.xor# + , testPrimop "not#" Primop.not# Wrapper.not# + , testPrimop "uncheckedShiftL#" Primop.uncheckedShiftL# Wrapper.uncheckedShiftL# + , testPrimop "uncheckedShiftRL#" Primop.uncheckedShiftRL# Wrapper.uncheckedShiftRL# + , testPrimop "word2Int#" Primop.word2Int# Wrapper.word2Int# + , testPrimop "gtWord#" Primop.gtWord# Wrapper.gtWord# + , testPrimop "geWord#" Primop.geWord# Wrapper.geWord# + , testPrimop "eqWord#" Primop.eqWord# Wrapper.eqWord# + , testPrimop "neWord#" Primop.neWord# Wrapper.neWord# + , testPrimop "ltWord#" Primop.ltWord# Wrapper.ltWord# + , testPrimop "leWord#" Primop.leWord# Wrapper.leWord# + , testPrimop "popCnt8#" Primop.popCnt8# Wrapper.popCnt8# + , testPrimop "popCnt16#" Primop.popCnt16# Wrapper.popCnt16# + , testPrimop "popCnt32#" Primop.popCnt32# Wrapper.popCnt32# + , testPrimop "popCnt64#" Primop.popCnt64# Wrapper.popCnt64# + , testPrimop "popCnt#" Primop.popCnt# Wrapper.popCnt# + , testPrimop "pdep8#" Primop.pdep8# Wrapper.pdep8# + , testPrimop "pdep16#" Primop.pdep16# Wrapper.pdep16# + , testPrimop "pdep32#" Primop.pdep32# Wrapper.pdep32# + , testPrimop "pdep64#" Primop.pdep64# Wrapper.pdep64# + , testPrimop "pdep#" Primop.pdep# Wrapper.pdep# + , testPrimop "pext8#" Primop.pext8# Wrapper.pext8# + , testPrimop "pext16#" Primop.pext16# Wrapper.pext16# + , testPrimop "pext32#" Primop.pext32# Wrapper.pext32# + , testPrimop "pext64#" Primop.pext64# Wrapper.pext64# + , testPrimop "pext#" Primop.pext# Wrapper.pext# + , testPrimop "clz8#" Primop.clz8# Wrapper.clz8# + , testPrimop "clz16#" Primop.clz16# Wrapper.clz16# + , testPrimop "clz32#" Primop.clz32# Wrapper.clz32# + , testPrimop "clz64#" Primop.clz64# Wrapper.clz64# + , testPrimop "clz#" Primop.clz# Wrapper.clz# + , testPrimop "ctz8#" Primop.ctz8# Wrapper.ctz8# + , testPrimop "ctz16#" Primop.ctz16# Wrapper.ctz16# + , testPrimop "ctz32#" Primop.ctz32# Wrapper.ctz32# + , testPrimop "ctz64#" Primop.ctz64# Wrapper.ctz64# + , testPrimop "ctz#" Primop.ctz# Wrapper.ctz# + , testPrimop "byteSwap16#" Primop.byteSwap16# Wrapper.byteSwap16# + , testPrimop "byteSwap32#" Primop.byteSwap32# Wrapper.byteSwap32# + , testPrimop "byteSwap64#" Primop.byteSwap64# Wrapper.byteSwap64# + , testPrimop "byteSwap#" Primop.byteSwap# Wrapper.byteSwap# + , testPrimop "bitReverse8#" Primop.bitReverse8# Wrapper.bitReverse8# + , testPrimop "bitReverse16#" Primop.bitReverse16# Wrapper.bitReverse16# + , testPrimop "bitReverse32#" Primop.bitReverse32# Wrapper.bitReverse32# + , testPrimop "bitReverse64#" Primop.bitReverse64# Wrapper.bitReverse64# + , testPrimop "bitReverse#" Primop.bitReverse# Wrapper.bitReverse# + , testPrimop "narrow8Int#" Primop.narrow8Int# Wrapper.narrow8Int# + , testPrimop "narrow16Int#" Primop.narrow16Int# Wrapper.narrow16Int# + , testPrimop "narrow32Int#" Primop.narrow32Int# Wrapper.narrow32Int# + , testPrimop "narrow8Word#" Primop.narrow8Word# Wrapper.narrow8Word# + , testPrimop "narrow16Word#" Primop.narrow16Word# Wrapper.narrow16Word# + , testPrimop "narrow32Word#" Primop.narrow32Word# Wrapper.narrow32Word# + ] + +instance TestPrimop (Char# -> Char# -> Int#) where + testPrimop s l r = Property s $ \ (uChar#-> x0) (uChar#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Char# -> Int#) where + testPrimop s l r = Property s $ \ (uChar#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int# -> Int# -> Int#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) (uInt#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt#-> x0) (uInt#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Int# -> Int# -> (# Int#,Int# #)) where + testPrimop s l r = Property s $ \ (uInt#-> x0) (uInt#-> x1) -> WTUP2(wInt#,wInt#, (l x0 x1)) === WTUP2(wInt#,wInt#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt#-> x0) (uInt#-> x1) -> WTUP2(wInt#,wInt#, (l x0 x1)) === WTUP2(wInt#,wInt#, (r x0 x1)) + +instance TestPrimop (Int# -> Int# -> (# Int#,Int#,Int# #)) where + testPrimop s l r = Property s $ \ (uInt#-> x0) (uInt#-> x1) -> WTUP3(wInt#,wInt#,wInt#, (l x0 x1)) === WTUP3(wInt#,wInt#,wInt#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt#-> x0) (uInt#-> x1) -> WTUP3(wInt#,wInt#,wInt#, (l x0 x1)) === WTUP3(wInt#,wInt#,wInt#, (r x0 x1)) + +instance TestPrimop (Int# -> Char#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wChar# (l x0) === wChar# (r x0) + +instance TestPrimop (Int# -> Int#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int# -> Int16#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wInt16# (l x0) === wInt16# (r x0) + +instance TestPrimop (Int# -> Int32#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wInt32# (l x0) === wInt32# (r x0) + +instance TestPrimop (Int# -> Int64#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wInt64# (l x0) === wInt64# (r x0) + +instance TestPrimop (Int# -> Int8#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wInt8# (l x0) === wInt8# (r x0) + +instance TestPrimop (Int# -> Word#) where + testPrimop s l r = Property s $ \ (uInt#-> x0) -> wWord# (l x0) === wWord# (r x0) + +instance TestPrimop (Int16# -> Int# -> Int16#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) (uInt#-> x1) -> wInt16# (l x0 x1) === wInt16# (r x0 x1) + +instance TestPrimop (Int16# -> Int16# -> Int#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) (uInt16#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt16#-> x0) (uInt16#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Int16# -> Int16# -> Int16#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) (uInt16#-> x1) -> wInt16# (l x0 x1) === wInt16# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt16#-> x0) (uInt16#-> x1) -> wInt16# (l x0 x1) === wInt16# (r x0 x1) + +instance TestPrimop (Int16# -> Int16# -> (# Int16#,Int16# #)) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) (uInt16#-> x1) -> WTUP2(wInt16#,wInt16#, (l x0 x1)) === WTUP2(wInt16#,wInt16#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt16#-> x0) (uInt16#-> x1) -> WTUP2(wInt16#,wInt16#, (l x0 x1)) === WTUP2(wInt16#,wInt16#, (r x0 x1)) + +instance TestPrimop (Int16# -> Int#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int16# -> Int16#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) -> wInt16# (l x0) === wInt16# (r x0) + +instance TestPrimop (Int16# -> Word16#) where + testPrimop s l r = Property s $ \ (uInt16#-> x0) -> wWord16# (l x0) === wWord16# (r x0) + +instance TestPrimop (Int32# -> Int# -> Int32#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) (uInt#-> x1) -> wInt32# (l x0 x1) === wInt32# (r x0 x1) + +instance TestPrimop (Int32# -> Int32# -> Int#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) (uInt32#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt32#-> x0) (uInt32#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Int32# -> Int32# -> Int32#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) (uInt32#-> x1) -> wInt32# (l x0 x1) === wInt32# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt32#-> x0) (uInt32#-> x1) -> wInt32# (l x0 x1) === wInt32# (r x0 x1) + +instance TestPrimop (Int32# -> Int32# -> (# Int32#,Int32# #)) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) (uInt32#-> x1) -> WTUP2(wInt32#,wInt32#, (l x0 x1)) === WTUP2(wInt32#,wInt32#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt32#-> x0) (uInt32#-> x1) -> WTUP2(wInt32#,wInt32#, (l x0 x1)) === WTUP2(wInt32#,wInt32#, (r x0 x1)) + +instance TestPrimop (Int32# -> Int#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int32# -> Int32#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) -> wInt32# (l x0) === wInt32# (r x0) + +instance TestPrimop (Int32# -> Word32#) where + testPrimop s l r = Property s $ \ (uInt32#-> x0) -> wWord32# (l x0) === wWord32# (r x0) + +instance TestPrimop (Int64# -> Int# -> Int64#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) (uInt#-> x1) -> wInt64# (l x0 x1) === wInt64# (r x0 x1) + +instance TestPrimop (Int64# -> Int64# -> Int#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) (uInt64#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt64#-> x0) (uInt64#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Int64# -> Int64# -> Int64#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) (uInt64#-> x1) -> wInt64# (l x0 x1) === wInt64# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt64#-> x0) (uInt64#-> x1) -> wInt64# (l x0 x1) === wInt64# (r x0 x1) + +instance TestPrimop (Int64# -> Int#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int64# -> Int64#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) -> wInt64# (l x0) === wInt64# (r x0) + +instance TestPrimop (Int64# -> Word64#) where + testPrimop s l r = Property s $ \ (uInt64#-> x0) -> wWord64# (l x0) === wWord64# (r x0) + +instance TestPrimop (Int8# -> Int# -> Int8#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) (uInt#-> x1) -> wInt8# (l x0 x1) === wInt8# (r x0 x1) + +instance TestPrimop (Int8# -> Int8# -> Int#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) (uInt8#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt8#-> x0) (uInt8#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Int8# -> Int8# -> Int8#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) (uInt8#-> x1) -> wInt8# (l x0 x1) === wInt8# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt8#-> x0) (uInt8#-> x1) -> wInt8# (l x0 x1) === wInt8# (r x0 x1) + +instance TestPrimop (Int8# -> Int8# -> (# Int8#,Int8# #)) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) (uInt8#-> x1) -> WTUP2(wInt8#,wInt8#, (l x0 x1)) === WTUP2(wInt8#,wInt8#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uInt8#-> x0) (uInt8#-> x1) -> WTUP2(wInt8#,wInt8#, (l x0 x1)) === WTUP2(wInt8#,wInt8#, (r x0 x1)) + +instance TestPrimop (Int8# -> Int#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Int8# -> Int8#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) -> wInt8# (l x0) === wInt8# (r x0) + +instance TestPrimop (Int8# -> Word8#) where + testPrimop s l r = Property s $ \ (uInt8#-> x0) -> wWord8# (l x0) === wWord8# (r x0) + +instance TestPrimop (Word# -> Int# -> Word#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) (uInt#-> x1) -> wWord# (l x0 x1) === wWord# (r x0 x1) + +instance TestPrimop (Word# -> Word# -> Int#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) (uWord#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord#-> x0) (uWord#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Word# -> Word# -> Word#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) (uWord#-> x1) -> wWord# (l x0 x1) === wWord# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord#-> x0) (uWord#-> x1) -> wWord# (l x0 x1) === wWord# (r x0 x1) + +instance TestPrimop (Word# -> Word# -> (# Word#,Int# #)) where + testPrimop s l r = Property s $ \ (uWord#-> x0) (uWord#-> x1) -> WTUP2(wWord#,wInt#, (l x0 x1)) === WTUP2(wWord#,wInt#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord#-> x0) (uWord#-> x1) -> WTUP2(wWord#,wInt#, (l x0 x1)) === WTUP2(wWord#,wInt#, (r x0 x1)) + +instance TestPrimop (Word# -> Word# -> (# Word#,Word# #)) where + testPrimop s l r = Property s $ \ (uWord#-> x0) (uWord#-> x1) -> WTUP2(wWord#,wWord#, (l x0 x1)) === WTUP2(wWord#,wWord#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord#-> x0) (uWord#-> x1) -> WTUP2(wWord#,wWord#, (l x0 x1)) === WTUP2(wWord#,wWord#, (r x0 x1)) + +instance TestPrimop (Word# -> Int#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wInt# (l x0) === wInt# (r x0) + +instance TestPrimop (Word# -> Word#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wWord# (l x0) === wWord# (r x0) + +instance TestPrimop (Word# -> Word16#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wWord16# (l x0) === wWord16# (r x0) + +instance TestPrimop (Word# -> Word32#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wWord32# (l x0) === wWord32# (r x0) + +instance TestPrimop (Word# -> Word64#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wWord64# (l x0) === wWord64# (r x0) + +instance TestPrimop (Word# -> Word8#) where + testPrimop s l r = Property s $ \ (uWord#-> x0) -> wWord8# (l x0) === wWord8# (r x0) + +instance TestPrimop (Word16# -> Int# -> Word16#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) (uInt#-> x1) -> wWord16# (l x0 x1) === wWord16# (r x0 x1) + +instance TestPrimop (Word16# -> Word16# -> Int#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) (uWord16#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord16#-> x0) (uWord16#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Word16# -> Word16# -> Word16#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) (uWord16#-> x1) -> wWord16# (l x0 x1) === wWord16# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord16#-> x0) (uWord16#-> x1) -> wWord16# (l x0 x1) === wWord16# (r x0 x1) + +instance TestPrimop (Word16# -> Word16# -> (# Word16#,Word16# #)) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) (uWord16#-> x1) -> WTUP2(wWord16#,wWord16#, (l x0 x1)) === WTUP2(wWord16#,wWord16#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord16#-> x0) (uWord16#-> x1) -> WTUP2(wWord16#,wWord16#, (l x0 x1)) === WTUP2(wWord16#,wWord16#, (r x0 x1)) + +instance TestPrimop (Word16# -> Int16#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) -> wInt16# (l x0) === wInt16# (r x0) + +instance TestPrimop (Word16# -> Word#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) -> wWord# (l x0) === wWord# (r x0) + +instance TestPrimop (Word16# -> Word16#) where + testPrimop s l r = Property s $ \ (uWord16#-> x0) -> wWord16# (l x0) === wWord16# (r x0) + +instance TestPrimop (Word32# -> Int# -> Word32#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) (uInt#-> x1) -> wWord32# (l x0 x1) === wWord32# (r x0 x1) + +instance TestPrimop (Word32# -> Word32# -> Int#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) (uWord32#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord32#-> x0) (uWord32#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Word32# -> Word32# -> Word32#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) (uWord32#-> x1) -> wWord32# (l x0 x1) === wWord32# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord32#-> x0) (uWord32#-> x1) -> wWord32# (l x0 x1) === wWord32# (r x0 x1) + +instance TestPrimop (Word32# -> Word32# -> (# Word32#,Word32# #)) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) (uWord32#-> x1) -> WTUP2(wWord32#,wWord32#, (l x0 x1)) === WTUP2(wWord32#,wWord32#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord32#-> x0) (uWord32#-> x1) -> WTUP2(wWord32#,wWord32#, (l x0 x1)) === WTUP2(wWord32#,wWord32#, (r x0 x1)) + +instance TestPrimop (Word32# -> Int32#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) -> wInt32# (l x0) === wInt32# (r x0) + +instance TestPrimop (Word32# -> Word#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) -> wWord# (l x0) === wWord# (r x0) + +instance TestPrimop (Word32# -> Word32#) where + testPrimop s l r = Property s $ \ (uWord32#-> x0) -> wWord32# (l x0) === wWord32# (r x0) + +instance TestPrimop (Word64# -> Int# -> Word64#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) (uInt#-> x1) -> wWord64# (l x0 x1) === wWord64# (r x0 x1) + +instance TestPrimop (Word64# -> Word64# -> Int#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) (uWord64#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord64#-> x0) (uWord64#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Word64# -> Word64# -> Word64#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) (uWord64#-> x1) -> wWord64# (l x0 x1) === wWord64# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord64#-> x0) (uWord64#-> x1) -> wWord64# (l x0 x1) === wWord64# (r x0 x1) + +instance TestPrimop (Word64# -> Int64#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) -> wInt64# (l x0) === wInt64# (r x0) + +instance TestPrimop (Word64# -> Word#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) -> wWord# (l x0) === wWord# (r x0) + +instance TestPrimop (Word64# -> Word64#) where + testPrimop s l r = Property s $ \ (uWord64#-> x0) -> wWord64# (l x0) === wWord64# (r x0) + +instance TestPrimop (Word8# -> Int# -> Word8#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) (uInt#-> x1) -> wWord8# (l x0 x1) === wWord8# (r x0 x1) + +instance TestPrimop (Word8# -> Word8# -> Int#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) (uWord8#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord8#-> x0) (uWord8#-> x1) -> wInt# (l x0 x1) === wInt# (r x0 x1) + +instance TestPrimop (Word8# -> Word8# -> Word8#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) (uWord8#-> x1) -> wWord8# (l x0 x1) === wWord8# (r x0 x1) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord8#-> x0) (uWord8#-> x1) -> wWord8# (l x0 x1) === wWord8# (r x0 x1) + +instance TestPrimop (Word8# -> Word8# -> (# Word8#,Word8# #)) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) (uWord8#-> x1) -> WTUP2(wWord8#,wWord8#, (l x0 x1)) === WTUP2(wWord8#,wWord8#, (r x0 x1)) + testPrimopDivLike s l r = Property s $ twoNonZero $ \ (uWord8#-> x0) (uWord8#-> x1) -> WTUP2(wWord8#,wWord8#, (l x0 x1)) === WTUP2(wWord8#,wWord8#, (r x0 x1)) + +instance TestPrimop (Word8# -> Int8#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) -> wInt8# (l x0) === wInt8# (r x0) +instance TestPrimop (Word8# -> Word#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) -> wWord# (l x0) === wWord# (r x0) -main = runTests testNumberRefs +instance TestPrimop (Word8# -> Word8#) where + testPrimop s l r = Property s $ \ (uWord8#-> x0) -> wWord8# (l x0) === wWord8# (r x0) ===================================== testsuite/tests/numeric/should_run/foundation.stdout ===================================== @@ -1,540 +1,1050 @@ Group ALL - Group Int - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Int8 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Int16 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Int32 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Int64 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Integer - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Word - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Word8 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Word16 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Word32 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations - Group Word64 - Group Integral - Running FromIntegral(Integer(a)) == a - Passed 100 iterations - Group Property - Running Eq - Passed 100 iterations - Running Show - Passed 100 iterations - Running Ord - Passed 100 iterations - Running < - Passed 100 iterations - Group Additive - Running a + azero == a - Passed 100 iterations - Running azero + a == a - Passed 100 iterations - Running a + b == b + a - Passed 100 iterations - Group Multiplicative - Running a * 1 == a - Passed 100 iterations - Running 1 * a == a - Passed 100 iterations - Running multiplication commutative - Passed 100 iterations - Running a * b == Integer(a) * Integer(b) - Passed 100 iterations - Group Divisible - Running (x `div` y) * y + (x `mod` y) == x - Passed 100 iterations - Group Precedence - Running + and - (1) - Passed 100 iterations - Running + and - (2) - Passed 100 iterations - Running + and * (1) - Passed 100 iterations - Running + and * (2) - Passed 100 iterations - Running - and * (1) - Passed 100 iterations - Running - and * (2) - Passed 100 iterations - Running * and ^ (1) - Passed 100 iterations - Running * and ^ (2) - Passed 100 iterations + Group ALL + Group Int + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Int8 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Int16 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Int32 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Int64 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Integer + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Word + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Word8 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Word16 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Word32 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group Word64 + Group Integral + Running FromIntegral(Integer(a)) == a + Passed 100 iterations + Group Property + Running Eq + Passed 100 iterations + Running Show + Passed 100 iterations + Running Ord + Passed 100 iterations + Running < + Passed 100 iterations + Group Additive + Running a + azero == a + Passed 100 iterations + Running azero + a == a + Passed 100 iterations + Running a + b == b + a + Passed 100 iterations + Group Multiplicative + Running a * 1 == a + Passed 100 iterations + Running 1 * a == a + Passed 100 iterations + Running multiplication commutative + Passed 100 iterations + Running a * b == Integer(a) * Integer(b) + Passed 100 iterations + Group Divisible + Running (x `div` y) * y + (x `mod` y) == x + Passed 100 iterations + Group Precedence + Running + and - (1) + Passed 100 iterations + Running + and - (2) + Passed 100 iterations + Running + and * (1) + Passed 100 iterations + Running + and * (2) + Passed 100 iterations + Running - and * (1) + Passed 100 iterations + Running - and * (2) + Passed 100 iterations + Running * and ^ (1) + Passed 100 iterations + Running * and ^ (2) + Passed 100 iterations + Group primop + Running gtChar# + Passed 100 iterations + Running geChar# + Passed 100 iterations + Running eqChar# + Passed 100 iterations + Running neChar# + Passed 100 iterations + Running ltChar# + Passed 100 iterations + Running leChar# + Passed 100 iterations + Running ord# + Passed 100 iterations + Running int8ToInt# + Passed 100 iterations + Running intToInt8# + Passed 100 iterations + Running negateInt8# + Passed 100 iterations + Running plusInt8# + Passed 100 iterations + Running subInt8# + Passed 100 iterations + Running timesInt8# + Passed 100 iterations + Running quotInt8# + Passed 100 iterations + Running remInt8# + Passed 100 iterations + Running quotRemInt8# + Passed 100 iterations + Running uncheckedShiftLInt8# + Passed 100 iterations + Running uncheckedShiftRAInt8# + Passed 100 iterations + Running uncheckedShiftRLInt8# + Passed 100 iterations + Running int8ToWord8# + Passed 100 iterations + Running eqInt8# + Passed 100 iterations + Running geInt8# + Passed 100 iterations + Running gtInt8# + Passed 100 iterations + Running leInt8# + Passed 100 iterations + Running ltInt8# + Passed 100 iterations + Running neInt8# + Passed 100 iterations + Running word8ToWord# + Passed 100 iterations + Running wordToWord8# + Passed 100 iterations + Running plusWord8# + Passed 100 iterations + Running subWord8# + Passed 100 iterations + Running timesWord8# + Passed 100 iterations + Running quotWord8# + Passed 100 iterations + Running remWord8# + Passed 100 iterations + Running quotRemWord8# + Passed 100 iterations + Running andWord8# + Passed 100 iterations + Running orWord8# + Passed 100 iterations + Running xorWord8# + Passed 100 iterations + Running notWord8# + Passed 100 iterations + Running uncheckedShiftLWord8# + Passed 100 iterations + Running uncheckedShiftRLWord8# + Passed 100 iterations + Running word8ToInt8# + Passed 100 iterations + Running eqWord8# + Passed 100 iterations + Running geWord8# + Passed 100 iterations + Running gtWord8# + Passed 100 iterations + Running leWord8# + Passed 100 iterations + Running ltWord8# + Passed 100 iterations + Running neWord8# + Passed 100 iterations + Running int16ToInt# + Passed 100 iterations + Running intToInt16# + Passed 100 iterations + Running negateInt16# + Passed 100 iterations + Running plusInt16# + Passed 100 iterations + Running subInt16# + Passed 100 iterations + Running timesInt16# + Passed 100 iterations + Running quotInt16# + Passed 100 iterations + Running remInt16# + Passed 100 iterations + Running quotRemInt16# + Passed 100 iterations + Running uncheckedShiftLInt16# + Passed 100 iterations + Running uncheckedShiftRAInt16# + Passed 100 iterations + Running uncheckedShiftRLInt16# + Passed 100 iterations + Running int16ToWord16# + Passed 100 iterations + Running eqInt16# + Passed 100 iterations + Running geInt16# + Passed 100 iterations + Running gtInt16# + Passed 100 iterations + Running leInt16# + Passed 100 iterations + Running ltInt16# + Passed 100 iterations + Running neInt16# + Passed 100 iterations + Running word16ToWord# + Passed 100 iterations + Running wordToWord16# + Passed 100 iterations + Running plusWord16# + Passed 100 iterations + Running subWord16# + Passed 100 iterations + Running timesWord16# + Passed 100 iterations + Running quotWord16# + Passed 100 iterations + Running remWord16# + Passed 100 iterations + Running quotRemWord16# + Passed 100 iterations + Running andWord16# + Passed 100 iterations + Running orWord16# + Passed 100 iterations + Running xorWord16# + Passed 100 iterations + Running notWord16# + Passed 100 iterations + Running uncheckedShiftLWord16# + Passed 100 iterations + Running uncheckedShiftRLWord16# + Passed 100 iterations + Running word16ToInt16# + Passed 100 iterations + Running eqWord16# + Passed 100 iterations + Running geWord16# + Passed 100 iterations + Running gtWord16# + Passed 100 iterations + Running leWord16# + Passed 100 iterations + Running ltWord16# + Passed 100 iterations + Running neWord16# + Passed 100 iterations + Running int32ToInt# + Passed 100 iterations + Running intToInt32# + Passed 100 iterations + Running negateInt32# + Passed 100 iterations + Running plusInt32# + Passed 100 iterations + Running subInt32# + Passed 100 iterations + Running timesInt32# + Passed 100 iterations + Running quotInt32# + Passed 100 iterations + Running remInt32# + Passed 100 iterations + Running quotRemInt32# + Passed 100 iterations + Running uncheckedShiftLInt32# + Passed 100 iterations + Running uncheckedShiftRAInt32# + Passed 100 iterations + Running uncheckedShiftRLInt32# + Passed 100 iterations + Running int32ToWord32# + Passed 100 iterations + Running eqInt32# + Passed 100 iterations + Running geInt32# + Passed 100 iterations + Running gtInt32# + Passed 100 iterations + Running leInt32# + Passed 100 iterations + Running ltInt32# + Passed 100 iterations + Running neInt32# + Passed 100 iterations + Running word32ToWord# + Passed 100 iterations + Running wordToWord32# + Passed 100 iterations + Running plusWord32# + Passed 100 iterations + Running subWord32# + Passed 100 iterations + Running timesWord32# + Passed 100 iterations + Running quotWord32# + Passed 100 iterations + Running remWord32# + Passed 100 iterations + Running quotRemWord32# + Passed 100 iterations + Running andWord32# + Passed 100 iterations + Running orWord32# + Passed 100 iterations + Running xorWord32# + Passed 100 iterations + Running notWord32# + Passed 100 iterations + Running uncheckedShiftLWord32# + Passed 100 iterations + Running uncheckedShiftRLWord32# + Passed 100 iterations + Running word32ToInt32# + Passed 100 iterations + Running eqWord32# + Passed 100 iterations + Running geWord32# + Passed 100 iterations + Running gtWord32# + Passed 100 iterations + Running leWord32# + Passed 100 iterations + Running ltWord32# + Passed 100 iterations + Running neWord32# + Passed 100 iterations + Running int64ToInt# + Passed 100 iterations + Running intToInt64# + Passed 100 iterations + Running negateInt64# + Passed 100 iterations + Running plusInt64# + Passed 100 iterations + Running subInt64# + Passed 100 iterations + Running timesInt64# + Passed 100 iterations + Running quotInt64# + Passed 100 iterations + Running remInt64# + Passed 100 iterations + Running uncheckedIShiftL64# + Passed 100 iterations + Running uncheckedIShiftRA64# + Passed 100 iterations + Running uncheckedIShiftRL64# + Passed 100 iterations + Running int64ToWord64# + Passed 100 iterations + Running eqInt64# + Passed 100 iterations + Running geInt64# + Passed 100 iterations + Running gtInt64# + Passed 100 iterations + Running leInt64# + Passed 100 iterations + Running ltInt64# + Passed 100 iterations + Running neInt64# + Passed 100 iterations + Running word64ToWord# + Passed 100 iterations + Running wordToWord64# + Passed 100 iterations + Running plusWord64# + Passed 100 iterations + Running subWord64# + Passed 100 iterations + Running timesWord64# + Passed 100 iterations + Running quotWord64# + Passed 100 iterations + Running remWord64# + Passed 100 iterations + Running and64# + Passed 100 iterations + Running or64# + Passed 100 iterations + Running xor64# + Passed 100 iterations + Running not64# + Passed 100 iterations + Running uncheckedShiftL64# + Passed 100 iterations + Running uncheckedShiftRL64# + Passed 100 iterations + Running word64ToInt64# + Passed 100 iterations + Running eqWord64# + Passed 100 iterations + Running geWord64# + Passed 100 iterations + Running gtWord64# + Passed 100 iterations + Running leWord64# + Passed 100 iterations + Running ltWord64# + Passed 100 iterations + Running neWord64# + Passed 100 iterations + Running +# + Passed 100 iterations + Running -# + Passed 100 iterations + Running *# + Passed 100 iterations + Running timesInt2# + Passed 100 iterations + Running mulIntMayOflo# + Passed 100 iterations + Running quotInt# + Passed 100 iterations + Running remInt# + Passed 100 iterations + Running quotRemInt# + Passed 100 iterations + Running andI# + Passed 100 iterations + Running orI# + Passed 100 iterations + Running xorI# + Passed 100 iterations + Running notI# + Passed 100 iterations + Running negateInt# + Passed 100 iterations + Running addIntC# + Passed 100 iterations + Running subIntC# + Passed 100 iterations + Running ># + Passed 100 iterations + Running >=# + Passed 100 iterations + Running ==# + Passed 100 iterations + Running /=# + Passed 100 iterations + Running <# + Passed 100 iterations + Running <=# + Passed 100 iterations + Running chr# + Passed 100 iterations + Running int2Word# + Passed 100 iterations + Running uncheckedIShiftL# + Passed 100 iterations + Running uncheckedIShiftRA# + Passed 100 iterations + Running uncheckedIShiftRL# + Passed 100 iterations + Running plusWord# + Passed 100 iterations + Running addWordC# + Passed 100 iterations + Running subWordC# + Passed 100 iterations + Running plusWord2# + Passed 100 iterations + Running minusWord# + Passed 100 iterations + Running timesWord# + Passed 100 iterations + Running timesWord2# + Passed 100 iterations + Running quotWord# + Passed 100 iterations + Running remWord# + Passed 100 iterations + Running quotRemWord# + Passed 100 iterations + Running and# + Passed 100 iterations + Running or# + Passed 100 iterations + Running xor# + Passed 100 iterations + Running not# + Passed 100 iterations + Running uncheckedShiftL# + Passed 100 iterations + Running uncheckedShiftRL# + Passed 100 iterations + Running word2Int# + Passed 100 iterations + Running gtWord# + Passed 100 iterations + Running geWord# + Passed 100 iterations + Running eqWord# + Passed 100 iterations + Running neWord# + Passed 100 iterations + Running ltWord# + Passed 100 iterations + Running leWord# + Passed 100 iterations + Running popCnt8# + Passed 100 iterations + Running popCnt16# + Passed 100 iterations + Running popCnt32# + Passed 100 iterations + Running popCnt64# + Passed 100 iterations + Running popCnt# + Passed 100 iterations + Running pdep8# + Passed 100 iterations + Running pdep16# + Passed 100 iterations + Running pdep32# + Passed 100 iterations + Running pdep64# + Passed 100 iterations + Running pdep# + Passed 100 iterations + Running pext8# + Passed 100 iterations + Running pext16# + Passed 100 iterations + Running pext32# + Passed 100 iterations + Running pext64# + Passed 100 iterations + Running pext# + Passed 100 iterations + Running clz8# + Passed 100 iterations + Running clz16# + Passed 100 iterations + Running clz32# + Passed 100 iterations + Running clz64# + Passed 100 iterations + Running clz# + Passed 100 iterations + Running ctz8# + Passed 100 iterations + Running ctz16# + Passed 100 iterations + Running ctz32# + Passed 100 iterations + Running ctz64# + Passed 100 iterations + Running ctz# + Passed 100 iterations + Running byteSwap16# + Passed 100 iterations + Running byteSwap32# + Passed 100 iterations + Running byteSwap64# + Passed 100 iterations + Running byteSwap# + Passed 100 iterations + Running bitReverse8# + Passed 100 iterations + Running bitReverse16# + Passed 100 iterations + Running bitReverse32# + Passed 100 iterations + Running bitReverse64# + Passed 100 iterations + Running bitReverse# + Passed 100 iterations + Running narrow8Int# + Passed 100 iterations + Running narrow16Int# + Passed 100 iterations + Running narrow32Int# + Passed 100 iterations + Running narrow8Word# + Passed 100 iterations + Running narrow16Word# + Passed 100 iterations + Running narrow32Word# + Passed 100 iterations ===================================== utils/genprimopcode/Main.hs ===================================== @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} ------------------------------------------------------------------ -- A primop-table mangling program -- -- @@ -10,11 +11,12 @@ import Parser import Syntax import Data.Char -import Data.List (union, intersperse, intercalate, nub) -import Data.Maybe ( catMaybes ) +import Data.List (union, intersperse, intercalate, nub, sort) +import Data.Maybe ( catMaybes, mapMaybe ) import System.Environment ( getArgs ) import System.IO ( hSetEncoding, stdin, stdout, utf8 ) + vecOptions :: Entry -> [(String,String,Int)] vecOptions i = concat [vecs | OptionVector vecs <- opts i] @@ -204,6 +206,9 @@ main = getArgs >>= \args -> "--wired-in-deprecations" -> putStr (gen_wired_in_deprecations p_o_specs) + "--foundation-tests" + -> putStr (gen_foundation_tests p_o_specs) + _ -> error "Should not happen, known_args out of sync?" ) @@ -229,7 +234,8 @@ known_args "--make-haskell-source", "--make-latex-doc", "--wired-in-docs", - "--wired-in-deprecations" + "--wired-in-deprecations", + "--foundation-tests" ] ------------------------------------------------------------------ @@ -679,6 +685,92 @@ gen_wired_in_deprecations (Info _ entries) | otherwise = Nothing +gen_foundation_tests :: Info -> String +gen_foundation_tests (Info _ entries) + = "tests =\n [ " + ++ intercalate "\n , " (catMaybes $ map mkTest entries) + ++ "\n ]\n" + ++ "\n" ++ intercalate "\n" (map mkInstances testable_tys) + where + testable_tys = nub (sort (mapMaybe (\po -> ty po <$ mkTest po) entries)) + + mkInstances inst_ty = + let test_lambda = "\\ " ++ intercalate " " (zipWith mkArg [0::Int ..] (arg_tys)) ++ " -> " ++ mk_body "l" ++ " === " ++ mk_body "r" + in unlines $ + [ "instance TestPrimop (" ++ pprTy inst_ty ++ ") where" + , " testPrimop s l r = Property s $ " ++ test_lambda ] + ++ (if mb_divable_tys + then [" testPrimopDivLike s l r = Property s $ twoNonZero $ " ++ test_lambda] + else []) + where + arg_tys = args inst_ty + -- eg Int -> Int -> a + mb_divable_tys = case arg_tys of + [ty1,ty2] -> ty1 == ty2 && ty1 `elem` divableTyCons + _ -> False + + mk_body s = res_ty inst_ty (" (" ++ s ++ " " ++ intercalate " " vs ++ ")") + + vs = zipWith (\n _ -> "x" ++ show n) [0::Int ..] (arg_tys) + + mkArg n t = "(" ++ unwrapper t ++ "-> x" ++ show n ++ ")" + + + wrapper s = "w" ++ s + unwrapper s = "u" ++ s + + + args (TyF (TyApp (TyCon c) []) t2) = c : args t2 + args (TyApp {}) = [] + args (TyUTup {}) = [] + -- If you hit this you will need to handle the foundation tests to handle the + -- type it failed on. + args arg_ty = error ("Unexpected primop type:" ++ pprTy arg_ty) + + res_ty (TyF _ t2) x = res_ty t2 x + res_ty (TyApp (TyCon c) []) x = wrapper c ++ x + res_ty (TyUTup tup_tys) x = + let wtup = case length tup_tys of + 2 -> "WTUP2" + 3 -> "WTUP3" + -- Only handles primops returning unboxed tuples up to 3 args currently + _ -> error "Unexpected primop result type" + in wtup ++"(" ++ intercalate "," (map (\a -> res_ty a "") tup_tys ++ [x]) ++ ")" + -- If you hit this you will need to handle the foundation tests to handle the + -- type it failed on. + res_ty unexpected_ty x = error ("Unexpected primop result type:" ++ pprTy unexpected_ty ++ "," ++ x) + + + wrap qual nm | isLower (head nm) = qual ++ "." ++ nm + | otherwise = "(" ++ qual ++ "." ++ nm ++ ")" + mkTest po + | Just poName <- getName po + , is_primop po + , not $ is_vector po + , poName /= "tagToEnum#" + , poName /= "quotRemWord2#" + , (testable (ty po)) + = let testPrimOpHow = if is_divLikeOp po + then "testPrimopDivLike" + else "testPrimop" + in Just $ intercalate " " [testPrimOpHow, "\"" ++ poName ++ "\"", wrap "Primop" poName, wrap "Wrapper" poName] + | otherwise = Nothing + + + + testable (TyF t1 t2) = testable t1 && testable t2 + testable (TyC _ t2) = testable t2 + testable (TyApp tc tys) = testableTyCon tc && all testable tys + testable (TyVar _a) = False + testable (TyUTup tys) = all testable tys + + testableTyCon (TyCon c) = + c `elem` ["Int#", "Word#", "Word8#", "Word16#", "Word32#", "Word64#" + , "Int8#", "Int16#", "Int32#", "Int64#", "Char#"] + testableTyCon _ = False + divableTyCons = ["Int#", "Word#", "Word8#", "Word16#", "Word32#", "Word64#" + ,"Int8#", "Int16#", "Int32#", "Int64#"] + ------------------------------------------------------------------ -- Create PrimOpInfo text from PrimOpSpecs ----------------------- ------------------------------------------------------------------ ===================================== utils/genprimopcode/Syntax.hs ===================================== @@ -53,6 +53,19 @@ is_primtype :: Entry -> Bool is_primtype (PrimTypeSpec {}) = True is_primtype _ = False +is_divLikeOp :: Entry -> Bool +is_divLikeOp entry = case entry of + PrimOpSpec{} -> has_div_like + PseudoOpSpec{} -> has_div_like + PrimVecOpSpec{} -> has_div_like + PrimTypeSpec{} -> False + PrimVecTypeSpec{} -> False + Section{} -> False + where + has_div_like = case lookup_attrib "div_like" (opts entry) of + Just (OptionTrue{}) -> True + _ -> False + -- a binding of property to value data Option = OptionFalse String -- name = False @@ -78,7 +91,7 @@ data Ty | TyVar TyVar | TyUTup [Ty] -- unboxed tuples; just a TyCon really, -- but convenient like this - deriving (Eq,Show) + deriving (Eq,Show, Ord) type TyVar = String type TyVarBinder = String View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1add43cb68ff6fe94067bcd7575996cb... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1add43cb68ff6fe94067bcd7575996cb... You're receiving this email because of your account on gitlab.haskell.org.