# Changeset View

Changeset View

# Standalone View

Standalone View

# compiler/codeGen/StgCmmPrim.hs

Show First 20 Lines • Show All 883 Lines • ▼ Show 20 Line(s) | 883 | = case callishPrimOpSupported dflags op of | |||
---|---|---|---|---|---|

884 | Left op -> emit $ mkUnsafeCall (PrimTarget op) results args | 884 | Left op -> emit $ mkUnsafeCall (PrimTarget op) results args | ||

885 | Right gen -> gen results args | 885 | Right gen -> gen results args | ||

886 | 886 | | |||

887 | type GenericOp = [CmmFormal] -> [CmmActual] -> FCode () | 887 | type GenericOp = [CmmFormal] -> [CmmActual] -> FCode () | ||

888 | 888 | | |||

889 | callishPrimOpSupported :: DynFlags -> PrimOp -> Either CallishMachOp GenericOp | 889 | callishPrimOpSupported :: DynFlags -> PrimOp -> Either CallishMachOp GenericOp | ||

890 | callishPrimOpSupported dflags op | 890 | callishPrimOpSupported dflags op | ||

891 | = case op of | 891 | = case op of | ||

892 | IntQuotRemOp | ncg && (x86ish | 892 | IntQuotRemOp | ncg && (x86ish || ppc) -> | ||

893 | || ppc) -> Left (MO_S_QuotRem (wordWidth dflags)) | 893 | Left (MO_S_QuotRem (wordWidth dflags)) | ||

894 | | otherwise -> Right (genericIntQuotRemOp dflags) | 894 | | otherwise -> | ||

895 | Right (genericIntQuotRemOp (wordWidth dflags)) | ||||

simonmar: nit: please fix the long lines | |||||

895 | 896 | | |||

896 | WordQuotRemOp | ncg && (x86ish | 897 | Int8QuotRemOp | (ncg && x86ish) | ||

897 | || ppc) -> Left (MO_U_QuotRem (wordWidth dflags)) | 898 | || llvm -> Left (MO_S_QuotRem W8) | ||

898 | | otherwise -> Right (genericWordQuotRemOp dflags) | 899 | | otherwise -> Right (genericIntQuotRemOp W8) | ||

900 | | ||||

901 | WordQuotRemOp | ncg && (x86ish || ppc) -> | ||||

902 | Left (MO_U_QuotRem (wordWidth dflags)) | ||||

903 | | otherwise -> | ||||

904 | Right (genericWordQuotRemOp (wordWidth dflags)) | ||||

899 | 905 | | |||

900 | WordQuotRem2Op | (ncg && (x86ish | 906 | WordQuotRem2Op | (ncg && (x86ish | ||

901 | || ppc)) | 907 | || ppc)) | ||

902 | || llvm -> Left (MO_U_QuotRem2 (wordWidth dflags)) | 908 | || llvm -> Left (MO_U_QuotRem2 (wordWidth dflags)) | ||

903 | | otherwise -> Right (genericWordQuotRem2Op dflags) | 909 | | otherwise -> Right (genericWordQuotRem2Op dflags) | ||

904 | 910 | | |||

911 | Word8QuotRemOp | (ncg && x86ish) | ||||

912 | || llvm -> Left (MO_U_QuotRem W8) | ||||

913 | | otherwise -> Right (genericWordQuotRemOp W8) | ||||

914 | | ||||

905 | WordAdd2Op | (ncg && (x86ish | 915 | WordAdd2Op | (ncg && (x86ish | ||

906 | || ppc)) | 916 | || ppc)) | ||

907 | || llvm -> Left (MO_Add2 (wordWidth dflags)) | 917 | || llvm -> Left (MO_Add2 (wordWidth dflags)) | ||

908 | | otherwise -> Right genericWordAdd2Op | 918 | | otherwise -> Right genericWordAdd2Op | ||

909 | 919 | | |||

910 | WordAddCOp | (ncg && (x86ish | 920 | WordAddCOp | (ncg && (x86ish | ||

911 | || ppc)) | 921 | || ppc)) | ||

912 | || llvm -> Left (MO_AddWordC (wordWidth dflags)) | 922 | || llvm -> Left (MO_AddWordC (wordWidth dflags)) | ||

Show All 39 Lines | 961 | x86ish = case platformArch (targetPlatform dflags) of | |||

952 | ArchX86 -> True | 962 | ArchX86 -> True | ||

953 | ArchX86_64 -> True | 963 | ArchX86_64 -> True | ||

954 | _ -> False | 964 | _ -> False | ||

955 | ppc = case platformArch (targetPlatform dflags) of | 965 | ppc = case platformArch (targetPlatform dflags) of | ||

956 | ArchPPC -> True | 966 | ArchPPC -> True | ||

957 | ArchPPC_64 _ -> True | 967 | ArchPPC_64 _ -> True | ||

958 | _ -> False | 968 | _ -> False | ||

959 | 969 | | |||

960 | genericIntQuotRemOp :: DynFlags -> GenericOp | 970 | genericIntQuotRemOp :: Width -> GenericOp | ||

961 | genericIntQuotRemOp dflags [res_q, res_r] [arg_x, arg_y] | 971 | genericIntQuotRemOp width [res_q, res_r] [arg_x, arg_y] | ||

962 | = emit $ mkAssign (CmmLocal res_q) | 972 | = emit $ mkAssign (CmmLocal res_q) | ||

963 | (CmmMachOp (MO_S_Quot (wordWidth dflags)) [arg_x, arg_y]) <*> | 973 | (CmmMachOp (MO_S_Quot width) [arg_x, arg_y]) <*> | ||

964 | mkAssign (CmmLocal res_r) | 974 | mkAssign (CmmLocal res_r) | ||

965 | (CmmMachOp (MO_S_Rem (wordWidth dflags)) [arg_x, arg_y]) | 975 | (CmmMachOp (MO_S_Rem width) [arg_x, arg_y]) | ||

966 | genericIntQuotRemOp _ _ _ = panic "genericIntQuotRemOp" | 976 | genericIntQuotRemOp _ _ _ = panic "genericIntQuotRemOp" | ||

967 | 977 | | |||

968 | genericWordQuotRemOp :: DynFlags -> GenericOp | 978 | genericWordQuotRemOp :: Width -> GenericOp | ||

969 | genericWordQuotRemOp dflags [res_q, res_r] [arg_x, arg_y] | 979 | genericWordQuotRemOp width [res_q, res_r] [arg_x, arg_y] | ||

970 | = emit $ mkAssign (CmmLocal res_q) | 980 | = emit $ mkAssign (CmmLocal res_q) | ||

971 | (CmmMachOp (MO_U_Quot (wordWidth dflags)) [arg_x, arg_y]) <*> | 981 | (CmmMachOp (MO_U_Quot width) [arg_x, arg_y]) <*> | ||

972 | mkAssign (CmmLocal res_r) | 982 | mkAssign (CmmLocal res_r) | ||

973 | (CmmMachOp (MO_U_Rem (wordWidth dflags)) [arg_x, arg_y]) | 983 | (CmmMachOp (MO_U_Rem width) [arg_x, arg_y]) | ||

974 | genericWordQuotRemOp _ _ _ = panic "genericWordQuotRemOp" | 984 | genericWordQuotRemOp _ _ _ = panic "genericWordQuotRemOp" | ||

975 | 985 | | |||

976 | genericWordQuotRem2Op :: DynFlags -> GenericOp | 986 | genericWordQuotRem2Op :: DynFlags -> GenericOp | ||

977 | genericWordQuotRem2Op dflags [res_q, res_r] [arg_x_high, arg_x_low, arg_y] | 987 | genericWordQuotRem2Op dflags [res_q, res_r] [arg_x_high, arg_x_low, arg_y] | ||

978 | = emit =<< f (widthInBits (wordWidth dflags)) zero arg_x_high arg_x_low | 988 | = emit =<< f (widthInBits (wordWidth dflags)) zero arg_x_high arg_x_low | ||

979 | where ty = cmmExprType dflags arg_x_high | 989 | where ty = cmmExprType dflags arg_x_high | ||

980 | shl x i = CmmMachOp (MO_Shl (wordWidth dflags)) [x, i] | 990 | shl x i = CmmMachOp (MO_Shl (wordWidth dflags)) [x, i] | ||

981 | shr x i = CmmMachOp (MO_U_Shr (wordWidth dflags)) [x, i] | 991 | shr x i = CmmMachOp (MO_U_Shr (wordWidth dflags)) [x, i] | ||

▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Line(s) | |||||

1319 | translateOp dflags WordQuotOp = Just (mo_wordUQuot dflags) | 1329 | translateOp dflags WordQuotOp = Just (mo_wordUQuot dflags) | ||

1320 | translateOp dflags WordRemOp = Just (mo_wordURem dflags) | 1330 | translateOp dflags WordRemOp = Just (mo_wordURem dflags) | ||

1321 | 1331 | | |||

1322 | translateOp dflags AddrGeOp = Just (mo_wordUGe dflags) | 1332 | translateOp dflags AddrGeOp = Just (mo_wordUGe dflags) | ||

1323 | translateOp dflags AddrLeOp = Just (mo_wordULe dflags) | 1333 | translateOp dflags AddrLeOp = Just (mo_wordULe dflags) | ||

1324 | translateOp dflags AddrGtOp = Just (mo_wordUGt dflags) | 1334 | translateOp dflags AddrGtOp = Just (mo_wordUGt dflags) | ||

1325 | translateOp dflags AddrLtOp = Just (mo_wordULt dflags) | 1335 | translateOp dflags AddrLtOp = Just (mo_wordULt dflags) | ||

1326 | 1336 | | |||

1337 | -- Int8# signed ops | ||||

1338 | | ||||

1339 | translateOp dflags Int8Extend = Just (MO_SS_Conv W8 (wordWidth dflags)) | ||||

1340 | translateOp dflags Int8Narrow = Just (MO_SS_Conv (wordWidth dflags) W8) | ||||

1341 | translateOp _ Int8NegOp = Just (MO_S_Neg W8) | ||||

1342 | translateOp _ Int8AddOp = Just (MO_Add W8) | ||||

1343 | translateOp _ Int8SubOp = Just (MO_Sub W8) | ||||

1344 | translateOp _ Int8MulOp = Just (MO_Mul W8) | ||||

1345 | translateOp _ Int8QuotOp = Just (MO_S_Quot W8) | ||||

1346 | translateOp _ Int8RemOp = Just (MO_S_Rem W8) | ||||

1347 | | ||||

1348 | translateOp _ Int8EqOp = Just (MO_Eq W8) | ||||

1349 | translateOp _ Int8GeOp = Just (MO_S_Ge W8) | ||||

1350 | translateOp _ Int8GtOp = Just (MO_S_Gt W8) | ||||

1351 | translateOp _ Int8LeOp = Just (MO_S_Le W8) | ||||

1352 | translateOp _ Int8LtOp = Just (MO_S_Lt W8) | ||||

1353 | translateOp _ Int8NeOp = Just (MO_Ne W8) | ||||

1354 | | ||||

1355 | -- Word8# unsigned ops | ||||

1356 | | ||||

1357 | translateOp dflags Word8Extend = Just (MO_UU_Conv W8 (wordWidth dflags)) | ||||

1358 | translateOp dflags Word8Narrow = Just (MO_UU_Conv (wordWidth dflags) W8) | ||||

1359 | translateOp _ Word8NotOp = Just (MO_Not W8) | ||||

1360 | translateOp _ Word8AddOp = Just (MO_Add W8) | ||||

1361 | translateOp _ Word8SubOp = Just (MO_Sub W8) | ||||

1362 | translateOp _ Word8MulOp = Just (MO_Mul W8) | ||||

1363 | translateOp _ Word8QuotOp = Just (MO_U_Quot W8) | ||||

1364 | translateOp _ Word8RemOp = Just (MO_U_Rem W8) | ||||

1365 | | ||||

1366 | translateOp _ Word8EqOp = Just (MO_Eq W8) | ||||

1367 | translateOp _ Word8GeOp = Just (MO_U_Ge W8) | ||||

1368 | translateOp _ Word8GtOp = Just (MO_U_Gt W8) | ||||

1369 | translateOp _ Word8LeOp = Just (MO_U_Le W8) | ||||

1370 | translateOp _ Word8LtOp = Just (MO_U_Lt W8) | ||||

1371 | translateOp _ Word8NeOp = Just (MO_Ne W8) | ||||

1372 | | ||||

1327 | -- Char# ops | 1373 | -- Char# ops | ||

1328 | 1374 | | |||

1329 | translateOp dflags CharEqOp = Just (MO_Eq (wordWidth dflags)) | 1375 | translateOp dflags CharEqOp = Just (MO_Eq (wordWidth dflags)) | ||

1330 | translateOp dflags CharNeOp = Just (MO_Ne (wordWidth dflags)) | 1376 | translateOp dflags CharNeOp = Just (MO_Ne (wordWidth dflags)) | ||

1331 | translateOp dflags CharGeOp = Just (MO_U_Ge (wordWidth dflags)) | 1377 | translateOp dflags CharGeOp = Just (MO_U_Ge (wordWidth dflags)) | ||

1332 | translateOp dflags CharLeOp = Just (MO_U_Le (wordWidth dflags)) | 1378 | translateOp dflags CharLeOp = Just (MO_U_Le (wordWidth dflags)) | ||

1333 | translateOp dflags CharGtOp = Just (MO_U_Gt (wordWidth dflags)) | 1379 | translateOp dflags CharGtOp = Just (MO_U_Gt (wordWidth dflags)) | ||

1334 | translateOp dflags CharLtOp = Just (MO_U_Lt (wordWidth dflags)) | 1380 | translateOp dflags CharLtOp = Just (MO_U_Lt (wordWidth dflags)) | ||

▲ Show 20 Lines • Show All 1126 Lines • Show Last 20 Lines |

nit: please fix the long lines