diff options
author | Carter Tazio Schonwald <carter.schonwald@gmail.com> | 2014-12-15 09:42:36 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-12-15 09:42:52 -0600 |
commit | f44333eae7bc7dc7b6003b75874a02445f6b633b (patch) | |
tree | 242ae7928d39bed82d4162b6a397d1e6ccdb45e5 /compiler/prelude/primops.txt.pp | |
parent | 8afdf274194e77e85e6a08dc4963022c56fc29d8 (diff) | |
download | haskell-f44333eae7bc7dc7b6003b75874a02445f6b633b.tar.gz |
Changing prefetch primops to have a `seq`-like interface
Summary:
The current primops for prefetching do not properly work in pure code;
namely, the primops are not 'hoisted' into the correct call sites based
on when arguments are evaluated. Instead, they should use a `seq`-like
interface, which will cause it to be evaluated when the needed term is.
See #9353 for the full discussion.
Test Plan: updated tests for pure prefetch in T8256 to reflect the design changes in #9353
Reviewers: simonmar, hvr, ekmett, austin
Reviewed By: ekmett, austin
Subscribers: merijn, thomie, carter, simonmar
Differential Revision: https://phabricator.haskell.org/D350
GHC Trac Issues: #9353
Diffstat (limited to 'compiler/prelude/primops.txt.pp')
-rw-r--r-- | compiler/prelude/primops.txt.pp | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index a3c15a9c46..909b17b7f1 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -2933,22 +2933,23 @@ section "Prefetch" architectures or vendor hardware. The manual can be found at http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html . - The {\tt prefetchMutableByteArray} family of operations has the order of operations + The {\tt prefetch*} family of operations has the order of operations determined by passing around the {\tt State#} token. - For the {\tt prefetchByteArray} - and {\tt prefetchAddr} families of operations, consider the following example: - - {\tt let a1 = prefetchByteArray2# a n in ...a1... } - - In the above fragement, {\tt a} is the input variable for the prefetch - and {\tt a1 == a} will be true. To ensure that the prefetch is not treated as deadcode, - the body of the let should only use {\tt a1} and NOT {\tt a}. The same principle - applies for uses of prefetch in a loop. + To get a "pure" version of these operations, use {\tt inlinePerformIO} which is quite safe in this context. + It is important to note that while the prefetch operations will never change the + answer to a pure computation, They CAN change the memory locations resident + in a CPU cache and that may change the performance and timing characteristics + of an application. The prefetch operations are marked has_side_effects=True + to reflect that these operations have side effects with respect to the runtime + performance characteristics of the resulting code. Additionally, if the prefetchValue + operations did not have this attribute, GHC does a float out transformation that + results in a let/app violation, at least with the current design. } + ------------------------------------------------------------------------ @@ -2956,48 +2957,75 @@ section "Prefetch" --- primop PrefetchByteArrayOp3 "prefetchByteArray3#" GenPrimOp - ByteArray# -> Int# -> ByteArray# + ByteArray# -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchMutableByteArrayOp3 "prefetchMutableByteArray3#" GenPrimOp - MutableByteArray# s -> Int# -> State# s -> State# s + MutableByteArray# s -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchAddrOp3 "prefetchAddr3#" GenPrimOp - Addr# -> Int# -> Addr# + Addr# -> Int# -> State# s -> State# s + with has_side_effects = True +primop PrefetchValueOp3 "prefetchValue3#" GenPrimOp + a -> State# s -> State# s + with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes } + has_side_effects = True ---- primop PrefetchByteArrayOp2 "prefetchByteArray2#" GenPrimOp - ByteArray# -> Int# -> ByteArray# + ByteArray# -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchMutableByteArrayOp2 "prefetchMutableByteArray2#" GenPrimOp - MutableByteArray# s -> Int# -> State# s -> State# s + MutableByteArray# s -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchAddrOp2 "prefetchAddr2#" GenPrimOp - Addr# -> Int# -> Addr# + Addr# -> Int# -> State# s -> State# s + with has_side_effects = True +primop PrefetchValueOp2 "prefetchValue2#" GenPrimOp + a -> State# s -> State# s + with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes } + has_side_effects = True ---- primop PrefetchByteArrayOp1 "prefetchByteArray1#" GenPrimOp - ByteArray# -> Int# -> ByteArray# + ByteArray# -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchMutableByteArrayOp1 "prefetchMutableByteArray1#" GenPrimOp - MutableByteArray# s -> Int# -> State# s -> State# s + MutableByteArray# s -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchAddrOp1 "prefetchAddr1#" GenPrimOp - Addr# -> Int# -> Addr# + Addr# -> Int# -> State# s -> State# s + with has_side_effects = True +primop PrefetchValueOp1 "prefetchValue1#" GenPrimOp + a -> State# s -> State# s + with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes } + has_side_effects = True ---- primop PrefetchByteArrayOp0 "prefetchByteArray0#" GenPrimOp - ByteArray# -> Int# -> ByteArray# + ByteArray# -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchMutableByteArrayOp0 "prefetchMutableByteArray0#" GenPrimOp - MutableByteArray# s -> Int# -> State# s -> State# s + MutableByteArray# s -> Int# -> State# s -> State# s + with has_side_effects = True primop PrefetchAddrOp0 "prefetchAddr0#" GenPrimOp - Addr# -> Int# -> Addr# - + Addr# -> Int# -> State# s -> State# s + with has_side_effects = True +primop PrefetchValueOp0 "prefetchValue0#" GenPrimOp + a -> State# s -> State# s + with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes } + has_side_effects = True ------------------------------------------------------------------------ --- --- |