{-# LANGUAGE MagicHash #-}
module Data.Array.Repa.Eval.Interleaved
( fillInterleavedP)
where
import Data.Array.Repa.Eval.Gang
import GHC.Exts
import Prelude as P
fillInterleavedP
:: Int
-> (Int -> a -> IO ())
-> (Int -> a)
-> IO ()
{-# INLINE [0] fillInterleavedP #-}
fillInterleavedP :: Int -> (Int -> a -> IO ()) -> (Int -> a) -> IO ()
fillInterleavedP !(I# Int#
len) Int -> a -> IO ()
write Int -> a
getElem
= Gang -> (Int -> IO ()) -> IO ()
gangIO Gang
theGang
((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \(I# Int#
thread) ->
let !step :: Int#
step = Int#
threads
!start :: Int#
start = Int#
thread
!count :: Int#
count = Int# -> Int#
elemsForThread Int#
thread
in Int# -> Int# -> Int# -> IO ()
fill Int#
step Int#
start Int#
count
where
!(I# Int#
threads) = Gang -> Int
gangSize Gang
theGang
!chunkLenBase :: Int#
chunkLenBase = Int#
len Int# -> Int# -> Int#
`quotInt#` Int#
threads
!chunkLenSlack :: Int#
chunkLenSlack = Int#
len Int# -> Int# -> Int#
`remInt#` Int#
threads
elemsForThread :: Int# -> Int#
elemsForThread Int#
thread
| Int#
1# <- Int#
thread Int# -> Int# -> Int#
<# Int#
chunkLenSlack
= Int#
chunkLenBase Int# -> Int# -> Int#
+# Int#
1#
| Bool
otherwise
= Int#
chunkLenBase
{-# INLINE elemsForThread #-}
fill :: Int# -> Int# -> Int# -> IO ()
fill !Int#
step !Int#
ix0 !Int#
count0
= Int# -> Int# -> IO ()
go Int#
ix0 Int#
count0
where
go :: Int# -> Int# -> IO ()
go !Int#
ix !Int#
count
| Int#
1# <- Int#
count Int# -> Int# -> Int#
<=# Int#
0#
= () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do Int -> a -> IO ()
write (Int# -> Int
I# Int#
ix) (Int -> a
getElem (Int# -> Int
I# Int#
ix))
Int# -> Int# -> IO ()
go (Int#
ix Int# -> Int# -> Int#
+# Int#
step) (Int#
count Int# -> Int# -> Int#
-# Int#
1#)
{-# INLINE fill #-}