summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-07-19 04:06:33 +0000
committerAndreas Klebinger <klebinger.andreas@gmx.at>2021-09-07 15:29:23 +0000
commit3a66747e1a6049ef8bd2285ccc53663db5de2cb8 (patch)
treea58b46d4bde5218e7b9d256fb4a88af16517d65a
parent2735f5a6103eb99e44776da0f5b9d35a18279cbc (diff)
downloadhaskell-wip/llvm-big-prim.tar.gz
Let LLVM and C handle > native size arithmeticwip/llvm-big-prim
NCG needs to call slow FFI functions where we "borrow" the C compiler's implementation, but there is no reason why we need to do that for LLVM, or the unregisterized backend where everything is via C anyways!
-rw-r--r--compiler/GHC/CmmToC.hs65
-rw-r--r--compiler/GHC/CmmToLlvm/CodeGen.hs60
-rw-r--r--compiler/GHC/StgToCmm/Prim.hs2
3 files changed, 67 insertions, 60 deletions
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs
index 3008f01c5c..e259cdb55d 100644
--- a/compiler/GHC/CmmToC.hs
+++ b/compiler/GHC/CmmToC.hs
@@ -860,40 +860,43 @@ pprCallishMachOp_for_C mop
MO_SubIntC {} -> unsupported
MO_U_Mul2 {} -> unsupported
MO_Touch -> unsupported
+ -- we could support prefetch via "__builtin_prefetch"
+ -- Not adding it for now
(MO_Prefetch_Data _ ) -> unsupported
- --- we could support prefetch via "__builtin_prefetch"
- --- Not adding it for now
- MO_I64_ToI -> text "hs_int64ToInt"
- MO_I64_FromI -> text "hs_intToInt64"
- MO_W64_ToW -> text "hs_word64ToWord"
- MO_W64_FromW -> text "hs_wordToWord64"
- MO_x64_Neg -> text "hs_neg64"
- MO_x64_Add -> text "hs_add64"
- MO_x64_Sub -> text "hs_sub64"
- MO_x64_Mul -> text "hs_mul64"
- MO_I64_Quot -> text "hs_quotInt64"
- MO_I64_Rem -> text "hs_remInt64"
- MO_W64_Quot -> text "hs_quotWord64"
- MO_W64_Rem -> text "hs_remWord64"
- MO_x64_And -> text "hs_and64"
- MO_x64_Or -> text "hs_xor64"
- MO_x64_Xor -> text "hs_xor64"
- MO_x64_Not -> text "hs_not64"
- MO_x64_Shl -> text "hs_uncheckedShiftL64"
- MO_I64_Shr -> text "hs_uncheckedIShiftRA64"
- MO_W64_Shr -> text "hs_uncheckedShiftRL64"
- MO_x64_Eq -> text "hs_eq64"
- MO_x64_Ne -> text "hs_ne64"
- MO_I64_Ge -> text "hs_geInt64"
- MO_I64_Gt -> text "hs_gtInt64"
- MO_I64_Le -> text "hs_leInt64"
- MO_I64_Lt -> text "hs_ltInt64"
- MO_W64_Ge -> text "hs_geWord64"
- MO_W64_Gt -> text "hs_gtWord64"
- MO_W64_Le -> text "hs_leWord64"
- MO_W64_Lt -> text "hs_ltWord64"
+
+ MO_I64_ToI -> dontReach64
+ MO_I64_FromI -> dontReach64
+ MO_W64_ToW -> dontReach64
+ MO_W64_FromW -> dontReach64
+ MO_x64_Neg -> dontReach64
+ MO_x64_Add -> dontReach64
+ MO_x64_Sub -> dontReach64
+ MO_x64_Mul -> dontReach64
+ MO_I64_Quot -> dontReach64
+ MO_I64_Rem -> dontReach64
+ MO_W64_Quot -> dontReach64
+ MO_W64_Rem -> dontReach64
+ MO_x64_And -> dontReach64
+ MO_x64_Or -> dontReach64
+ MO_x64_Xor -> dontReach64
+ MO_x64_Not -> dontReach64
+ MO_x64_Shl -> dontReach64
+ MO_I64_Shr -> dontReach64
+ MO_W64_Shr -> dontReach64
+ MO_x64_Eq -> dontReach64
+ MO_x64_Ne -> dontReach64
+ MO_I64_Ge -> dontReach64
+ MO_I64_Gt -> dontReach64
+ MO_I64_Le -> dontReach64
+ MO_I64_Lt -> dontReach64
+ MO_W64_Ge -> dontReach64
+ MO_W64_Gt -> dontReach64
+ MO_W64_Le -> dontReach64
+ MO_W64_Lt -> dontReach64
where unsupported = panic ("pprCallishMachOp_for_C: " ++ show mop
++ " not supported!")
+ dontReach64 = panic ("pprCallishMachOp_for_C: " ++ show mop
+ ++ " should be not be encountered because the regular primop for this 64-bit operation is used instead.")
-- ---------------------------------------------------------------------
-- Useful #defines
diff --git a/compiler/GHC/CmmToLlvm/CodeGen.hs b/compiler/GHC/CmmToLlvm/CodeGen.hs
index dd2779ef71..b10b26d416 100644
--- a/compiler/GHC/CmmToLlvm/CodeGen.hs
+++ b/compiler/GHC/CmmToLlvm/CodeGen.hs
@@ -807,6 +807,8 @@ cmmPrimOpFunctions mop = do
intrinTy2 = "p0i8." ++ showSDoc dflags (ppr $ llvmWord platform)
unsupported = panic ("cmmPrimOpFunctions: " ++ show mop
++ " not supported here")
+ dontReach64 = panic ("cmmPrimOpFunctions: " ++ show mop
+ ++ " should be not be encountered because the regular primop for this 64-bit operation is used instead.")
return $ case mop of
MO_F32_Exp -> fsLit "expf"
@@ -911,35 +913,35 @@ cmmPrimOpFunctions mop = do
MO_Cmpxchg _ -> unsupported
MO_Xchg _ -> unsupported
- MO_I64_ToI -> fsLit "hs_int64ToInt"
- MO_I64_FromI -> fsLit "hs_intToInt64"
- MO_W64_ToW -> fsLit "hs_word64ToWord"
- MO_W64_FromW -> fsLit "hs_wordToWord64"
- MO_x64_Neg -> fsLit "hs_neg64"
- MO_x64_Add -> fsLit "hs_add64"
- MO_x64_Sub -> fsLit "hs_sub64"
- MO_x64_Mul -> fsLit "hs_mul64"
- MO_I64_Quot -> fsLit "hs_quotInt64"
- MO_I64_Rem -> fsLit "hs_remInt64"
- MO_W64_Quot -> fsLit "hs_quotWord64"
- MO_W64_Rem -> fsLit "hs_remWord64"
- MO_x64_And -> fsLit "hs_and64"
- MO_x64_Or -> fsLit "hs_or64"
- MO_x64_Xor -> fsLit "hs_xor64"
- MO_x64_Not -> fsLit "hs_not64"
- MO_x64_Shl -> fsLit "hs_uncheckedShiftL64"
- MO_I64_Shr -> fsLit "hs_uncheckedIShiftRA64"
- MO_W64_Shr -> fsLit "hs_uncheckedShiftRL64"
- MO_x64_Eq -> fsLit "hs_eq64"
- MO_x64_Ne -> fsLit "hs_ne64"
- MO_I64_Ge -> fsLit "hs_geInt64"
- MO_I64_Gt -> fsLit "hs_gtInt64"
- MO_I64_Le -> fsLit "hs_leInt64"
- MO_I64_Lt -> fsLit "hs_ltInt64"
- MO_W64_Ge -> fsLit "hs_geWord64"
- MO_W64_Gt -> fsLit "hs_gtWord64"
- MO_W64_Le -> fsLit "hs_leWord64"
- MO_W64_Lt -> fsLit "hs_ltWord64"
+ MO_I64_ToI -> dontReach64
+ MO_I64_FromI -> dontReach64
+ MO_W64_ToW -> dontReach64
+ MO_W64_FromW -> dontReach64
+ MO_x64_Neg -> dontReach64
+ MO_x64_Add -> dontReach64
+ MO_x64_Sub -> dontReach64
+ MO_x64_Mul -> dontReach64
+ MO_I64_Quot -> dontReach64
+ MO_I64_Rem -> dontReach64
+ MO_W64_Quot -> dontReach64
+ MO_W64_Rem -> dontReach64
+ MO_x64_And -> dontReach64
+ MO_x64_Or -> dontReach64
+ MO_x64_Xor -> dontReach64
+ MO_x64_Not -> dontReach64
+ MO_x64_Shl -> dontReach64
+ MO_I64_Shr -> dontReach64
+ MO_W64_Shr -> dontReach64
+ MO_x64_Eq -> dontReach64
+ MO_x64_Ne -> dontReach64
+ MO_I64_Ge -> dontReach64
+ MO_I64_Gt -> dontReach64
+ MO_I64_Le -> dontReach64
+ MO_I64_Lt -> dontReach64
+ MO_W64_Ge -> dontReach64
+ MO_W64_Gt -> dontReach64
+ MO_W64_Le -> dontReach64
+ MO_W64_Lt -> dontReach64
-- | Tail function calls
diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs
index ab1ac89576..dff86341b1 100644
--- a/compiler/GHC/StgToCmm/Prim.hs
+++ b/compiler/GHC/StgToCmm/Prim.hs
@@ -1707,6 +1707,8 @@ emitPrimOp dflags primop = case primop of
-> PrimopCmmEmit
opTranslate64 args mkMop callish =
case platformWordSize platform of
+ -- LLVM and C `can handle larger than native size arithmetic natively.
+ _ | not ncg -> opTranslate args $ mkMop W64
PW4 -> opCallish args callish
PW8 -> opTranslate args $ mkMop W64