Maxwill Lin
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Computer Organization author: Yan-Tong Lin tags: NCTU, 2020 --- # Computer Organization [TOC] ## Labs * [Computer Organization lab 0](/91w4a3v2TtqfwihAk-1ccQ) * [Computer Organization lab 1](/ZLYhJj6BRgSIQz9daM9OZA) * [Computer Organization lab 2](/8HEfOozyQau8GKq4SUOxQw) * [Computer Organization lab 3]() * [Computer Organization lab 4]() ## Notes ## HDL (2020/3/12) [HDL gitbook](https://hom-wang.gitbooks.io/verilog-hdl/content/index.html) [HDL note](/ZRHSG6oUQ7-xzc4YO3irkg) ## Ref - Verilog [Ref - Verilog](https://hackmd.io/@dppa1008/Logic_Design_Mak?type=view) ## Week 2-2 (2020/3/12) ### Instruction Sets - Chapter 2 #### Difinition and General * An agreement between architects and machine language programmers * types of instructions * data movement(load/save) * data processing(ALU) * branch #### Different IS * RISC-V ::: spoiler ![](https://i.imgur.com/8xXJvOd.png) * format * Coding * R(register) * I(immediate) * S(store) * SB(branch) * U(upper immediate) * function code 7/3 * Register r1, r2 * Immediate Value ::: * arm * android, most popular 32-bit IS * conditional code everywhere => execution in a row * format : DP(data process)/DT(data transfer)/BR(branch) * x86 - old IS #### Concepts ##### Memory Layout * branch, jump and link * stack * array :::spoiler ![](https://i.imgur.com/5mR4xYZ.png) ![](https://i.imgur.com/txoLqbM.png) ::: * rd - * PC - Program Counter * sp - stack pointer ### Performance - Chapter1 #### * Execution Time * Elasped Time V.S. CPU time * CPU Time = System CPU + User CPU * $Performance = \frac{1}{Execution\ Time}$ * $Execution\ Time = Instruction\ Count * CPI * Cycle\ Time$ * ![](https://i.imgur.com/prI521e.png =50%x) ## Week 3-2 Computation ### 2th Complement ### ALU #### full adder #### comparisons #### carry lookahead ## Due to the cronovirus outbreak, the future classes will be online ## Week 5-1 Data Path(Cont.) (3/30 online) - 3/30 Quiz 4 - Because if the mux doesn’t matter, it won't affect the result, and we want to emphasize that by giving it x(don’t care). - 3 cases: - Reg/MemWrite => If write options are open when they should not be open, it will result in undesired write, which will cause errors; - MemRead=> Memory reading is a more high-cost task, and it doesn’t always happen; though it doesn’t affect the result, we don’t want to keep it open; - RegRead is not controlled because it almost always happens. - Q: why there is immediate shift 1 - A: for shorter IS design and PC+2 ![](https://i.imgur.com/IZLUngE.png =70%x) ## Week 6 - 4/9 quiz - A1: ld, sd(ex: ld x0 (8)x1) use x1+8 as memory address => need ALU to do addition, add instruction needs add. - A2: beq use ALU substraction to see if it produces zero output, substruct instruction needs substract. - wonder if zero is bitwise nor as I guess - [data path reference](https://cseweb.ucsd.edu/classes/su06/cse141/slides/s06-1cyc_control-1up.pdf) ### Chap 4-1 - Datapath - MISC vs RISC-V - Control vs Mux - Dont care? ### Chap 4-2 - Pipeline ## Week 7 - 4/13 class ![](https://i.imgur.com/iEzNMmb.png =70%x) ### Risc-V pipeline 1. IF: Instruction fetch from memory 2. ID: Instruction decode & register read 3. EX: Execute operation or calculate address 4. MEM: Access memory operand 5. WB: Write result back to register ### Pipeline registers are required ### Design - structural hazards: resource conflicts, e.g. only one memory - sol: adding more resource - control hazards: need to worry about branch instructions - sol: resolve earlier, predict branch - data hazards: an instruction depends on a previous instruction - sol: forwarding, bypassing ### write Reg changes before apllied ![](https://i.imgur.com/ufFkopl.png =70%x) ### Corrected Datapath ![](https://i.imgur.com/VzBd8i0.png =70%x) ### 2020/4/13 quiz ![](https://i.imgur.com/p7Zcm6O.png =70%x) 1. write reg and write data is inconsistent 2. fix by passing write reg information along with datapath and apply when is actually needed(Write Back stage) ### Pipeline Control ![](https://i.imgur.com/QRN2qMP.png =70%x) ### Data Hazard and its solutions #### Stall detection #### Data Forwarding ![](https://i.imgur.com/m47NZ23.png =70%x) Note: above by 2020/4/13, including peeking ## Week 7-2(Online Class) ### Online Class Q: Why immediate gen at that pos - pros - no critical path(more important) - cons - more use of pipeline register ### beq - zero-flag is critical path - so beq address is passed back to PC in 4th cycle ### Data Dependency => Data Hazard ### Solutions to Data Hazard - Stall - ex: software: nop(no op) - Data forwardind/by-passing - pros: no stall - cons: path add mask, forward unit to check dependency. ### Quiz 4/16 ![](https://i.imgur.com/8o1Z5tX.png =50%x) A: 1. To solve data hazard caused by data dependency. 2. need to add additional option for ALU input and add forward unit for control; thus will bring more cost to critical path ## Week 8-1 ### Quiz 4/20 ## Week 9 ### Quiz 4/30 1. original + 7+4, load data hazard => +2 2. first load*2, then add*2 (... ld x2, ld x4, add x3 x1 x2, add x5 x1 x4 ... ) --- ## Week 11 - Midterm score out : 103.5(mean 73.61) ### Quiz 1. reduce the time of loop control 2. avoid data dependency 3. 14/8, for solving hazards ## Week 12 - Memory Hierarchy ### Quiz ## Week 13 CO 5/25 quiz 17 1. has a lower missing rate and can use more cache strategy 2. LRU Replacement, by the name of it, replace the least recently used cache set with the new one 3. No, there are trade-offs, we should choose the appropriate one depending on the situation 4. disadvantages: (a)larger tag storage (b)larger decoder/mux to load larger tags © bigger hardware/power consumption (d) increase access time --- ## Week 15 - Before Final ### Important - CPU, MEM(DMA), IO ### IO interrupt / pulling / DMA ![](https://i.imgur.com/HGgbhVd.png) ![](https://i.imgur.com/3OYfYTb.png) ### DAM(exam ) - between IO and CPU - Delegating I/O Responsibility from the CPU ![](https://i.imgur.com/GDhFEGo.png) #### Problems - Cache May change - VM is not spacial contious (because of hash) ### RAID - correction - --- ## Week 16 - Before final exam, self study - https://hackmd.io/@sysprog/H1sZHv4R#%E7%AC%AC22%EF%BD%9E26%E8%AC%9B-Memory-78 - https://sites.google.com/site/nutncsie10412/ge-ren-jian-jie/ji-yi-ti ## Pipeline ### EX hazard / Mem hazard ![](https://i.imgur.com/Cdz6fB8.png) - EX > Mem (more direct) - Mem need to add !Ex to condition - check register write - Ex: - Ex/Mem.RegWrite - Mem: - Mem/Wb.RegWrite - check not 0 register(const) - check register out = register in - Ex: - ID/Ex.RegRs1 == Ex/Mem.RegRd - Mem: - ID/Ex.RegRs1 == Mem/Wb.RegRd ### load-use hazard ![](https://i.imgur.com/cpWysRY.png =70%x) ![](https://i.imgur.com/3sf1SHw.png =70%x) ![](https://i.imgur.com/O6gcFES.png =70%x) - use load result - deal at "IF/ID" - things to do: - No OP (set control = 0) - No IF write - No PC write - condition - is mememory read - ID/EX. MemRead - load use - IF/ID. RegisterRs1/Rs2 == ID/EX.RegisterRd ### Quick summary ![](https://i.imgur.com/hITg3bn.png =70%x) ![](https://i.imgur.com/N6hrM3Y.png =70%x) --- ### branch hazard - Naive - move to 1st/2nd cycle - Delayed Branch - delay slot and software istruction scheduling - Dynamic Branch Prediction - 1 bit/2 bit Branch-Prediction Buffer - Correlating bpb - BPB + BTB ---- ### General BPB(branch prediction buffer)(a.k.a BHT) - History Table of T/NT(not taken) - in IF - guess by history - may reach 90% accuracy if well designed - if wrong, flush pipeline(costly) + flip prediction ### 1-bit BHT ![](https://i.imgur.com/TzJdXTZ.png =50%x) - branch target address k bits(middle close to end) hash to 1 bit - can add beq/bne op-code to hash table? - NO ![](https://i.imgur.com/WYSARwM.png =30%x) - can store additional "last" PC, no need - weakness: - example: double loop ### 2-bit ### BTB(branch target buffer) (5/7 on 6/17) - to avoid IF that get the target of branch - store current PC + taget PC - since current PC has to be a branch!!! - (we cannot wait for IF now) - teacher's error? (in BHT + IF case, isnt dont care 1/0 error, but can see decode - can by-pass IF if save instruction istead of PC' ### Note BHT and BTB work together - BHT for T/NT - Q: is branch target address PC'? - PC' => T/NT - BTB for address - PC => PC' --- ## Exception Handling - flush pipeline - to handle routine - save address of offending address - !!! **precise interrupts** - complete prior istructions(is) - stop offending is - flush all following is ## Instruction Level Parrallelism (ILP) - EXE time = IS per program * Clock per IS(CPI) * clock time - Deeper Pipeline - modern CPU ~20 - IPC * stage - Multiple Issue Processor - PC = PC+8 - IPC * 2 - static/dynamic at run time or pre decision - static (VLIW, very long instruction word) - compiler - predecided which to send - dymanic (superscalar) - newer work - hardware - decide which to send on runtime - what wil be duplicate? - ALU, immediate-gen - Register 2R1W => 4Read2Write - Multiple Issue Cont. ![](https://i.imgur.com/FL0M9hh.png) --- ## Memory ![](https://i.imgur.com/A5nhXcL.png) ---- ### Hardware - SRAM - sparse, fast, higher power, expensive - power on => work - logic gate - DRAM - dense, slow, lower power, inexpensive - need refresh - 2d matrix - Disk ---- ### Hierachy - Block - the minimal fixed size for moving - also named "page" in VM - Why work - 90%-10% rule - Locality - temporal - spacial - settings - Terms - block - hit - miss ---- ### Direct Map Scheme - trivial - idex/tag(32-2-bit index)/data - Q: why -2 when 4B data ---- ### Set Associativity - set size * set num = cache - one address can save to more places(in the set) than direct map(1) - seach in set(set size) ---- ### Calc ![](https://i.imgur.com/I20CB7c.png) - K is 1024 ![](https://i.imgur.com/AbEMzN7.png) ---- ### AMAT(5/25) ![](https://i.imgur.com/WHV14z6.png) ![](https://i.imgur.com/Sj154Tg.png) ![](https://i.imgur.com/UWURNN2.png) ![](https://i.imgur.com/MqGsnTf.png) - associative too high => cycle time up #### Block Size (5/21) ![](https://i.imgur.com/knB9WOe.png) - spatial => bigger better - temporal => cant be too big(for num of block down) - ~64B #### Associativity - if up - adv: - reduce conflict(more flexible placement) - inclusion property (teacher say follow LRU??) - $1way \suset 2way ...$ - disadv: - num of set down - cycle time(for compares and mux => critical path) - ~4 way ![](https://i.imgur.com/SkTFfQn.png) ![](https://i.imgur.com/PDYcmc6.png) #### replacement policy - LRU ### Conclusion(Miss Rate Improvements) ![](https://i.imgur.com/aXKx7ul.png) ### miss penalty improvement(5/28) - multi level - L1, L2 - calc - can optimize saperately with different size of L1, L2 - larger block/associativity in L2 - the concept can be used for split/unified mem too ### Bandwidth (Bus size / Interleave) ![](https://i.imgur.com/ShT0ECB.png) ![](https://i.imgur.com/zB0yVEM.png) ---- ### Write Back (6/1) - dirty bit ---- ### VM - page --- ## Chapter 6 - Parallel Process, Client to Cloud / Storage Bus IO ### multi CPU and speed up ### Instruction and DATA stream ![](https://i.imgur.com/TOGcJ2F.png) #### Vector Processor / GPU (SIMD) #### Multithreading (MIMD) #### SMT(6/8) - simaltenous mt - shared thread - different from issue by switching ![](https://i.imgur.com/IlmV3Xn.png) #### SMP - shared data(mem)

    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