X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Futils%2FFastBool.lhs;h=32cb7aef3a58be310db943ed242fd87e74569f66;hp=d7776e4259eac959ed71c09898cd9d507b0576a7;hb=c5b178be60a5a44abd2f4ddf8c399857678326e2;hpb=983c316af4654b6532909a0e85dec175e808401a diff --git a/compiler/utils/FastBool.lhs b/compiler/utils/FastBool.lhs index d7776e4..32cb7ae 100644 --- a/compiler/utils/FastBool.lhs +++ b/compiler/utils/FastBool.lhs @@ -5,6 +5,7 @@ \begin{code} module FastBool ( + --fastBool could be called bBox; isFastTrue, bUnbox; but they're not FastBool, fastBool, isFastTrue, fastOr, fastAnd ) where @@ -12,25 +13,57 @@ module FastBool ( -- Import the beggars import GHC.Exts - ( Int(..), Int#, (+#), (-#), (*#), - quotInt#, negateInt#, (==#), (<#), (<=#), (>=#), (>#) - ) +#ifdef DEBUG import Panic +#endif type FastBool = Int# fastBool True = 1# fastBool False = 0# -isFastTrue x = x ==# 1# + +#ifdef DEBUG +--then waste time deciding whether to panic. FastBool should normally +--be at least as fast as Bool, one would hope... + +isFastTrue 1# = True +isFastTrue 0# = False +isFastTrue _ = panic "FastTypes: isFastTrue" -- note that fastOr and fastAnd are strict in both arguments -- since they are unboxed fastOr 1# _ = 1# fastOr 0# x = x -fastOr _ _ = panic# "FastTypes: fastOr" +fastOr _ _ = panicFastInt "FastTypes: fastOr" fastAnd 0# _ = 0# fastAnd 1# x = x -fastAnd _ _ = panic# "FastTypes: fastAnd" +fastAnd _ _ = panicFastInt "FastTypes: fastAnd" + +--these "panicFastInt"s (formerly known as "panic#") rely on +--FastInt = FastBool ( = Int# presumably), +--haha, true enough when __GLASGOW_HASKELL__. Why can't we have functions +--that return _|_ be kind-polymorphic ( ?? to be precise ) ? + +#else /* ! DEBUG */ +--Isn't comparison to zero sometimes faster on CPUs than comparison to 1? +-- (since using Int# as _synonym_ fails to guarantee that it will +-- only take on values of 0 and 1) +isFastTrue 0# = False +isFastTrue _ = True + +-- note that fastOr and fastAnd are strict in both arguments +-- since they are unboxed +-- Also, to avoid incomplete-pattern warning +-- (and avoid wasting time with redundant runtime checks), +-- we don't pattern-match on both 0# and 1# . +fastOr 0# x = x +fastOr _ _ = 1# + +fastAnd 0# _ = 0# +fastAnd _ x = x + +#endif /* ! DEBUG */ + #else /* ! __GLASGOW_HASKELL__ */