<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 11/06/2015 08:36 AM, Richard Diamond
wrote:<br>
</div>
<blockquote
cite="mid:CAPpP=LCgpvDw=gFeyoCsDG_tx03Bnn6AmWCth+gKEPffT+StDw@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Nov 3, 2015 at 5:09 PM,
Philip Reames <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> The common use case
I've seen for a black box like construct is when writing
microbenchmarks. In particular, you're generally
looking for a way to "sink" the result of a computation
without having that sink outweigh the cost of the thing
you're trying to measure.<br>
<br>
Common alternate approaches are to use a volatile store
(so that it can't be eliminated or sunk out of loops) or
a call to an external function with a cheap calling
convention. <br>
<br>
As an example:<br>
int a = 5; // initialization is not visible to compiler<br>
</div>
</blockquote>
<div><br>
</div>
<div>This intrinsic is designed to provide exactly this
(assuming `__builtin_blackbox` is also added to clang):</div>
<div><br>
</div>
<div>int a = __builtin_blackbox(5);</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> int b = 7;<br>
void add_two_globals()<br>
sink(a+b)<br>
</div>
</blockquote>
<div><br>
</div>
<div>And:</div>
<div><br>
</div>
<div>__builtin_blackbox(a+b);</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> }<br>
<br>
If what I'm look into is the code generation around
addition, this is a very useful way of testing the
entire compiler - frontend, middle end, and backend. <br>
<br>
I'll note that we use such a framework extensively. <br>
<br>
What I'm not clear on is why this needs to be an
intrinsic. Why does a call to an external function or a
volatile store not suffice? <span><font
color="#888888"><br>
</font></span></div>
</blockquote>
<div><br>
</div>
<div>Because Rust's `test::black_box` is generic, it can't
be an external function. Also, code using this will
actually be executed, so it's also not good enough to
leave it undefined.</div>
</div>
</div>
</div>
</blockquote>
This statement doesn't make sense to me. What does generic have to
do with being external? And why can't an external function be
defined?<br>
<br>
Philip<br>
<br>
</body>
</html>