@@ -83,6 +83,9 @@ prefetchIndex (BitArray (PrimArray ba#)) (BlockIx blockIx) =
83
83
84
84
assert (i >= 0 && i < sizeofByteArray (ByteArray ba# ) - 63 ) $
85
85
86
+ -- In prefetchByteArray0, the 0 refers to a "non temporal" load, which is
87
+ -- a hint that the value will be used soon, and then not used again (soon).
88
+ -- So the caches can evict the value as soon as they like.
86
89
ST (\ s -> case prefetchByteArray0# ba# i# s of
87
90
s' -> (# s', () # ))
88
91
@@ -133,8 +136,10 @@ unsafeSet (MBitArray arr) blockIx blockBitIx = do
133
136
{-# INLINE prefetchSet #-}
134
137
prefetchSet :: MBitArray s -> BlockIx -> ST s ()
135
138
prefetchSet (MBitArray (MutablePrimArray mba# )) (BlockIx blockIx) = do
136
- -- For setting, we will do several writes to the same cache line, so
137
- -- read it into all 3 levels of cache.
139
+ -- For setting, we will do several writes to the same cache line, but all
140
+ -- immediately after each other, after which we will not need the value in
141
+ -- the cache again (for a long time). So as with prefetchIndex we want to
142
+ -- disturbe the caches the least, and so we use prefetchMutableByteArray0.
138
143
let ! (I # i# ) = fromIntegral blockIx `shiftL` 6
139
144
-- blockIx * 64 to go from block index to the byte offset of the beginning
140
145
-- of the block. This offset is in bytes, not words.
@@ -144,6 +149,9 @@ prefetchSet (MBitArray (MutablePrimArray mba#)) (BlockIx blockIx) = do
144
149
assert (let i = I # i# in i >= 0 && i < sz- 63 ) $ return ()
145
150
#endif
146
151
152
+ -- In prefetchMutableByteArray0, the 0 refers to a "non temporal" load,
153
+ -- which is a hint that the value will be used soon, and then not used
154
+ -- again (soon). So the caches can evict the value as soon as they like.
147
155
ST (\ s -> case prefetchMutableByteArray0# mba# i# s of
148
156
s' -> (# s', () # ))
149
157
0 commit comments