{"id":6976,"date":"2015-06-05T09:15:10","date_gmt":"2015-06-05T16:15:10","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=6976"},"modified":"2021-06-16T16:20:58","modified_gmt":"2021-06-16T23:20:58","slug":"instruction-pipelines","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/instruction-pipelines\/","title":{"rendered":"Instruction Pipelines"},"content":{"rendered":"<p>Implementation of an <em>instruction pipeline<\/em> is a common technique used when working with microprocessors. Pipelining improves operation\u00a0and processing time. Microprocessors such as the Microchip\u00ae PIC32MX460F512L\u00a0on the <a href=\"https:\/\/digilent.com\/blog\/Products\/Detail.cfm?NavPath=2,892,1218&amp;Prod=CHIPKIT-PRO-MX4\">chipKIT Pro MX4<\/a>\u00a0board\u00a0use this technology to provide efficient processing and instruction execution. Though the process is sophisticated, it is actually quite simple in concept. In my explanation of instruction pipelines, I&#8217;ll specifically refer to the\u00a0Microchip PIC32 microprocessor that I mentioned above.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_4232\" aria-describedby=\"caption-attachment-4232\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/medium-PIC32.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7469\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/medium-PIC32.png\" alt=\"medium-PIC32\" width=\"300\" height=\"300\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/medium-PIC32.png 300w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/medium-PIC32-150x150.png 150w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/medium-PIC32-225x225.png 225w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-4232\" class=\"wp-caption-text\">A <a href=\"http:\/\/www.adafruit.com\/products\/200?gclid=CjwKEAjw-ZqrBRDt_KjhjcbzhhISJAAlRGvle1D9sXkqCslgoGGmEcr5jMUt9pCF922wsgEOmIcnrBoCX3Tw_wcB\">Microchip PIC32<\/a> microprocessor.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>The PIC32 executes instructions with a 5-stage pipeline. These 5 stages are as follows:<\/p>\n<ul>\n<li>Instruction stage (I)<\/li>\n<li>Execution stage (E)<\/li>\n<li>Memory stage (M)<\/li>\n<li>Align stage (A)<\/li>\n<li>Write back stage (W)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>An instruction is fetched in the instruction stage and decoded in the execution stage. Operations are then completed in the memory stage, resulting data is aligned in the align stage, and data is written back to what&#8217;s called the register file in the write back stage. Thus, an instruction goes through 5 separate stages before all relevant operations are completed. That being said, every instruction would take 5 clock cycles to complete, assuming one clock cycle per stage. 5 clock cycles might not seem like much, especially at the PIC32&#8217;s operating frequency of up to 80MHz, but computing is all about efficiency! That is where an instruction pipeline comes in. Rather than sending one instruction at a time and waiting for all 5 stages to complete before the next instruction, a pipeline allows five\u00a0different instructions to be operated on simultaneously.<\/p>\n<figure id=\"attachment_4232\" aria-describedby=\"caption-attachment-4232\" style=\"width: 197px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/pipeline.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7494\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/pipeline.png\" alt=\"pipeline\" width=\"197\" height=\"162\" \/><\/a><figcaption id=\"caption-attachment-4232\" class=\"wp-caption-text\">A visual representation of an instruction pipeline.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Say we have instructions i-1, i-2, i-3, and so on, and refer to the diagram above. Instruction i-1 is fetched first. After one clock cycle i-1 continues to the next stage of the pipeline. As soon as i-1 is in the execution stage, the computer can fetch the next instruction, i-2. With another clock cycle, i-1 is decoded and continues to the memory stage. Instruction i-2 has been fetched and continues to the execution stage, and the computer can fetch yet another instruction, i-3. You&#8217;re probably starting to get the drift by now. Essentially, 5 instructions are managed at once, one in each stage of the pipeline. You can see from the diagram that once the pipeline is full, an instruction is completed with each single clock cycle. It is clear how this is substantially more efficient than completing one instruction every five\u00a0clock cycles.<\/p>\n<p>&nbsp;<\/p>\n<p>Lastly, to make the concept a little more clear, you can think of an instruction pipeline as, well, a pipeline. All five\u00a0stages, or sections, are filled with five\u00a0different instructions and one instruction is completed with each clock cycle. Check out the picture below.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_4232\" aria-describedby=\"caption-attachment-4232\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-7506\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic-600x245.png\" alt=\"Pipeline Graphic\" width=\"600\" height=\"245\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic-600x245.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic-225x92.png 225w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic.png 739w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4232\" class=\"wp-caption-text\">Representing the instruction pipeline with a pipeline.<\/figcaption><\/figure>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-6976 jlk' data-task='like' data-post_id='6976' data-nonce='5286a1c13f' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-6976 lc'>+1<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-6976 jlk' data-task='unlike' data-post_id='6976' data-nonce='5286a1c13f' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-6976 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-6976 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Implementation of an instruction pipeline is a common technique used when working with microprocessors. Pipelining improves operation and processing time. Microprocessors such as the Microchip\u00ae PIC32MX460F512L on the chipKIT Pro MX4 board use this technology to provide efficient processing and instruction execution. Though the process is sophisticated, it is actually quite simple in concept. In my explanation of instruction pipelines, I&#8217;ll specifically refer to the Microchip PIC32 microprocessor.<\/p>\n","protected":false},"author":16,"featured_media":7506,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1563,4326],"tags":[],"ppma_author":[4467],"class_list":["post-6976","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide","category-teaching-training"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2015\/06\/Pipeline-Graphic.png","jetpack_sharing_enabled":true,"authors":[{"term_id":4467,"user_id":16,"is_guest":0,"slug":"wwadkins","display_name":"William Wadkins","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f23af17e3f0aa5cdce4db10c96eb005614c30853a9579a999104e070cf86df4c?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/6976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=6976"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/6976\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/7506"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=6976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=6976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=6976"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=6976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}