{-# LANGUAGE MagicHash #-}
module Data.Array.Repa.Eval.Cursored
( fillBlock2P
, fillCursoredBlock2P
, fillCursoredBlock2S )
where
import Data.Array.Repa.Index
import Data.Array.Repa.Shape
import Data.Array.Repa.Eval.Elt
import Data.Array.Repa.Eval.Gang
import GHC.Base
fillBlock2P
:: Elt a
=> (Int -> a -> IO ())
-> (DIM2 -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
{-# INLINE [0] fillBlock2P #-}
fillBlock2P :: (Int -> a -> IO ())
-> (DIM2 -> a) -> Int# -> Int# -> Int# -> Int# -> Int# -> IO ()
fillBlock2P Int -> a -> IO ()
write DIM2 -> a
getElem !Int#
imageWidth !Int#
x0 !Int#
y0 !Int#
w0 Int#
h0
= (Int -> a -> IO ())
-> (DIM2 -> DIM2)
-> (DIM2 -> DIM2 -> DIM2)
-> (DIM2 -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
forall a cursor.
Elt a =>
(Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
fillCursoredBlock2P
Int -> a -> IO ()
write DIM2 -> DIM2
forall a. a -> a
id DIM2 -> DIM2 -> DIM2
forall sh. Shape sh => sh -> sh -> sh
addDim DIM2 -> a
getElem
Int#
imageWidth Int#
x0 Int#
y0 Int#
w0 Int#
h0
fillCursoredBlock2P
:: Elt a
=> (Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
{-# INLINE [0] fillCursoredBlock2P #-}
fillCursoredBlock2P :: (Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
fillCursoredBlock2P
Int -> a -> IO ()
write
DIM2 -> cursor
makeCursorFCB DIM2 -> cursor -> cursor
shiftCursorFCB cursor -> a
getElemFCB
!Int#
imageWidth !Int#
x0 !Int#
y0 !Int#
w0 !Int#
h0
= Gang -> (Int -> IO ()) -> IO ()
gangIO Gang
theGang Int -> IO ()
fillBlock
where
!(I# Int#
threads) = Gang -> Int
gangSize Gang
theGang
!colChunkLen :: Int#
colChunkLen = Int#
w0 Int# -> Int# -> Int#
`quotInt#` Int#
threads
!colChunkSlack :: Int#
colChunkSlack = Int#
w0 Int# -> Int# -> Int#
`remInt#` Int#
threads
{-# INLINE colIx #-}
colIx :: Int# -> Int#
colIx !Int#
ix
| Int#
1# <- Int#
ix Int# -> Int# -> Int#
<# Int#
colChunkSlack = Int#
x0 Int# -> Int# -> Int#
+# (Int#
ix Int# -> Int# -> Int#
*# (Int#
colChunkLen Int# -> Int# -> Int#
+# Int#
1#))
| Bool
otherwise = Int#
x0 Int# -> Int# -> Int#
+# (Int#
ix Int# -> Int# -> Int#
*# Int#
colChunkLen) Int# -> Int# -> Int#
+# Int#
colChunkSlack
{-# INLINE fillBlock #-}
fillBlock :: Int -> IO ()
fillBlock :: Int -> IO ()
fillBlock !(I# Int#
ix)
= let !x0' :: Int#
x0' = Int# -> Int#
colIx Int#
ix
!w0' :: Int#
w0' = Int# -> Int#
colIx (Int#
ix Int# -> Int# -> Int#
+# Int#
1#) Int# -> Int# -> Int#
-# Int#
x0'
!y0' :: Int#
y0' = Int#
y0
!h0' :: Int#
h0' = Int#
h0
in (Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
forall a cursor.
Elt a =>
(Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
fillCursoredBlock2S
Int -> a -> IO ()
write
DIM2 -> cursor
makeCursorFCB DIM2 -> cursor -> cursor
shiftCursorFCB cursor -> a
getElemFCB
Int#
imageWidth Int#
x0' Int#
y0' Int#
w0' Int#
h0'
fillCursoredBlock2S
:: Elt a
=> (Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
{-# INLINE [0] fillCursoredBlock2S #-}
fillCursoredBlock2S :: (Int -> a -> IO ())
-> (DIM2 -> cursor)
-> (DIM2 -> cursor -> cursor)
-> (cursor -> a)
-> Int#
-> Int#
-> Int#
-> Int#
-> Int#
-> IO ()
fillCursoredBlock2S
Int -> a -> IO ()
write
DIM2 -> cursor
makeCursor DIM2 -> cursor -> cursor
shiftCursor cursor -> a
getElem
!Int#
imageWidth !Int#
x0 !Int#
y0 !Int#
w0 Int#
h0
= do Int# -> IO ()
fillBlock Int#
y0
where !x1 :: Int#
x1 = Int#
x0 Int# -> Int# -> Int#
+# Int#
w0
!y1 :: Int#
y1 = Int#
y0 Int# -> Int# -> Int#
+# Int#
h0
{-# INLINE fillBlock #-}
fillBlock :: Int# -> IO ()
fillBlock !Int#
y
| Int#
1# <- Int#
y Int# -> Int# -> Int#
>=# Int#
y1 = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do Int# -> IO ()
fillLine4 Int#
x0
Int# -> IO ()
fillBlock (Int#
y Int# -> Int# -> Int#
+# Int#
1#)
where {-# INLINE fillLine4 #-}
fillLine4 :: Int# -> IO ()
fillLine4 !Int#
x
| Int#
1# <- Int#
x Int# -> Int# -> Int#
+# Int#
4# Int# -> Int# -> Int#
>=# Int#
x1 = Int# -> IO ()
fillLine1 Int#
x
| Bool
otherwise
= do
let srcCur0 :: cursor
srcCur0 = DIM2 -> cursor
makeCursor (Z
Z Z -> Int -> Z :. Int
forall tail head. tail -> head -> tail :. head
:. (Int# -> Int
I# Int#
y) (Z :. Int) -> Int -> DIM2
forall tail head. tail -> head -> tail :. head
:. (Int# -> Int
I# Int#
x))
let srcCur1 :: cursor
srcCur1 = DIM2 -> cursor -> cursor
shiftCursor (Z
Z Z -> Int -> Z :. Int
forall tail head. tail -> head -> tail :. head
:. Int
0 (Z :. Int) -> Int -> DIM2
forall tail head. tail -> head -> tail :. head
:. Int
1) cursor
srcCur0
let srcCur2 :: cursor
srcCur2 = DIM2 -> cursor -> cursor
shiftCursor (Z
Z Z -> Int -> Z :. Int
forall tail head. tail -> head -> tail :. head
:. Int
0 (Z :. Int) -> Int -> DIM2
forall tail head. tail -> head -> tail :. head
:. Int
1) cursor
srcCur1
let srcCur3 :: cursor
srcCur3 = DIM2 -> cursor -> cursor
shiftCursor (Z
Z Z -> Int -> Z :. Int
forall tail head. tail -> head -> tail :. head
:. Int
0 (Z :. Int) -> Int -> DIM2
forall tail head. tail -> head -> tail :. head
:. Int
1) cursor
srcCur2
let val0 :: a
val0 = cursor -> a
getElem cursor
srcCur0
let val1 :: a
val1 = cursor -> a
getElem cursor
srcCur1
let val2 :: a
val2 = cursor -> a
getElem cursor
srcCur2
let val3 :: a
val3 = cursor -> a
getElem cursor
srcCur3
a -> IO ()
forall a. Elt a => a -> IO ()
touch a
val0
a -> IO ()
forall a. Elt a => a -> IO ()
touch a
val1
a -> IO ()
forall a. Elt a => a -> IO ()
touch a
val2
a -> IO ()
forall a. Elt a => a -> IO ()
touch a
val3
let !dstCur0 :: Int#
dstCur0 = Int#
x Int# -> Int# -> Int#
+# (Int#
y Int# -> Int# -> Int#
*# Int#
imageWidth)
Int -> a -> IO ()
write (Int# -> Int
I# Int#
dstCur0) a
val0
Int -> a -> IO ()
write (Int# -> Int
I# (Int#
dstCur0 Int# -> Int# -> Int#
+# Int#
1#)) a
val1
Int -> a -> IO ()
write (Int# -> Int
I# (Int#
dstCur0 Int# -> Int# -> Int#
+# Int#
2#)) a
val2
Int -> a -> IO ()
write (Int# -> Int
I# (Int#
dstCur0 Int# -> Int# -> Int#
+# Int#
3#)) a
val3
Int# -> IO ()
fillLine4 (Int#
x Int# -> Int# -> Int#
+# Int#
4#)
{-# INLINE fillLine1 #-}
fillLine1 :: Int# -> IO ()
fillLine1 !Int#
x
| Int#
1# <- Int#
x Int# -> Int# -> Int#
>=# Int#
x1 = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do let val0 :: a
val0 = (cursor -> a
getElem (cursor -> a) -> cursor -> a
forall a b. (a -> b) -> a -> b
$ DIM2 -> cursor
makeCursor (Z
Z Z -> Int -> Z :. Int
forall tail head. tail -> head -> tail :. head
:. (Int# -> Int
I# Int#
y) (Z :. Int) -> Int -> DIM2
forall tail head. tail -> head -> tail :. head
:. (Int# -> Int
I# Int#
x)))
Int -> a -> IO ()
write (Int# -> Int
I# (Int#
x Int# -> Int# -> Int#
+# (Int#
y Int# -> Int# -> Int#
*# Int#
imageWidth))) a
val0
Int# -> IO ()
fillLine1 (Int#
x Int# -> Int# -> Int#
+# Int#
1#)