News for hackers. Stuff that matters.
Re:What's new in CPUs since the 80s and how does it affect p... by userbinator on Sunday August 23, 2015 @09:32PM (#10107461)
"However, loads can be reordered with earlier stores. For example, if you write

    mov 1, [%esp]
    mov [%ebx], %eax
it can be executed as if you wrote

    mov [%ebx], %eax
    mov 1, [%esp]"
The confusing mix of Intel and GAS/AT&T syntax aside, this is not possible since it would give different results when ebx == esp.
Re:What's new in CPUs since the 80s and how does it affect p... by caf on Sunday August 23, 2015 @10:13PM (#10107538)
It's not a static decision though - the memory accesses can still be reordered when %ebx != %esp, though of course this only ends up visible where there are multiple CPUs involved.

For example, consider the case above and assume that the initial conditions are:

  (%esp) == 0
  (%ebx) == 0
Now imagine we have a second CPU executing simultaneously, with the same %ebx and %esp as the first CPU, but executing this:

  mov $1, (%ebx)
  mov (%esp), %eax
Now if there was no reordering, either one or both CPUs must end with %eax == 1. However, the hoisting of loads before earlier stores means that you can actually end up with both CPUs have %eax == 0 after this executes.
Re:What's new in CPUs since the 80s and how does it affect p... by userbinator on Sunday August 23, 2015 @10:46PM (#10107622)
You're correct about it being possible for other CPUs to see "crossed" loads/stores, but within one CPU/stream of instructions the programmer-visible ordering is absolutely preserved, because if it wasn't, a lot of existing software would break. In your example, if ebx == esp, and both CPUs executed those two instructions, then they must both see eax == 1. I think you had this scenario in mind instead (where A and B are different memory locations):

CPU 1:

  mov $1, (A)
  mov (B), %eax
CPU 2:

  mov $1, (B)
  mov (A), %eax
Where eax == 0 on both CPUs is definitely possible.
Re:What's new in CPUs since the 80s and how does it affect p... by caf on Sunday August 23, 2015 @11:16PM (#10107703)
We are of course in violent agreement.

The point to note is that the decision on whether or not the reordering can occur, based on whether or not A and B are the same or not, is made dynamically at the point of execution.