14.2.9 Guarantees

There are some minimal guarantees that may be expected of a CPU:

  1. On any given CPU, dependent memory accesses will be issued in order, with respect to itself. This means that for:



    Q = P; D = *Q;
    


    the CPU will issue the following memory operations:



    Q = LOAD P, D = LOAD *Q
    


    and always in that order.

  2. Overlapping loads and stores within a particular CPU will appear to be ordered within that CPU. This means that for:



    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).

  3. A series of stores to a single variable will appear to all CPUs to have occurred in a single order, thought this order might not be predictable from the code, and in fact the order might vary from one run to another.

And there are a number of things that must or must not be assumed:

  1. It must not be assumed that independent loads and stores will be issued in the order given. This means that for:



    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
    


  2. It must be assumed that overlapping memory accesses may be merged or discarded. This means that for:



    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