module Data.Array.Parallel.Prelude.Bool
( Bool(..)
, otherwise, (&&), (||), not, andP, orP
, fromBool, toBool
)
where
import Data.Array.Parallel.Prim ()
import Data.Array.Parallel.Prelude.Base
import Data.Array.Parallel.Lifted.Closure
import Data.Array.Parallel.PArray.PReprInstances
import Data.Array.Parallel.Lifted.Scalar
import qualified Data.Array.Parallel.Unlifted as U
import Data.Bits
(&&*) :: Bool :-> Bool :-> Bool
(&&*) = closure2 (&&) and_l
and_l :: PArray Bool -> PArray Bool -> PArray Bool
and_l (PArray n# bs) (PArray _ cs)
= PArray n# $
case bs of { PBool sel1 ->
case cs of { PBool sel2 ->
PBool $ U.tagsToSel2 (U.zipWith (.&.) (U.tagsSel2 sel1) (U.tagsSel2 sel2)) }}
(||*) :: Bool :-> Bool :-> Bool
(||*) = closure2 (||) or_l
or_l :: PArray Bool -> PArray Bool -> PArray Bool
or_l (PArray n# bs) (PArray _ cs)
= PArray n# $
case bs of { PBool sel1 ->
case cs of { PBool sel2 ->
PBool $ U.tagsToSel2 (U.zipWith (.|.) (U.tagsSel2 sel1) (U.tagsSel2 sel2)) }}
not_v :: Bool :-> Bool
not_v = closure1 not not_l
not_l :: PArray Bool -> PArray Bool
not_l (PArray n# bs)
= PArray n# $
case bs of { PBool sel ->
PBool $ U.tagsToSel2 (U.map complement (U.tagsSel2 sel)) }
andP:: PArr Bool -> Bool
andP _ = True
andP_v :: PArray Bool :-> Bool
andP_v = closure1 (scalar_fold (&&) True) (scalar_folds (&&) True)
orP:: PArr Bool -> Bool
orP _ = True
orP_v :: PArray Bool :-> Bool
orP_v = closure1 (scalar_fold (||) False) (scalar_folds (||) False)
fromBool :: Bool -> Int
fromBool False = 0
fromBool True = 1
toBool :: Int -> Bool
toBool 0 = False
toBool _ = True