Adapted to simplified VECTORISE pragmas
[packages/dph.git] / dph-lifted-copy / Data / Array / Parallel / Prelude / Bool.hs
1 {-# OPTIONS_GHC -fvectorise #-}
2
3 module Data.Array.Parallel.Prelude.Bool
4 ( Bool(..)
5
6 , otherwise, (&&), (||), not, andP, orP
7 , fromBool, toBool
8 )
9 where
10
11 import Data.Array.Parallel.Prim () -- dependency required by the vectoriser
12
13 import Data.Array.Parallel.Prelude.Base
14
15 import Data.Array.Parallel.Lifted.Closure
16 import Data.Array.Parallel.PArray.PReprInstances
17 import Data.Array.Parallel.Lifted.Scalar
18 import qualified Data.Array.Parallel.Unlifted as U
19
20 import Data.Bits
21
22
23 -- We re-export 'Prelude.otherwise' as is as it is special-cased in the Desugarer
24
25 {-# VECTORISE (&&) = (&&*) #-}
26 (&&*) :: Bool :-> Bool :-> Bool
27 {-# INLINE (&&*) #-}
28 (&&*) = closure2 (&&) and_l
29 {-# NOVECTORISE (&&*) #-}
30
31 and_l :: PArray Bool -> PArray Bool -> PArray Bool
32 {-# INLINE and_l #-}
33 and_l (PArray n# bs) (PArray _ cs)
34 = PArray n# $
35 case bs of { PBool sel1 ->
36 case cs of { PBool sel2 ->
37 PBool $ U.tagsToSel2 (U.zipWith (.&.) (U.tagsSel2 sel1) (U.tagsSel2 sel2)) }}
38 {-# NOVECTORISE and_l #-}
39
40 {-# VECTORISE (||) = (||*) #-}
41 (||*) :: Bool :-> Bool :-> Bool
42 {-# INLINE (||*) #-}
43 (||*) = closure2 (||) or_l
44 {-# NOVECTORISE (||*) #-}
45
46 or_l :: PArray Bool -> PArray Bool -> PArray Bool
47 {-# INLINE or_l #-}
48 or_l (PArray n# bs) (PArray _ cs)
49 = PArray n# $
50 case bs of { PBool sel1 ->
51 case cs of { PBool sel2 ->
52 PBool $ U.tagsToSel2 (U.zipWith (.|.) (U.tagsSel2 sel1) (U.tagsSel2 sel2)) }}
53 {-# NOVECTORISE or_l #-}
54
55 {-# VECTORISE not = not_v #-}
56 not_v :: Bool :-> Bool
57 {-# INLINE not_v #-}
58 not_v = closure1 not not_l
59 {-# NOVECTORISE not_v #-}
60
61 not_l :: PArray Bool -> PArray Bool
62 {-# INLINE not_l #-}
63 not_l (PArray n# bs)
64 = PArray n# $
65 case bs of { PBool sel ->
66 PBool $ U.tagsToSel2 (U.map complement (U.tagsSel2 sel)) }
67 {-# NOVECTORISE not_l #-}
68
69 andP:: PArr Bool -> Bool
70 {-# NOINLINE andP #-}
71 andP _ = True
72 {-# VECTORISE andP = andP_v #-}
73 andP_v :: PArray Bool :-> Bool
74 {-# INLINE andP_v #-}
75 andP_v = closure1 (scalar_fold (&&) True) (scalar_folds (&&) True)
76 {-# NOVECTORISE andP_v #-}
77
78 orP:: PArr Bool -> Bool
79 {-# NOINLINE orP #-}
80 orP _ = True
81 {-# VECTORISE orP = orP_v #-}
82 orP_v :: PArray Bool :-> Bool
83 {-# INLINE orP_v #-}
84 orP_v = closure1 (scalar_fold (||) False) (scalar_folds (||) False)
85 {-# NOVECTORISE orP_v #-}
86
87 fromBool :: Bool -> Int
88 fromBool False = 0
89 fromBool True = 1
90
91 toBool :: Int -> Bool
92 toBool 0 = False
93 toBool _ = True