FANFNA
    • 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
    • Make a copy
    • 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 Make a copy 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
    # Hazar [TOC] ## Structural hazards(Source hazard): :::danger - **CPI:** - **1.23+0.1(N–5)~N=stage-per-pip~** - **Time cycle per ins**: - **T~c~=(740/N+90)~N=stage-per-pip~** ::: :::success **HW** cannot support this **combination of instructions** :::info (**single** person to fold and put clothes away) **<font color = 'red'>不同指令同時對某硬體做存取</font>** ::: ## Data hazards: :::success Instruction depends on result of prior instruction<font color = "red"> **still in the pipeline (missing sock)</font> 當管道因為某一步驟必須等待其他步驟而停滯,起因於兩道指令俱有<font color = "red">*相依性*</font>** also call it **data dependency** ::: ![](https://i.imgur.com/G2P9YzH.png) :::info ### 1. Read after write (RAW) **(i2 tries to read a source before i1 writes to it)** A read after write (RAW) data hazard refers to a situation where an instruction refers to a result that has not yet been calculated or retrieved. This can occur because even though an instruction is executed after a prior instruction, the prior instruction has been processed only partly through the pipeline. :::warning **Example** ![](https://i.imgur.com/ASNJEBC.png) The first instruction is calculating a value to be saved in register R2, and the second is going to use this value to compute a result for register R4. However, in a pipeline, when operands are fetched for the 2nd operation, the results from the first have not yet been saved, and hence a data dependency occurs. A data dependency occurs with instruction i2, as it is dependent on the completion of instruction i1. ::: :::info ### 2. Write after read (WAR) (i2 tries to write a destination before it is read by i1) A write after read (WAR) data hazard represents a problem with concurrent execution. :::warning Example For example: ![](https://i.imgur.com/GrsPXGB.png) In any situation with a chance that i2 may finish before i1 (i.e., with concurrent execution), it must be ensured that the result of register R5 is not stored before i1 has had a chance to fetch the operands. ::: :::info ### 3. Write after write (WAW) (i2 tries to write an operand before it is written by i1) A write after write (WAW) data hazard may occur in a concurrent execution environment. :::warning Example For example: ![](https://i.imgur.com/ui8pRL2.png) The write back (WB) of i2 must be delayed until i1 finishes executing. ::: :::danger ### 解決方案: 1. 加入low cost to implement 2. reduces **[IPC](https://en.wikipedia.org/wiki/Instructions_per_cycle)** 3. Minimizing RAW stalls 4. 可使用forwarding解決 5. load-use data hazard,即使使用forwarding還是要stall一個cycle 6. code scheduling 可避免hazard ::: ## Control hazards (branch hazards): :::success Caused by delay between the fetching of instructions and decisions about changes in control flow (**branches** and **jumps**). ::: :::info **Hazar會發生** 1. Branch jump to new MEM location 2. invalidating all prior stages in the pipeline(之前所有的`PIP`指令都不見了) ::: :::danger ### **避免 control** hazards microarchitectures can: - insert a pipeline **bubble[^comparison]** , guaranteed to increase **latency** - Branch Prediction:先做錯了再換 :::warning 1. Not Taken 2. Static Branch Prediction:根據跳躍類型預測,例如loop猜會往回跳,if猜往前跳 3. Dynamic Branch Prediction:會考量每一個分支指令的特性,程式運作過程中會改變對一道分支的預測,假設之後的Branch會照著「趨勢」走。 (**OPT ALGO**) ::: :::info - 但是使用這些解決方案都會造成能源的浪費 - 效能下降(因為要回復這些錯誤的訊息) ::: ## 補充: ### [Bubbling](https://en.wikipedia.org/wiki/Pipeline_stall) :::warning - Bubbling in the pipeline, <font color ="red">可稱為 a **pipeline break** or **pipeline stall**</font>, is a method to <font color ="red">包含 **data**, **structural**, and **branch** hazards</font>. As instructions are fetched, control logic determines whether a hazard could/will occur. ::: :::info If this is true, then the control logic inserts no operations (**NOPs**) into the pipeline. Thus, before the next instruction (which would 發生 `hazard`) ::: ### 結語 :::success executes, the prior one will have had sufficient time to finish and prevent the hazard. If the number of NOPs equals the number of stages in the pipeline, the processor has been cleared of all instructions and can proceed free from hazards. All forms of stalling introduce a delay before the processor can resume execution. ::: ::: :::info 補充 Which of the following statement **is correct**? (a) Pipelining improves the performance of a processor by <font color="red">decreasing the latency</font> of a job (e.g., an instruction) to be done. (b) The more balanced pipeline stages a specific datapath has, the higher performance this pipelined datapath can achieve. (c) Every single instruction, when being executed in a <font color ="red"> n-stage</font> pipelined datapath, consistently. **single ins 都是在單一stage完成** needs n clock cycles before its execution is completely done. (d) It is likely to have fewer hazards and less severe impact of hazards(STR) with deeper design of pipelining (i.e., more pipeline stage).**more pip more hazard 產生** (e) The number of pipeline stages monotonically [deep pip](https://www.sciencedirect.com/topics/computer-science/pipeline-stage) :::spoiler Answer: (b) 註:正在n-stage pipelinedatapath中被執行的單一指令,在完成執行前所需的clock個數小於n ::: [^comparison]: [Bubbling](https://en.wikipedia.org/wiki/Pipeline_stall)

    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