Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Al Grant <algrant@myrealbox.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Faking a dependency, for consume-semantics |
| Date | 2013-06-05 23:13 -0700 |
| Organization | unknown |
| Message-ID | <5ad08a05-47da-4530-b5f9-9e9b43d4ec4f@w15g2000vbn.googlegroups.com> (permalink) |
Sometimes we want to fake a data-dependency in order
to use consume-semantics - we can use idioms like x & 0
or x ^ x, and by 1.10#9 the implementation must treat this
as carrying a dependency:
x = ready.load(std::memory_order_consume);
if (x)
y = *(&buffer + (x & 0)); // fake dependency on x
I couldn't find a standard way to do this, i.e. a counterpart
to std::kill_dependency.
By my reading of 1.10#9, we can do this:
template<typename P, typename V>
P& with_dependency(P& p, V) { return p; }
x = ready.load(std::memory_order_consume);
if (x)
y = with_dependency(buffer, x);
We could even define it as variadic:
template<typename P>
P& with_dependency(P& p, ...) { return p; }
Can we indeed create a data-dependency this way?
If so, it seems that compilers must not only avoid optimizing
away explicit fake data-dependencies (of the x&0 kind), ensuring
that they appear as data-dependent instruction sequences
on memory-models where consume-semantics needs this,
but actually synthesize such code to create data-dependencies
on values whose only "use" is to be passed as unused operands
to a function.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next | Find similar
Faking a dependency, for consume-semantics Al Grant <algrant@myrealbox.com> - 2013-06-05 23:13 -0700
csiph-web