Knowledge (XXG)

Delay slot

Source 📝

531:
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;
170:. In these systems, the CPU immediately moves on to what it believes will be the correct side of the branch and thereby eliminates the need for the code to specify some unrelated instruction, which may not always be obvious at compile-time. If the assumption is wrong, and the other side of the branch has to be called, this can introduce a lengthy delay. This occurs rarely enough that the speed up of avoiding the delay slot is easily made up by the smaller number of wrong decisions. 36: 427:(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 behaviour is followed despite no longer being relevant. 210:. This adds some additional circuitry to hold the intermediate states of the instruction as it flows through the units. While this does not improve the cycle timing of any single instruction, the idea is to allow a second instruction to use the other CPU sub-units when the previous instruction has moved on. 542:
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
530:
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 =
299:
top: read a number from memory and store it in a register read another number and store it in a different register add the two numbers into a third register if the result in the 3rd register is greater than 1000, then go back to top: (if it is not) write the result to memory read a
186:
using a four-step process; the instruction is first read from memory, then decoded to understand what needs to be performed, those actions are then executed, and finally, any results are written back to memory. In early designs, each of these stages was performed in series, so that instructions took
379:
read a number from memory and store it in a register read another number and store it in a different register add the two numbers into a third register if the result in the 3rd register is greater than 1000, then go back to the top read a number from memory and store it in another register (if
327:
instruction read from memory instead. That takes one full instruction cycle, at a minimum, and results in the pipeline being empty for at least one instruction's time. This is known as a "pipeline stall" or "bubble", and, depending on the number of branches in the code, can have a noticeable impact
217:
type arrangement, the total number of instructions processed at any time can be improved by up to the number of pipeline stages. In the Z80, for example, a four-stage pipeline could improve overall throughput by four times. However, due to the complexity of the instruction timing, this would not be
249:
and add it to the value in another, another version might add the value found in memory to a register, while another might add the value in one memory location to another memory location. Each of these instructions takes a different amount of bytes to represent it in memory, meaning they take
526:
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.
359:
could be updated with the correct value. This simple solution wastes the processing time available. More advanced solutions would instead try to identify another instruction, typically nearby in the code, to place in the delay slot so that useful work would be accomplished.
340:, which refers to the instruction slot after any instruction that needs more time to complete. In the examples above, the instruction that requires more time is the branch, which is by far the most common type of delay slot, and these are more commonly referred to as a 383:
Now when the branch is executing, it goes ahead and performs the next instruction. By the time that instruction is read into the processor and starts to decode, the result of the comparison is ready and the processor can now decide which instruction to read next, the
269:
top: read a number from memory and store it in a register read another number and store it in a different register add the two numbers into a third register write the result to memory read a number from memory and store it in another register ...
395:
Finding an instruction to fill the slot can be difficult. The compilers generally have a limited "window" to examine and may not find a suitable instruction in that range of code. Moreover, the instruction cannot rely on any of the data within the branch; if an
367:
instruction at the end is completely independent, it does not rely on any other information and can be performed at any time. This makes it suitable for placement in the branch delay slot. Normally this would be handled automatically by the
293:, by the time it is complete the value from the second is ready and the CPU can immediately add them. In a non-pipelined processor the first four instructions will take 16 cycles to complete, in a pipelined one, it takes only five. 415:
within the branch delay slot. An interrupt is unable to occur during a branch delay slot and is deferred until after the branch delay slot. Placing branch instruction in the branch delay slot is prohibited or deprecated.
234:
A major issue with the implementation of pipelines in early systems was that instructions had widely varying cycle counts. For instance, the instruction to add two values would often be offered in multiple versions, or
261:
However, there is one problem that comes up in pipeline systems that can slow performance. This occurs when the next instruction may change depending on the results of the last. In most systems, this happens when a
400:
instruction takes a previous calculation as one of its inputs, that input cannot be part of the code in a branch that might be taken. Deciding if this is true can be very complex in the presence of
250:
different amounts of time to fetch, may require multiple trips through the memory interface to gather values, etc. This greatly complicates the pipeline logic. One of the goals of the
140:
is an instruction slot being executed without the effects of a preceding instruction. The most common form is a single arbitrary instruction located immediately after a
508: 868: 213:
For instance, while one instruction is using the ALU, the next instruction from the program can be in the decoder, and a third can be fetched from memory. In this
913: 515:
use a double branch delay slot; such a processor will execute a pair of instructions following a branch instruction before the branch takes effect. Both
198:
At any given stage of the instruction's processing, only one part of the chip is involved. For instance, during the execution stage, typically only the
937: 822: 1078: 1059: 769: 419:
The ideal number of branch delay slots in a particular pipeline implementation is dictated by the number of pipeline stages, the presence of
303:
In this example the outcome of the comparison on line four will cause the "next instruction" to change; sometimes it will be the following
195:, the minimum number of clocks needed to complete an instruction was four, but could be as many as 23 clocks for some (rare) instructions. 226:
allowed a two-stage pipeline to be included, which gave it performance that was about double that of the Z80 at any given clock speed.
961: 721: 655: 119: 404:, in which the processor may place data in registers other than what the code specifies without the compiler being aware of this. 1104: 420: 316: 144: 57: 543:
or from a cache, and may be slowed by resource contention. Load delays were seen on very early RISC processor designs. The
100: 219: 206:
or decode the instruction, are idle. One way to improve the overall performance of a computer is through the use of an
72: 155:
architecture; this instruction will execute even if the preceding branch is taken. This makes the instruction execute
53: 79: 46: 263: 141: 520: 516: 496: 436: 254:
chip design concept was to remove these variants so that the pipeline logic was simplified, which leads to the
152: 179: 86: 311:
from memory at the top. The processor's pipeline will normally have already read the next instruction, the
548: 166:
Modern processor designs generally do not use delay slots, and instead perform ever more complex forms of
156: 255: 199: 133: 889: 558:
The following example is MIPS I assembly code, showing both a load delay slot and a branch delay slot.
347:
In early implementations, the instruction following the branch would be filled with a no-operation, or
68: 1086: 424: 207: 289:
is decoding, and so forth. Although it still takes the same number of cycles to complete the first
500: 1065: 626: 621: 246: 160: 688:. University of Maryland Baltimore County Computer Science and Electrical Engineering Department 1055: 651: 444: 401: 369: 167: 1047: 504: 480: 798: 745: 351:, simply to fill out the pipeline to ensure the timing was right such that by the time the 1044:
Proceedings of the 14th annual international symposium on Computer architecture (ISCA '87)
356: 523:
use a triple branch delay slot. The TMS320C4x has both non-delayed and delayed branches.
1009: 93: 392:
at the bottom. This prevents any wasted time and keeps the pipeline full at all times.
273:
In this case, the program is linear and can be easily pipelined. As soon as the first
1098: 214: 1069: 616: 183: 685: 423:, what stage of the pipeline the branch conditions are computed, whether or not a 1039: 985: 847: 315:, by the time the ALU has calculated which path it will take. This is known as a 17: 203: 35: 671: 464: 452: 408: 188: 27:
Instruction slot being executed without the effects of a preceding instruction
484: 412: 192: 281:
instruction can be read from memory. When the first moves to execute, the
373: 223: 1051: 476: 468: 460: 448: 890:"Evaluating and Programming the 29K RISC Family Third Edition – DRAFT" 544: 512: 492: 456: 407:
Another side effect is that special handling is needed when managing
237: 707: 552: 475:
are RISC architectures that each have a single branch delay slot;
472: 202:(ALU) is active, while other units, like those that interact with 499:
architectures that each have a single branch delay slot include
488: 440: 251: 148: 241:, which varied on where they read in the data. One version of 29: 355:
had been loaded from memory the branch was complete and the
1040:"An evaluation of branch architectures §2 Delayed Branches" 914:"i860™ 64-bit Microprocessor Programmer's Reference Manual" 300:
number from memory and store it in another register ...
277:
instruction has been read and is being decoded, the second
266:
occurs. For instance, consider the following pseudo-code:
467:(unconditional branch instructions have one delay slot), 459:(unconditional branch instructions have one delay slot), 1046:. Association for Computing Machinery. pp. 10–16. 1010:"The TMS320C30 Floating-Point Digital Signal Processor" 336:
One strategy for dealing with this problem is to use a
869:"SH7020 and SH7021 Hardware ManualSuperH™ RISC engine" 471:(delayed or non-delayed branch can be specified), and 708:"The MOS 6502 and the Best Layout Guy in the World" 397: 389: 385: 364: 352: 348: 324: 320: 312: 308: 304: 290: 286: 282: 278: 274: 242: 60:. Unsourced material may be challenged and removed. 451:(delayed or non-delayed branch can be specified), 686:"CMSC 411 Lecture 19, Pipelining Data Forwarding" 296:Now consider what occurs when a branch is added: 986:"MIPS-X Instruction Set and Programmer's Manual" 793: 791: 789: 646:A.Patterson, David; L.Hennessy, John (1990). 258:which completes one instruction every cycle. 8: 648:Computer Archtecture A Quantitative Approach 555:microprocessors) suffers from this problem. 380:it is not) write the result to memory ... 938:"MC88100 RISC Microprocessor User's Manual" 823:"MC88100 RISC Microprocessor User's Manual" 650:. Morgan Kaufmann Publishers. p. 275. 285:is being read from memory while the second 411:on instructions as well as stepping while 376:, which would re-order the instructions: 182:generally performs instructions from the 159:compared to its location in the original 120:Learn how and when to remove this message 323:instruction has to be discarded and the 307:to memory, and sometimes it will be the 1085:. Iowa State University. Archived from 848:"An Evaluation of Branch Architectures" 638: 435:Branch delay slots are found mainly in 319:. If it has to return to the top, the 599:# jump to the address specified by v0 584:# load word from address v1+4 into v0 7: 962:"μPD77230 Advanced Signal Processor" 770:"μPD77230 Advanced Signal Processor" 722:"μPD77230 Advanced Signal Processor" 218:easy to implement. The much simpler 58:adding citations to reliable sources 245:might take the value found in one 191:to complete. For instance, in the 25: 1038:DeRosa, J.A.; Levy, H.M. (1987). 846:DeRosa, John A.; Levy, Henry M. 34: 187:some multiple of the machine's 45:needs additional citations for 1083:Computer Architecture Tutorial 1: 727:. pp. 38(3-39), 70(3-41) 706:Cox, Russ (3 January 2011). 220:instruction set architecture 1079:"Branch Prediction Schemes" 363:In the examples above, the 1121: 605:# wasted branch delay slot 799:"TMS320C4x User's Guide" 746:"TMS320C4x User's Guide" 590:# wasted load delay slot 560: 547:ISA (implemented in the 439:architectures and older 328:on overall performance. 180:central processing unit 1105:Instruction processing 256:classic RISC pipeline 200:arithmetic logic unit 134:computer architecture 1015:. ti.com. p. 14 425:branch target buffer 208:instruction pipeline 54:improve this article 1052:10.1145/30350.30352 967:. p. 191(4-76) 775:. p. 191(4-76) 672:"MSX Assembly Page" 421:register forwarding 1077:Prabhu, Gurpur M. 943:. p. 81(3-26) 919:. p. 70(5-11) 828:. p. 88(3-33) 804:. p. 171(7-9) 751:. p. 75(3-15) 627:Branch predication 622:Bubble (computing) 388:at the top or the 332:Branch delay slots 247:processor register 230:Branching problems 161:assembler language 1061:978-0-8186-0776-9 495:do not have any. 402:register renaming 370:assembler program 342:branch delay slot 168:branch prediction 130: 129: 122: 104: 18:Branch delay slot 16:(Redirected from 1112: 1090: 1073: 1024: 1023: 1021: 1020: 1014: 1006: 1000: 999: 997: 996: 990: 982: 976: 975: 973: 972: 966: 958: 952: 951: 949: 948: 942: 934: 928: 927: 925: 924: 918: 910: 904: 903: 901: 900: 894: 886: 880: 879: 877: 876: 865: 859: 858: 856: 855: 843: 837: 836: 834: 833: 827: 819: 813: 812: 810: 809: 803: 795: 784: 783: 781: 780: 774: 766: 760: 759: 757: 756: 750: 742: 736: 735: 733: 732: 726: 718: 712: 711: 703: 697: 696: 694: 693: 682: 676: 675: 668: 662: 661: 643: 606: 603: 600: 597: 594: 591: 588: 585: 582: 579: 576: 573: 570: 567: 564: 399: 391: 387: 366: 354: 350: 326: 322: 314: 310: 306: 292: 288: 284: 280: 276: 244: 125: 118: 114: 111: 105: 103: 62: 38: 30: 21: 1120: 1119: 1115: 1114: 1113: 1111: 1110: 1109: 1095: 1094: 1093: 1076: 1062: 1037: 1033: 1028: 1027: 1018: 1016: 1012: 1008: 1007: 1003: 994: 992: 988: 984: 983: 979: 970: 968: 964: 960: 959: 955: 946: 944: 940: 936: 935: 931: 922: 920: 916: 912: 911: 907: 898: 896: 892: 888: 887: 883: 874: 872: 871:. p. 42,70 867: 866: 862: 853: 851: 845: 844: 840: 831: 829: 825: 821: 820: 816: 807: 805: 801: 797: 796: 787: 778: 776: 772: 768: 767: 763: 754: 752: 748: 744: 743: 739: 730: 728: 724: 720: 719: 715: 705: 704: 700: 691: 689: 684: 683: 679: 670: 669: 665: 658: 645: 644: 640: 635: 613: 608: 607: 604: 601: 598: 595: 592: 589: 586: 583: 580: 577: 574: 571: 568: 565: 562: 540: 538:Load delay slot 534: 532: 443:architectures. 433: 431:Implementations 381: 357:program counter 334: 301: 271: 232: 176: 126: 115: 109: 106: 63: 61: 51: 39: 28: 23: 22: 15: 12: 11: 5: 1118: 1116: 1108: 1107: 1097: 1096: 1092: 1091: 1089:on 2020-08-07. 1074: 1060: 1034: 1032: 1031:External links 1029: 1026: 1025: 1001: 977: 953: 929: 905: 881: 860: 838: 814: 785: 761: 737: 713: 698: 677: 663: 656: 637: 636: 634: 631: 630: 629: 624: 619: 612: 609: 561: 539: 536: 529: 432: 429: 378: 333: 330: 298: 268: 231: 228: 175: 172: 128: 127: 42: 40: 33: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 1117: 1106: 1103: 1102: 1100: 1088: 1084: 1080: 1075: 1071: 1067: 1063: 1057: 1053: 1049: 1045: 1041: 1036: 1035: 1030: 1011: 1005: 1002: 987: 981: 978: 963: 957: 954: 939: 933: 930: 915: 909: 906: 891: 885: 882: 870: 864: 861: 849: 842: 839: 824: 818: 815: 800: 794: 792: 790: 786: 771: 765: 762: 747: 741: 738: 723: 717: 714: 709: 702: 699: 687: 681: 678: 673: 667: 664: 659: 657:1-55860-069-8 653: 649: 642: 639: 632: 628: 625: 623: 620: 618: 615: 614: 610: 559: 556: 554: 550: 546: 537: 535: 528: 524: 522: 518: 514: 510: 506: 502: 498: 494: 490: 486: 482: 478: 474: 470: 466: 462: 458: 454: 450: 446: 442: 438: 430: 428: 426: 422: 417: 414: 410: 405: 403: 393: 377: 375: 371: 361: 358: 345: 343: 339: 331: 329: 318: 317:branch hazard 297: 294: 267: 265: 259: 257: 253: 248: 240: 239: 229: 227: 225: 222:(ISA) of the 221: 216: 215:assembly line 211: 209: 205: 201: 196: 194: 190: 185: 181: 173: 171: 169: 164: 162: 158: 154: 150: 146: 143: 139: 135: 124: 121: 113: 102: 99: 95: 92: 88: 85: 81: 78: 74: 71: –  70: 66: 65:Find sources: 59: 55: 49: 48: 43:This article 41: 37: 32: 31: 19: 1087:the original 1082: 1043: 1017:. Retrieved 1004: 993:. Retrieved 991:. p. 18 980: 969:. Retrieved 956: 945:. Retrieved 932: 921:. Retrieved 908: 897:. Retrieved 895:. p. 54 884: 873:. Retrieved 863: 852:. Retrieved 841: 830:. Retrieved 817: 806:. Retrieved 777:. Retrieved 764: 753:. Retrieved 740: 729:. Retrieved 716: 701: 690:. Retrieved 680: 666: 647: 641: 617:Control flow 557: 541: 533: 525: 434: 418: 406: 394: 382: 362: 346: 341: 337: 335: 302: 295: 272: 260: 236: 233: 212: 197: 184:machine code 177: 165: 157:out-of-order 137: 131: 116: 110:October 2023 107: 97: 90: 83: 76: 69:"Delay slot" 64: 52:Please help 47:verification 44: 850:. p. 1 409:breakpoints 204:main memory 189:clock cycle 145:instruction 1019:2023-11-04 995:2023-12-03 971:2023-11-05 947:2023-12-21 923:2023-12-21 899:2023-12-20 875:2023-12-17 854:2024-01-27 832:2023-12-30 808:2023-10-29 779:2023-10-28 755:2023-12-02 731:2023-11-17 692:2020-01-22 633:References 465:Intel i860 453:ETRAX CRIS 338:delay slot 174:Pipelining 138:delay slot 80:newspapers 521:TMS320C4x 517:TMS320C3x 413:debugging 193:Zilog Z80 1099:Category 611:See also 511:DSP and 503:and the 501:μPD77230 374:compiler 224:MOS 6502 1070:1870852 477:PowerPC 469:MC88000 461:Am29000 449:PA-RISC 238:opcodes 94:scholar 1068:  1058:  654:  545:MIPS I 513:MIPS-X 507:. The 505:VS DSP 493:RISC-V 491:, and 457:SuperH 264:branch 163:code. 142:branch 96:  89:  82:  75:  67:  1066:S2CID 1013:(PDF) 989:(PDF) 965:(PDF) 941:(PDF) 917:(PDF) 893:(PDF) 826:(PDF) 802:(PDF) 773:(PDF) 749:(PDF) 725:(PDF) 553:R3000 549:R2000 509:SHARC 485:Alpha 473:SPARC 390:write 321:write 313:write 305:write 147:on a 101:JSTOR 87:books 1056:ISBN 652:ISBN 551:and 519:and 489:V850 445:MIPS 441:RISC 386:read 365:read 325:read 309:read 291:read 287:read 279:read 275:read 252:RISC 149:RISC 136:, a 73:news 1048:doi 602:nop 587:nop 497:DSP 481:ARM 437:DSP 398:add 372:or 353:NOP 349:NOP 283:add 243:add 153:DSP 151:or 132:In 56:by 1101:: 1081:. 1064:. 1054:. 1042:. 788:^ 596:v0 593:jr 578:v1 566:v0 563:lw 487:, 483:, 479:, 463:, 455:, 447:, 344:. 178:A 1072:. 1050:: 1022:. 998:. 974:. 950:. 926:. 902:. 878:. 857:. 835:. 811:. 782:. 758:. 734:. 710:. 695:. 674:. 660:. 581:) 575:( 572:4 569:, 123:) 117:( 112:) 108:( 98:· 91:· 84:· 77:· 50:. 20:)

Index

Branch delay slot

verification
improve this article
adding citations to reliable sources
"Delay slot"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
computer architecture
branch
instruction
RISC
DSP
out-of-order
assembler language
branch prediction
central processing unit
machine code
clock cycle
Zilog Z80
arithmetic logic unit
main memory
instruction pipeline
assembly line
instruction set architecture
MOS 6502

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.