[cpp-threads] memory model

Peter Dimov pdimov at mmltd.net
Sat Apr 30 11:23:44 BST 2005


Boehm, Hans wrote:
> Compilers convert between control and data dependence all the
> time, by converting conditionals to predicated instructions.
> Many modern architectures have at least conditional move instructions.
> Itanium allows almost all instructions to be executed conditionally
> based on the contents of a predicate register.  The reverse is
> also done occasionally.
>
> Even more importantly, compilers can optimize away conditionals
> if they can deduce the value of the condition.  This makes it
> really difficult to say what it means that some ordering should be
> respected for control dependent operations.  If I have
>
> r1 = load_acquire_for_control_dependent_loads(&x);
> if (r1 == r1)
>   r2 = y
>
> are the loads of x and y ordered?  You know there won't be a
> branch in the object code.  (Well, you hope that anyway.)

No, because whether the load of y is executed does not depend on the value 
of r1.

> I'm not sure if load_acquire_for_data_dependent_loads makes
> sense either.  If I have
>
> r3 = ...
> r1 = load_acquire_for_data_dependent_loads(x)
> r2 = *(r3 + r1 - r1)
>
> The second load also isn't really data-dependent on the first,
> by the time you look at the assembly code.

It's also not data dependent without the concept of assembly code, because 
the location being fetched does not depend on the value of r1.

I don't see the problem in these examples.

If a load is being conditionally executed depending on a value, it's cc. If 
the location being fetched depends on a value, the load is dd. All 
interesting cases in practice are clear-cut. 





More information about the cpp-threads mailing list