The C29x CPU instructions operate by
utilizing and updating registers in different stages of the pipeline, while memory
reads and writes occur in separate stages of the pipeline. One of the effects of
having operations for an instruction in different phases of the pipeline is that
pipeline conflicts (also known as pipeline hazards) are possible. There are three
main types of hazards in any pipelined architecture.
- Control Hazard: A
control hazard occurs due to discontinuities in the execution sequence. The
D2 controller and Instruction buffer control mechanism are responsible for
automatically handling such hazards, there is a possibility discarding some
instruction packets. To minimize cycle overhead, the user assembly code can
choose to have discontinuity instructions (except CALL.PROT, RET.PROT and
LB.PROT ) execute instructions in the delay slots of a discontinuity. This
decision is part of the opcode of the discontinuity instruction.
- Structural Hazard: The
C29x CPU does not present any structural hazards for instruction execution.
However, there is a structural hazard that can occur in the context-save and
restore sequence when handling Realtime Interrupts or Non-Maskable
Interrupts (NMIs). This hazard occurs due to the timing of the pipeline
operations during the interrupt context save and restore process. For the
RETI.RTINT instruction to restore the CPU register contents, RETI.RTINT
instruction must be preceded by a minimum of 6 instruction packets. If the
RETI.RTINT instruction is executed less than 6 instruction packets after the
interrupt service routine is entered, hardware pipeline protection gets
activated.
- Data Hazard: Almost
all the hazards in the C29x CPU pipeline fall into the category of data
hazards. These hazards can arise from different scenarios, such as a write
operation to a memory location before a read operation from the same memory
location, or a write operation to a register before a read operation from
the same register. The C29x CPU pipeline controller has hardware to detect
these data hazards and generate pipeline protection stall cycles to make
sure that the instruction execution sequence is not affected.
- WAW Hazard: A
Write-after-Write (WAW) hazard occurs when a resource (like a register) can
be updated in multiple phases of the pipeline.
- Instructions that
update Ax registers during the D2 phase of the pipeline can cause
WAW hazards due to the fact that Ax registers can now be loaded from
memory or Mx registers moved in the E1 phase of the pipeline. This
allows for a sequence of instructions to update the same Ax register
out of order or in the same cycle.
- In the E1 phase,
operations that update the Dx and Mx registers are composed of both
single cycle and multicycle instructions. This means that some
instructions can update the Dx/Mx register after the E1 phase is
complete, while others take several cycles (E2 - E6) to update the
Dx/Mx register. As a result, a sequence of instructions can cause a
WAW hazard by updating the same Dx/Mx register either out of order
or in the same cycle.
Lets look into the data hazard example
shown in Table 4-2 and Figure 4-3.
Table 4-2 Sample Instruction Sequence
with Data Hazard
Instruction Packet |
Label for Reference |
Comments |
MV D8, #0x1231156 |
IPKT-1 |
|
MV M6, #0x4022F983 |
IPKT-2 |
|
MV D2, #0x2 |
IPKT-3 |
|
FTOS16 D7, M6 |
IPKT-4 |
|
LD.32 A4, *A0 |
IPKT-5 |
A4 register is loaded at the end of E1 phase of the
instruction. |
CMP D7, D8 |
IPKT-6 |
|
ADD.U16 A4, A4, #0x20 |
IPKT-7 |
ADD of A4 register happens in the D2 phase of the pipeline. This
instruction uses A4 register that was loaded in IPKT-5. |
MV D4, #0x5 |
IPKT-8 |
|
In the absence of hardware pipeline
protection, when the above instruction packet sequence is executed, the load of the
A4 register by IPKT-5 occur in the W phase of the pipeline, while the add operation
of IPKT-7 (D2 phase of the pipeline) takes place earlier in the same cycle and thus
use the old value of the A4 register. The C29x CPU has hardware pipeline protection
mechanisms that makes sure any resource used as a source operand in an instruction
is only utilized after any pending updates by any previous instructions are
finished. If the source operand is a memory location, then any pending writes to the
same address (or address block for certain regions that are block protected) by
previous instructions are issued before the read. The hardware pipeline protection
mechanism detects that IPKT-7 is using the A4 register before A4 is updated by
IPKT-5, and inserts stall cycles so that IPKT-7 is held in the D2 phase until the A4
register update is completed. This is shown in Figure 4-3.