Delay slot
In computer architecture, a delay slot is an instruction slot being executed without the effects of a preceding instruction.[1] The most common form is a single arbitrary instruction located immediately after a branch instruction on a RISC or DSP architecture; this instruction will execute even if the preceding branch is taken. Thus, by design, the instructions appear to execute in an illogical or incorrect order. It is typical for assemblers to automatically reorder instructions by default, hiding the awkwardness from assembly developers and compilers.[citation needed]
Branch delay slots
When a branch instruction is involved, the location of the following delay slot instruction in the pipeline may be called a branch delay slot. Branch delay slots are found mainly in DSP architectures and older RISC architectures. MIPS, PA-RISC(delayed or non-delayed branch can be specified),[2] ETRAX CRIS, SuperH (unconditional branch instructions have one delay slot),[3] Am29000,[4] Intel i860 (unconditional branch instructions have one delay slot),[5] MC88000 (delayed or non-delayed branch can be specified),[6] and SPARC are RISC architectures that each have a single branch delay slot; PowerPC, ARM, Alpha, V850, and RISC-V do not have any. DSP architectures that each have a single branch delay slot include μPD77230[7] and the VS DSP. The SHARC DSP and MIPS-X use a double branch delay slot;[8] such a processor will execute a pair of instructions following a branch instruction before the branch takes effect. Both TMS320C3x[9] and TMS320C4x[10] use a triple branch delay slot. The TMS320C4x has both non-delayed and delayed branches.[10]
The following example shows delayed branches in assembly language for the SHARC DSP including a pair after the RTS instruction. Registers R0 through R9 are cleared to zero in order by number (the register cleared after R6 is R7, not R9). No instruction executes more than once.
R0 = 0; CALL fn (DB); /* call a function, below at label "fn" */ R1 = 0; /* first delay slot */ R2 = 0; /* second delay slot */ /***** discontinuity here (the CALL takes effect) *****/ R6 = 0; /* the CALL/RTS comes back here, not at "R1 = 0" */ JUMP end (DB); R7 = 0; /* first delay slot */ R8 = 0; /* second delay slot */ /***** discontinuity here (the JUMP takes effect) *****/ /* next 4 instructions are called from above, as function "fn" */ fn: R3 = 0; RTS (DB); /* return to caller, past the caller's delay slots */ R4 = 0; /* first delay slot */ R5 = 0; /* second delay slot */ /***** discontinuity here (the RTS takes effect) *****/ end: R9 = 0;
The goal of a pipelined architecture is to complete an instruction every clock cycle. To maintain this rate, the pipeline must be full of instructions at all times. The branch delay slot is a side effect of pipelined architectures due to the branch hazard, i.e. the fact that the branch would not be resolved until the instruction has worked its way through the pipeline. A simple design would insert stalls into the pipeline after a branch instruction until the new branch target address is computed and loaded into the program counter. Each cycle where a stall is inserted is considered one branch delay slot. A more sophisticated design would execute program instructions that are not dependent on the result of the branch instruction. This optimization can be performed in software at compile time by moving instructions into branch delay slots in the in-memory instruction stream, if the hardware supports this. Another side effect is that special handling is needed when managing breakpoints on instructions as well as stepping while debugging within branch delay slot. An interrupt is unable to occur during a branch delay slot and is deferred until after the branch delay slot.[11][12] Placing branch instruction in the branch delay slot is prohibited or deprecated.[13][10][14]
The ideal number of branch delay slots in a particular pipeline implementation is dictated by the number of pipeline stages, the presence of register forwarding, what stage of the pipeline the branch conditions are computed, whether or not a branch target buffer (BTB) is used and many other factors. Software compatibility requirements dictate that an architecture may not change the number of delay slots from one generation to the next. This inevitably requires that newer hardware implementations contain extra hardware to ensure that the architectural behavior is followed despite no longer being relevant.
Load delay slot
A load delay slot is an instruction which executes immediately after a load (of a register from memory) but does not see, and need not wait for, the result of the load. Load delay slots are very uncommon because load delays are highly unpredictable on modern hardware. A load may be satisfied from RAM or from a cache, and may be slowed by resource contention. Load delays were seen on very early RISC processor designs. The MIPS I ISA (implemented in the R2000 and R3000 microprocessors) suffers from this problem.
The following example is MIPS I assembly code, showing both a load delay slot and a branch delay slot.
lw v0,4(v1) # load word from address v1+4 into v0 nop # wasted load delay slot jr v0 # jump to the address specified by v0 nop # wasted branch delay slot
See also
- Control flow
- Bubble (computing)
- Branch predication
References
- ↑ A.Patterson, David; L.Hennessy, John (1990). Computer Archtecture A Quantitative Approach. Morgan Kaufmann Publishers. p. 275. ISBN 1-55860-069-8.
- ↑ DeRosa, John A.; Levy, Henry M.. "An Evaluation of Branch Architectures". p. 1. https://dl.acm.org/doi/pdf/10.1145/30350.30352. Retrieved 2024-01-27.
- ↑ "SH7020 and SH7021 Hardware ManualSuperH™ RISC engine". p. 42,70. https://www.renesas.com/us/en/document/mah/superh-risc-engine-sh7020-and-sh7021-hd6437020-hd6477021-hd6437021-hd6417021?r=469371. Retrieved 2023-12-17.
- ↑ "Evaluating and Programming the 29K RISC Family Third Edition – DRAFT". p. 54. https://ia902802.us.archive.org/22/items/29kprog/29kprog.pdf#page=78. Retrieved 2023-12-20.
- ↑ "i860™ 64-bit Microprocessor Programmer's Reference Manual". p. 70(5-11). http://www.bitsavers.org/components/intel/i860/240329-002_i860_64-Bit_Microprocessor_Programmers_Reference_Feb89.pdf#page=70. Retrieved 2023-12-21.
- ↑ "MC88100 RISC Microprocessor User's Manual". p. 81(3-26). http://www.bitsavers.org/components/motorola/88000/MC88100_RISC_Microprocessor_Users_Manual_2ed_1990.pdf#page=81. Retrieved 2023-12-21.
- ↑ "μPD77230 Advanced Signal Processor". p. 191(4-76). http://www.bitsavers.org/components/nec/_dataSheets/uPD77230_Advanced_Signal_Processor_198603.pdf. Retrieved 2023-11-05.
- ↑ "MIPS-X Instruction Set and Programmer's Manual". p. 18. https://apps.dtic.mil/sti/tr/pdf/ADA181619.pdf. Retrieved 2023-12-03.
- ↑ "The TMS320C30 Floating-Point Digital Signal Processor". ti.com. p. 14. https://www.ti.com/lit/an/spra397/spra397.pdf#page=14. Retrieved 2023-11-04.
- ↑ 10.0 10.1 10.2 "TMS320C4x User's Guide". p. 171(7-9). https://www.ti.com/lit/ug/spru063c/spru063c.pdf#page=171. Retrieved 2023-10-29.
- ↑ "μPD77230 Advanced Signal Processor". pp. 38(3-39), 70(3-41). http://www.bitsavers.org/components/nec/_dataSheets/uPD77230_Advanced_Signal_Processor_198603.pdf. Retrieved 2023-11-17.
- ↑ "TMS320C4x User's Guide". p. 75(3-15). https://www.ti.com/lit/ug/spru063c/spru063c.pdf#page=171. Retrieved 2023-12-02.
- ↑ "μPD77230 Advanced Signal Processor". p. 191(4-76). http://www.bitsavers.org/components/nec/_dataSheets/uPD77230_Advanced_Signal_Processor_198603.pdf#page=191. Retrieved 2023-10-28.
- ↑ "MC88100 RISC Microprocessor User's Manual". p. 88(3-33). http://www.bitsavers.org/components/motorola/88000/MC88100_RISC_Microprocessor_Users_Manual_2ed_1990.pdf#page=88. Retrieved 2023-12-30.
External links
- DeRosa, J.A.; Levy, H.M. (1987). "An evaluation of branch architectures §2 Delayed Branches". Proceedings of the 14th annual international symposium on Computer architecture (ISCA '87). Association for Computing Machinery. pp. 10–16. doi:10.1145/30350.30352. ISBN 978-0-8186-0776-9. https://dl.acm.org/doi/pdf/10.1145/30350.30352.
- Prabhu, Gurpur M.. "Branch Prediction Schemes". Computer Architecture Tutorial. Iowa State University. http://web.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/branchPred.html.
Original source: https://en.wikipedia.org/wiki/Delay slot.
Read more |