Commit bab8dc79 authored by tibbe's avatar tibbe

Add preprocessor defines when SSE is enabled

This will add the following preprocessor defines when Haskell source
files are compiled:

 * __SSE__ - If any version of SSE is enabled
 * __SSE2__ - If SSE2 or greater is enabled
 * __SSE4_2_ - If SSE4.2 is enabled

Note that SSE2 is enabled by default on x86-64.
parent ccd8c6f0
......@@ -1962,12 +1962,20 @@ doCpp dflags raw include_cc_opts input_fn output_fn = do
-- remember, in code we *compile*, the HOST is the same our TARGET,
-- and BUILD is the same as our HOST.
let sse2 = isSse2Enabled dflags
sse4_2 = isSse4_2Enabled dflags
sse_defs =
[ "-D__SSE__=1" | sse2 || sse4_2 ] ++
[ "-D__SSE2__=1" | sse2 || sse4_2 ] ++
[ "-D__SSE4_2__=1" | sse4_2 ]
cpp_prog ( map SysTools.Option verbFlags
++ map SysTools.Option include_paths
++ map SysTools.Option hsSourceCppOpts
++ map SysTools.Option target_defs
++ map SysTools.Option hscpp_opts
++ map SysTools.Option cc_opts
++ map SysTools.Option sse_defs
++ [ SysTools.Option "-x"
, SysTools.Option "c"
, SysTools.Option input_fn
......
......@@ -118,6 +118,10 @@ module DynFlags (
tAG_MASK,
mAX_PTR_TAG,
tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
-- * SSE
isSse2Enabled,
isSse4_2Enabled,
) where
#include "HsVersions.h"
......@@ -2153,6 +2157,11 @@ dynamic_flags = [
, Flag "monly-4-regs" (NoArg (addWarn "The -monly-4-regs flag does nothing; it will be removed in a future GHC release"))
, Flag "msse2" (NoArg (setGeneralFlag Opt_SSE2))
, Flag "msse4.2" (NoArg (setGeneralFlag Opt_SSE4_2))
-- at some point we should probably have a single SSE flag that
-- contains the SSE version, instead of having a different flag
-- per version. That would make it easier to e.g. check if SSE2 is
-- enabled as you wouldn't have to check if either Opt_SSE2 or
-- Opt_SSE4_2 is set (as the latter implies the former).
------ Warning opts -------------------------------------------------
, Flag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
......@@ -3371,3 +3380,21 @@ makeDynFlagsConsistent dflags
arch = platformArch platform
os = platformOS platform
-- -----------------------------------------------------------------------------
-- SSE
isSse2Enabled :: DynFlags -> Bool
isSse2Enabled dflags = isSse4_2Enabled dflags || isSse2Enabled'
where
isSse2Enabled' = case platformArch (targetPlatform dflags) of
ArchX86_64 -> -- SSE2 is fixed on for x86_64. It would be
-- possible to make it optional, but we'd need to
-- fix at least the foreign call code where the
-- calling convention specifies the use of xmm regs,
-- and possibly other places.
True
ArchX86 -> gopt Opt_SSE2 dflags
_ -> False
isSse4_2Enabled :: DynFlags -> Bool
isSse4_2Enabled dflags = gopt Opt_SSE4_2 dflags
......@@ -71,20 +71,12 @@ is32BitPlatform = do
sse2Enabled :: NatM Bool
sse2Enabled = do
dflags <- getDynFlags
case platformArch (targetPlatform dflags) of
ArchX86_64 -> -- SSE2 is fixed on for x86_64. It would be
-- possible to make it optional, but we'd need to
-- fix at least the foreign call code where the
-- calling convention specifies the use of xmm regs,
-- and possibly other places.
return True
ArchX86 -> return (gopt Opt_SSE2 dflags || gopt Opt_SSE4_2 dflags)
_ -> panic "sse2Enabled: Not an X86* arch"
return (isSse2Enabled dflags)
sse4_2Enabled :: NatM Bool
sse4_2Enabled = do
dflags <- getDynFlags
return (gopt Opt_SSE4_2 dflags)
return (isSse4_2Enabled dflags)
if_sse2 :: NatM a -> NatM a -> NatM a
if_sse2 sse2 x87 = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment