In the Buba, a 5-stage pipeline without bypass logic, the result of an
instruction will not be available to be read (in the Register File
stage) until 4 clock cyles later. So for instance, if a certain
instruction writes a value to R0, that value cannot be used by the
next 3 instructions (they will all be reading the previous value of
R0). The fourth instruction (following the original instruction) is
the first that will be able to read the new value of R0. So, for
instance, consider the following code:
ADDC(R31, 10, RO)
SUBC(R0, 5, R1)
ANDC(R0, 6, R2)
ORC(R0, 7, R3)
CMPLTC(R0, 11, R4)
The CMPLTC will be the first instruction to fetch the new value of
R0. All the preceding instructions will be using the previous value(s)
of R0. The ADDC instruction is in the Write Back stage while ORC is in
the Register File stage-so the new R0 is not written back in time for
the ORC to read it.
For the working Beta, S1, S2, and S3 all compute the same results.
Initially: Reg[ R1 ] = -1, Reg[ R2 ] = 1, Reg[ R3 ] = 5, Reg[ R4 ] = -1
ADD( R1, R2, R3 ) Reg[ R3 ] = Reg[ R1 ] + Reg[ R2 ] = (-1) + 1 = 0
SUB( R2, R3, R4 ) Reg[ R4 ] = Reg[ R2 ] - Reg[ R3 ] = 1 - 0 = 1
CMPLT( R3, R4, R5 ) Reg[ R5 ] = (Reg[ R3 ] < Reg[ R4 ]) = (0 < 1) = 1
so Reg[ R5 ] = 1 for all three cases.
For the Buba (italics denote cases in which the Buba is different from
a working Beta, in which the most recently calculated result is not
being used):
S1:
ADD( R1, R2, R3 ) Reg[ R3 ] = Reg[ R1 ] + Reg[ R2 ] = (-1) + 1 = 0
new value of Reg[R3] not available yet
SUB( R2, R3, R4 ) Reg[ R4 ] = Reg[ R2 ] - Reg[ R3 ] = 1 - 5 = -4
new values of Reg[ R3 ] and Reg[ R4 ] not available yet
CMPLT( R3, R4, R5 ) Reg[ R5 ] = (Reg[ R3 ] < Reg[ R4 ]) = (5 < -1) = 0
Reg[ R5 ] = 0
S2:
ADD( R1, R2, R3 ) Reg[ R3 ] = Reg[ R1 ] + Reg[ R2 ] = (-1) + 1 = 0
NOP
new value of Reg[ R3 ] not available yet
SUB( R2, R3, R4 ) Reg[ R4 ] = Reg[ R2 ] - Reg[ R3 ] = 1 - 5 = -4
NOP
new value of Reg[ R4 ] not available yet (but Reg[ R3 ] is available)
CMPLT( R3, R4, R5 ) Reg[ R5 ] = (Reg[ R3 ] < Reg[ R4 ]) = (0 < -1) = 0
Reg[ R5 ] = 0
S3:
ADD( R1, R2, R3 ) Reg[ R3 ] = Reg[ R1 ] + Reg[ R2 ] = (-1) + 1 = 0
NOP
new value of Reg[ R3 ] not available yet
SUB( R2, R3, R4 ) Reg[ R4 ] = Reg[ R2 ] - Reg[ R3 ] = 1 - 5 = -4
new values of Reg[ R3 ] and Reg[ R4 ] not available yet
CMPLT( R3, R4, R5 ) Reg[ R5 ] = (Reg[ R3 ] < Reg[ R4 ]) = (5 < -1) = 0
Reg[ R5 ] = 0