<div dir="ltr">just to clarify:<div><br></div><div>the issue lies with the pure operations.</div><div> Strictly speaking, the one on mutable byte arrays doesn&#39;t even need the effects annotation, because the ST s / IO ordering will be enough to make sure it will always be run when it should.  the pure ones, would almost always need to be in some sort of monadic wrapper to make sure they&#39;re sequences ahead of time at the right time, i think</div>

<div><br></div><div>the concern lies with prefetches being for performance:  they only make sense as part of a thoughtful approach to leveraging the memory bandwidth of a system, and GHC does make use of system memory buses pretty aggressively as is! </div>

<div><br></div><div><br></div><div style>to be clear: I&#39;d very much like to be able to write code like </div><div style><br></div><div style>prefetchPtrM :: Monad m =&gt;  Ptr a -&gt; m ()</div><div style>prefetchPtrM (Ptr adr) = do (return $ prefetchAddrOp addr) ; return ()</div>

<div style><br></div><div style><br></div><div style>this is reasonably motivated use case: the Vector library has monadic operations on its Pure vectors to enforce evaluation order. </div><div style><br></div><div style>

naively, it seems like the right approach requires at least the &quot;can fail&quot; annotation, and perhaps maybe the &quot;has side effects annotation&quot;, so that the above prefetchM operation is definable. </div><div style>

<br></div><div style>or maybe im not understanding something, and this is simpler than I fear?</div><div style><br></div><div style>thanks!</div><div style><br></div><div style><br></div><div><br></div><div><br></div></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 16, 2013 at 1:35 AM, Carter Schonwald <span dir="ltr">&lt;<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">just for reference, the  current ops are <div><br></div><div><br></div><div><div>primop PrefetchByteArrayOp2 &quot;prefetchByteArray2#&quot; GenPrimOp</div>

<div>   ByteArray# -&gt; Int# -&gt; ByteArray#</div>
<div>   with llvm_only = True</div><div><br></div><div>primop PrefetchMutableByteArrayOp2 &quot;prefetchMutableByteArray2#&quot; GenPrimOp</div><div>   MutableByteArray# s -&gt; Int# -&gt; State# s -&gt; State# s</div><div>


   with has_side_effects = True</div><div>        llvm_only = True</div><div><br></div><div>primop PrefetchAddrOp2 &quot;prefetchAddr2#&quot; GenPrimOp</div><div>   Addr# -&gt; Int# -&gt; Addr#</div><div>   with llvm_only = True</div>


</div><div><br></div><div>one of the things my patch (for 7.8) will do is add preliminary native code gen support for prefetch, admittedly in the form of Nops. (later work will fix that to be a bit more actionable)</div>


<div><br></div><div><br></div><div>any opinions that help us suss this out would be appreciated</div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">

On Mon, Sep 16, 2013 at 1:08 AM, Carter Schonwald <span dir="ltr">&lt;<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey all,<div>I&quot;ve been doing some work to finish up my prefetch patch that  I hope to land in 7.8, and one design matter thats come up is what the optimization semantics should be!</div>


<div>
<br></div><div>is it appropriate to duplicate prefetches? (probably yes)</div><div>is it appropriate to float OUT prefetched? (probably not?)</div><div><br></div><div>operations that are dupable which shouldn&#39;t float out are marked with the can_fail= true</div>



<div>property,</div><div>operations which cannot be safely floated out and can&#39;t be duped are marked as having side effects.</div><div><br></div><div>on the GHC irc channel, Duncan was patient enough to walk my through understanding this, and this makes me lean towards the conclusion that duplication is ok, but floating out isnt. Thus all the prefetch ops (pure or not) should have the attribute &quot;can fail&quot;, rather than no attribut or &quot;has effects&quot;.</div>



<div><br></div><div>this is exploiting that &quot;can fail&quot;  really just means &quot;don&#39;t float out&quot;.</div><div><br></div><div>thoughts and counter points?</div><div><br></div>
<div>thanks</div><span><font color="#888888"><div><br></div><div>-Carter</div><div><br></div><div><br></div><div><br></div></font></span></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>