There are some minimal guarantees that may be expected of a CPU:
Q = P; D = *Q; |
the CPU will issue the following memory operations:
Q = LOAD P, D = LOAD *Q |
and always in that order.
a = *X; *X = b; |
the CPU will only issue the following sequence of memory operations:
a = LOAD *X, STORE *X = b |
And for:
*X = c; d = *X; |
the CPU will only issue:
STORE *X = c, d = LOAD *X |
(Loads and stores overlap if they are targetted at overlapping pieces of memory).
And there are a number of things that must or must not be assumed:
X = *A; Y = *B; *D = Z; |
we may get any of the following sequences:
X = LOAD *A, Y = LOAD *B, STORE *D = Z X = LOAD *A, STORE *D = Z, Y = LOAD *B Y = LOAD *B, X = LOAD *A, STORE *D = Z Y = LOAD *B, STORE *D = Z, X = LOAD *A STORE *D = Z, X = LOAD *A, Y = LOAD *B STORE *D = Z, Y = LOAD *B, X = LOAD *A |
X = *A; Y = *(A + 4); |
we may get any one of the following sequences:
X = LOAD *A; Y = LOAD *(A + 4); Y = LOAD *(A + 4); X = LOAD *A; {X, Y} = LOAD {*A, *(A + 4) }; |
And for:
*A = X; Y = *A; |
we may get either of:
STORE *A = X; Y = LOAD *A; STORE *A = Y = X; |
Paul E. McKenney 2011-12-16