Previous | Next --- Slide 9 of 37
Back to Lecture Thumbnails
acortes

How does the processor know that z is not dependent on x? A programmer can see this but how far back does the processor go to see if something depends on another variable. I.e. if we had set x = *p; y = x+1; a = x+ 1; z = a+2; z doesn't immediately depend on x but since a depends on x then so does z, how does this happen?

tcm

The trick is that the hardware walks forward over the (predicted) instruction stream, noting which instructions depend on which inputs. At run-time, the hardware knows all memory addresses (at least once they are calculated) and register numbers, so there isn't any ambiguity. It maintains a data structure (sometimes called a "scoreboard") where it remembers which locations are not ready yet, because they have yet to be computed (or fetched, in the case of a memory load). An instruction can execute once all of its inputs are marked as "ready" by the hardware.

Therefore in the original example above, location "x" is marked as being "not ready" until the load (through pointer "p") completes; therefore the "x + 1" computation in the second instruction cannot begin, which means that the hardware realizes that "y" is also "not ready". On the other hand, location "a" is ready, so the "a + 2" computation can proceed.

In the example that you provided, "x" would be marked as "not ready" due to the load (through "*p"), which means that "x + 1" cannot be calculated yet, which in turns means that neither "y" or "a" are ready. This in turn indicates that "a+2" cannot be calculated.