P76095018
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Quiz 5 Annotation ### Quiz5 Links https://hackmd.io/@sysprog/arch2021-quiz5-sol <!-- Reference https://hackmd.io/@shauming1020/ca-quiz5 [Quiz-5_marks.xlsx](https://www.youtube.com/watch?v=dQw4w9WgXcQ) --> ## Problem A Consider the G circuit, depicted on the following. ![](https://i.imgur.com/P70tOER.png) Since the G circuit is currently only combinational, you know exactly what to do: Pipeline it. 1. For your first iteration, you decide to start small with a two-stage pipeline. Using the diagram below, please show a two-stage pipeline with maximal throughput using a minimum number of registers. Calculate the overall throughput and latency of your circuit. ![](https://i.imgur.com/H50esh6.png) - Latency (ns): __ A01 __ - Throughput (1/ns): __ A02 __ - A01 = 24 - A02 = 1/12 ### 📝 Annotate :::info #### Why the stages is arrange like this? To create a pipeline with maximal throughput, we need to split the circuit into stages while trying to reduce the differences of latency within stages. ![](https://i.imgur.com/ql1cGOM.png) In the split above, the maxmium latency of stage 1 (on the left side of the circuit) is: **2 + 5 + 3 + 1 = 11ns** And the maxmium latency of stage 2 is: **7 + 1 + 4 = 12ns**. The difference of maxmium latency between two stage is 1, which is small enough to maximized this pipeline throughput. #### How to calculate Latency and Throughput? Latency = Maxmium value of slowest path in all stages * number of stages If we split the stage into two as follows: ![](https://i.imgur.com/Nk5dYAH.png) **The Latency is equal to 12 * 2 = 24 ns** Throughput is equal to 1 over the Maxmium value of slowest path in all stage (which is 12 in this case), hence the value of throughput in this circuit is **Throughput = 1/12 ns** ::: 2. Now, you decide to add an additional stage. Using the diagram below, please show a three-stage pipeline with maximal throughput using a minimum number of registers. Calculate the overall throughput and latency of your circuit. ![](https://i.imgur.com/8rc8FIp.png) - Latency (ns): __ A03 __ - Throughput (1/ns): __ A04 __ - A03 = 30 - A04 = 1/10 ### 📝 Annotate :::info The three stage is draw like followings. ![](https://i.imgur.com/OsmlO1y.png) Then we can calculate the maximum latency in each stage as follows. ![](https://i.imgur.com/GZTLhT0.png) **Latency = Max(10, 8, 5) * 3 = 10 * 3 = 30ns** **Throughtput = 1/10 ns** Also notes that if you split the stages like so, it will not work as some stage output is pointing to the previous stage. ![](https://i.imgur.com/R0RRgEC.png) ::: 3. Then, think of the maximalthroughput pipeline. Using the diagram below, please show a pipeline that maximizes the throughput using a minimum number of registers. Calculate the latency and throughput of your circuit. For full credit you pipelined circuit should use the smallest number of pipeline stages required to achieve maximum throughput. ![](https://i.imgur.com/k3yhddE.png) - Latency (ns): __ A05 __ - Throughput (1/ns): __ A06 __ - A05 = 28 - A06 = 1/7 ### 📝 Annotate :::info The stages are arranged as follows. ![](https://i.imgur.com/96MlRZW.png) The maxmium latency in each stage is as follows. ![](https://i.imgur.com/0KXiRlY.png) **Latency = Max(7, 7, 5, 4) * 4 = 7 * 4 = 28ns** **Throughtput = 1/7 ns** ::: ## Problem B Assume that we are trying to build a RISC-V processor. For the reference purpose, there are two 5 stage (IF, DEC, EXE, MEM, WB) bypassing processors. However, they are a little broken. The processors are as follows: Processor 1: A defective 5 stage bypassing processor which does not annul instructions following branches. Processor 2: A defective 5 stage bypassing processor that reads all values bypassed back as 0 but reads correctly from the register file. Known properties: Both processors always predict that branches are not taken (they always fetch from PC + 4). Both processors determine the direction of the branch in the EXE stage. We try this simple RISC-V looping code on both of these processors. Assume at the start of the code that x2 is set to some number greater than 0 and that all the other registers are set to 0. ```=asm L1: addi x1, x2, -4 bnez x1, L1 slli x3, x1, 1 lw x2, 0x100(x0) . = 0x100 .word 0x4 ``` 1. If we had a fully working 5 stage bypassing processor, which always fetches from PC + 4 and annuls instructions following taken branches, how many cycles would it take for one iteration of the loop? Assume that the bnez is taken. Provide the number of cycles per loop iteration. - B01 = 4 ### 📝 Annotate :::info Under normal conditions, the bnez will flush the instruction in EXE and DEC stage and replace it with NOP ![](https://hackmd.io/_uploads/r1YMBJhYK.png) ![](https://i.imgur.com/phMdlJ0.gif) ::: 2. If we pass the number 0x10 into x2, by the time the second iteration’s addi reaches EXE, what value will be passed to x1 for each of the two defective processors? If the loop does not make it to a second iteration’s addi, write N/A. - B02 = 0 ### 📝 Annotate :::info In processor 1, as the instructions following bnez will not be replaced with NOP, the cycle will continue without jumping to the start of the loop. ![](https://hackmd.io/_uploads/rJsVIk3YF.png) Tthe slli and lw instructions are not annulled thus x2 = 4 in the second iteration of the loop and the addi then sets x1 = x2 – 4 = 0. ![](https://i.imgur.com/Ur097IV.gif) ![](https://i.imgur.com/4lnjZaf.png) ::: - B03 = N/A ### 📝 Annotate In processor 2, on the first iteration of the loop the ```bnez``` reads the bypassed value of ```x1``` which is incorrectly bypassed back as a ```0``` so it immediately exits the loop and never gets to the second iteration ![](https://i.imgur.com/eXVWkSI.png) ``` addi x1, x2, -4 bnez x1, L1 <-- x1 is read as 0 when exec ``` ## Problem C Since having full bypassing can be very costly, we attempt to reorder the instructions in this loop so that we can minimize the total number of cycles per loop iteration while using a single bypass path. ```=asm loop: slli a4, a3,5 or a5, a0, a7 xor a3, a4, a2 add a1, a2, a3 sub a6, a5, a2 blt a6, a2, loop ``` We can change the order of the instructions in the program as long as it does not change the final result. In what order would you execute the 6 instructions in the loop so that you only need a single bypass path? 1. Here, we select EXE → DEC bypass path. Please list the opcodes in order of execution: __ C01 __ (split in comma) Acceptable Answers: - slli, xor, add, or, sub, blt - or, slli, xor, add, sub, blt - or, sub, slli, xor, add, blt ### 📝 Annotate :::info Let say we have the EXE → DEC bypass path. That means for any operations that involve arithmetic can follow each other during execution as soon as it did not change the execution sequence that involve registers that has been edited in the previous instructions. ![](https://i.imgur.com/P6CymTt.png) Hence, any sequence that satisfy the followings should be correct. ``` slli → xor or → sub xor → add sub → blt ``` ![](https://i.imgur.com/rlhy7Dz.png) ::: 2. Now, suppose we are offered another processor. This processor is identical to the processor used above with full bypassing, except that it can make branch decisions in the decode stage rather than the execute stage. The disadvantage is that this increases the clock period from 400 ps (before) to 450 ps (with the branch calculated in decode). Which processor is faster (old: branch decision in EXE and tCLK = 400ps, new: branch decision in DEC and tCLK = 450ps)? __ C02 __ - C02 = new ### 📝 Annotate :::info The number of cycle count reduced from 8 to 7 as the ```blt``` instruction is being done in one stage eariler in the new processor. Old: 8 (400 ps) = 8 * 400 = 3200 ps to execute the loop. New: 7 (450 ps) = 7 * 450 = 3150 ps to execute the loop. Thus, new is faster. ::: ## Problem D Consider the following C code: ```=c int price[6] = {7, 5, 8, 10, 15, 7}; int maximum = 10, c = 3, t = 5; for (int i = 0; i < 6; i++) { if (price[i] > maximum) maximum = price[i]; } int total_cost = maximum + c + t; ``` Then, the translated RISC-V assembly: ```=asm // x4 = 0x24 - length of price in bytes // x5 = 0x3 - c // x6 = 0x5 - t // x7 = 0xA - maximum // x1 = 0x400 - address of price[0] start: addi x2, x0, 0 slli x2, x2, 2 loop: add x8, x2, x1 lw x3, 0(x8) bge x7, x3, skip mv x7, x3 ori x7, x7, 0 skip: addi x2, x2, 4 blt x2, x4, loop add x7, x7, x5 add x7, x7, x6 ``` Assume the registers are initialized to the values specified in the assembly code comments. In the following five-stage pipelined RISC-V processor (IF, DEC, EXE, MEM, WB): - All branches are predicted not-taken. (Always fetch from PC + 4). - Branch decisions are made in the EXE stage. - The pipeline has full bypassing. - The processor annuls instructions following taken branches. - Assume that in the first iteration of the loop both branches are taken. 1. How many cycles did it take to execute the first loop iteration on this processor? Make sure not to include the first two instructions at label start in your cycle count. Cycles to execute first iteration of the loop on this processor: __ D01 __ - D01 = 11 ### 📝 Annotate :::info Following the logic of the instruction, when executing the bge instruction, the register values are as follows. ![](https://i.imgur.com/ym4Ct9C.png) Hence, it skips to the "skip:" label and end the first loop at cycle 11. ![](https://i.imgur.com/drkxXKX.gif) ![](https://i.imgur.com/jQjkLNY.png) ![](https://i.imgur.com/V7z4MCW.png) ::: 2. If you could modify your fetch stage to always fetch the correct next instruction instead of predicting all branches not taken, how many cycles will it now take to execute the first iteration of the loop on this modified processor? __ D02 __ - D02 = 7 ### 📝 Annotate :::info There are totally 4 NOP inserted into the pipeline during the execution of first loop. There are inserted after ```bge``` and ```blt``` instruction. Removes both branch annulments, so the total of 4 cycles can be saved, making the cycles per iteration 11−4=7. ::: 3. Now, let’s change this processor without bypassing. That is, all data hazards are resolved by stalling. How many cycles did it take to execute the first loop on this processor? __ D03 __ - D03 = 24 ### 📝 Annotate :::info If all data hazards are resolved by stalling, the following pipeline diagram will appears ![](https://i.imgur.com/Cgcbx4U.png) Without bypasses, there is a 3-cycle penalty for each EXE → DEC bypass used in the bypassed pipeline, and a 1-cycle penalty for every WB → DEC bypass used. In previous question, there were 4 EXE → DEC bypasses and 1 WB → DEC bypass, so cycles=11+4×3+1×1=24. And it will takes 24 cycles to finish the first loop. ![](https://i.imgur.com/ZaGx0X5.gif) ::: ## Problem E Given the standard RISC-V datapath, determine if the following is implementable or not without any additional functional units? Assume the instruction is not a pseudoinstruction encoding. ![](https://hackmd.io/_uploads/Hy84rehKt.png) 1. Consider the new instruction isnull rd, rs1 which check if an input given through rs1 is considered NULL or not by C standard. The result is returned through rd as a bit. Is it Implementable? __ E01 __ (Answer in Yes or No) - E01 = Yes 2. What changes would you need to make in order for the instruction to be able to execute correctly? Assume all modifications and additions are done on top of the existing single cycle datapath. Select all that apply. __ E02 __ (Anwser in the items and use comma to split) - a. Modify Branch Comparator logic. - b. Modify the control signals to the ALU. - c. Modify the control logic for the Branch Comparator. - d. Modify ALU buses. - e. Modify the control logic for WBSel. - f. Add additional control signals for the writeback mux. - g. Modify control logic for ALU/ALUSel. - h. Modify the control logic for parsing instr[31:0]. - i. Add an additional comparator. - j. None of the above. - E02 = c,e,h ### 📝 Annotate :::info ![](https://i.imgur.com/2NbhLoC.png) The pipeline needs the following modification in order to support the new instruction. (Read more over [here](https://inst.eecs.berkeley.edu/~cs61c/sp21/pdfs/exams/Sp21_Final_Solutions.pdf)) ::: 3. ```isnull rd, rs1``` is not in a standard RISC-V instruction format; as we are attempting to reduce the number of hardware changes in our datapath. We instead choose to implement our instruction as a pseudoinstruction in the following format. Which of the following statements is true? Assume earlier changes propagate. Select all that apply __ E03 __ (Anwser in the items and use comma to split) - a. We need to provide a second argument x0 when calling the instruction and modify the control signals - b. We need to provide a second argument x0 as a comparator for all branch comparisons. - c. It is impossible to represent as an R-Type instruction - d. We need to wire x0 as a comparator for all branch comparisons. - e. We need to wire x0 as rs2 and modify the control signals. - E03 = e ### 📝 Annotate :::info Null is ```\0``` in C which is equal to all 0 in a byte. Hence, to check rs1 is Null, you just need to check if the rs1 bytes are all 0. ::: ## Problem F Much of the assembly code she writes involves iterating through arrays of integers. Instead of using several instructions to calculate the address of the next element, we propose a new instruction, iarrn rd, rs1, rs2 which places into rd the address of the rs2-th element of the array pointed to by rs1. This instruction does not do bounds checking and it assumes the size of an integer is 4B (32 bits). Do not assume this instruction belongs to a specific type. In verilog, the instruction is described as follows: ``` R[rd] = R[rs1] + (4 * R[rs2]) ``` 1. We are interested in modifying our RISC-V datapath to support this instruction. Assume we have introduced a new control bit “IArrN” which is 1 when the current instruction is iarrn and 0 otherwise. Using the datapath below, fill in the following table with the rest of the control bits for this instruction. If the control bit can be set to *, please draw an X in the table below. ![](https://hackmd.io/_uploads/H1GPMWnKt.png) | IArrN | PCSel | RegWEn | MemRW | WBSel | BrUn | ALUSel | |:-----:|:-----:|:------:|:-----:|:-----:|:----:|:------:| | 1 | F01 | F02 | F03 | F04 | F05 | ADD | - F01 = 0 - F02 = 1 - F03 = 0 - F04 = 1 - F05 = X ### 📝 Annotate :::info - ```PCSel``` = 0 because it is executing a non jump / branch instruction - ```RegWEn``` = 1 because this instruction contain a write target rd - ```MemRW``` = 0 because it is not writing into the data memory, its result is outputting from ALU instead of Data Memory after the ```4 * R[rs2]``` operation - ```WBSel``` = 1 because it is writing back to rd from ALU result - ```BrUn``` = X because this is not a branching operation ::: 2. This instruction involves changing a few hardware pieces on the datapath in addition to changing control bits above. We propose modifying the ASel and BSel muxes, and their associated control bits (circled below). ![](https://i.imgur.com/mwxgSVq.png) How should we change ```BSel``` to allow our new instruction, and all other RISC-V instructions, to execute correctly? Select one __ F06 __ ![](https://i.imgur.com/ZRzLVxI.png) ![](https://i.imgur.com/2oHRLis.png) ![](https://i.imgur.com/LnhtuvR.png) ![](https://i.imgur.com/wmnJmTp.png) ![](https://i.imgur.com/o9FtMc5.png) - F06 = A ### 📝 Annotate :::info By transforming the description to sequential logic block diagram, you can easily spot either A or D is the correct solution as other circuit combination cannot produce the desire output. ```IArrN``` default should be ```0``` as it is a new input where other instruction do not support. Hence, ```IArrN``` should only be switch to new logic block if it is set to ```1```. Thus, A is the answer. ::: 3. Following the previous quetion, how should we change ``ASel`` to allow our new instruction, and all other RISC-V instructions, to execute correctly? Select one __ F07 __ ![](https://i.imgur.com/jA3t6ZQ.png) - F07 = A ### 📝 Annotate :::info We don't need to change the ```ASel``` for the new instruction. Hence, A is the correct answer. Notes: The original block diagram's ```rs1``` (0) and ```PC```(1) is flipped upsidedown compare to the one shown in A, but they behave the same. :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully