湯镸
    • 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
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # (二)午 計算機組織 ## class1:課程大綱 湯湯 [Toc] 組合語言:RISC-V第五代精簡指令集 symbolic machine code:符號機器碼 系統程式包含 complier assembler linker loader >### logic gate >combinational element : adder sequential element : register * 各種邏輯閘review * 加法器:算術邏輯單元最基本零件 * 逢紐曼架構:stored procedur ### 指令集結構 交響曲的譜 硬體是樂器 組合語言 透過 指令集結構ISA 變成機器語言 >program content程式計數器 >### 轉換組合語言六種格式 >![](https://i.imgur.com/HUPY22k.png) >imm 立即值 就像常數 >funct 功能碼 -------------------------------- CISC 複雜指令集 vs RISC 精簡指令集 cisc 程式碼精簡 支援可變長度的指令ex32 64 128位元 因此需要用到 分段暫存器:補上沒滿的段落 多時脈週期multi-clock會很長 偏重記憶體到記憶體之間m to m 程式碼小 clock快 管線化 暫存器到暫存器 固定指令長度 程式碼 cpu 週期 時脈週期clock cycle執行一個回合 ### Pipeline ![](https://i.imgur.com/Q6GTAKF.png) Superscalar超純量 執行時間一樣 但增加產量 ------------------------------------------------------- UNIT1 --- > [time=Tue, Feb 7, 2023 2:15 PM] 2nd class ### 計算機演進 * The first computer:ENIAC 把程式跟資料存在卡上 =>stored procedure : program、data MIPS 每秒百萬指令數 Millions of Instructions per Second - Performance : throughput工作量、latency延遲時間-速度 - Algorithm - Programming language,compiler,architecture - processor and memory system - I/O system (OS including) * ## ==Five Classic Components== ![](https://i.imgur.com/wYEzVo7.png) ### ==Integrated Circuit Cost== ![](https://i.imgur.com/TGZTNYM.png) ![](https://i.imgur.com/JNK4Ee1.png) ### 有關Proformance : CPI及clock之類的東西 * Performance ∝ 1/time * Elasped time = Total Responce time 1. Procesing time =>==CPU time : user、 system== 2. I/O time 3. OS overhead time 4. idle time * 時間表示 ![](https://i.imgur.com/svsMxic.png) * CPU time = CPU clock cycles * clockcycle time = CPU clockcycles/clock rate ![](https://i.imgur.com/9WY8rBI.png) * 進行的時脈周期數(Clock Count)=指令數(IC) x 每個指令進行的時脈周期數(CPI) Avg CPI=總進行的時脈周期數Total C.C/總進行的指令數(IC) sequence序列 序列的數字指的是那個序列的行數 ![](https://i.imgur.com/0o6t7h0.png) ![](https://i.imgur.com/RKGaUjK.png) 功耗 ![](https://i.imgur.com/g1dxv4P.png) disspated power : 靜態+動態功耗 * ++Paralled programing++ 平行運算 看數學 programer:軟體 =>交給CUDA 分配給各個核心Load balancing、各CPU的溝通及同步 instruction level paralled => 跟programmer無關 * ++Superscalar超純量++:同一個指令 塞更多指令進去 SIMD Superpipelined超管線化:從cpu的角度去切割 讓piping這件事的功能最大化 * 阿姆達爾定律 加速 元件買多一點 他就加速了 只是每個階段加速的幅度不太一樣 ![](https://i.imgur.com/7NTttSu.png) ----------------------------------------------------- UNIT2 --- Computer Architecture = ??? ### Translating to Assembly Operators運算子:+/ -* Operands運算元:123abc 所有的Operands、程式都在記憶體裡 Load是從記憶體到暫存器 Store是從暫存器到記憶體 右邊給左邊 #### Stored program #### 指令 #### ISA 可以用來做很多事 不同CPU有不同的指令集結構 曲目 ISA的組成 >Register暫存器 memory記憶 Addressiy定址 Datatype資料型別 Datastructure資料結構 Instruction Format >>ALU >>Control transfer >>EXceptional handling #### 指令分類 set definition Register --- word 其實很多都是Load / store 但有很多的版本 * load word(32)、load double(64)、load byte(8)、load halfword(16)/store * RISC-C載入暫存器的長度都一樣 乘法的實現 : shift ex:向左偏移shift left-* 向右偏移-/ 課本p70 ![](https://i.imgur.com/LGhDdVX.png) RISC-V * CPU設計的規則 : 簡單導致規律 ![](https://i.imgur.com/mPqqhXj.png) 運算元:七個 temp暫時暫存器 暫存器的規範 ![](https://i.imgur.com/NXQQ6is.png) ABI Global pointer:全域指標暫存器 stack裡面用 stack pointer,選stack 用它 暫時變數暫存器Temporary:x5-7 ,x28-31 ABI name 都是t開頭 t0-6 宣告的變數暫存器Saved x8、9、18-27 $在頭表明指暫存器的名稱 x表明暫存器的編號 ![](https://i.imgur.com/e1wijuG.png) 幾位元的電腦就有幾個暫存器 暫存器比記憶體快、Complier擅長用暫存器,比如上下行用到同一個暫存器編號,它可以改變順序、保留變數,讓他不用一直跟主記憶體要 Call density:程式行數密度 * CPU設計的規則 : 小➜快 ![](https://i.imgur.com/KNMOVsr.png) f、g、h、i、j : $s0 - $s11 s開頭的saved (g+h)、(i+j) : $t0 - t6 t開頭temporary s開頭儲存運算元的變數 t開頭儲存暫時運算的結果 ### Memory Operands 記憶體的基本單位是位元組byte memory,存取出來的是以word字組為單位(32bits-4bytes/word) double word雙字組:64bits 8bytes program counter Little Endian : 小端 pointer p+4 p+4+4 RAM 內頻的倍數都用一樣的 little/big Endian RISC-V是遞增 : Little Endian 32位元:每次存取4bytes Alignment restriction要對齊 #### Load指令寫出來? Offset 偏移量: 從M[0]要往下走幾個bytes(以) ![](https://i.imgur.com/HEfWRpz.png) ld x9 , 24 (x22) operator(load一個double word)位置(給x9這個暫存器),offset(從Base register 往下數24bytes)記憶體暫存器(Base register是x22) 因為逢紐曼瓶頸:把東西放在暫存器 阿暫存器放不下=>存回記憶體Register spill溢出 ### 立即值指令 立即值inmmediate value 常數的感覺 他跟邏輯運算指令長一樣 Design Principle3:Make the common case fast長度一樣 subi 沒 要用addi x22,x20,-1 沒有move 要用加零到哪裡來移動base register 32vs64 搬運做sign extention時 值會不一樣 ex:10001010 -> 111111111001010 十六進位0x..... ### R-type 機械語言轉換 ![](https://i.imgur.com/pl16ELz.png) <--------------------------------------------------------------------------------little ini add$9,$20$21 ----------> ![](https://i.imgur.com/8YarN5y.png) 然後變十六進位0x_____(每四個一組編碼):機械語言 ![](https://i.imgur.com/Jye68jJ.png) * Design Principle 4: Good design demands good compromises協調 每個欄位都差不多 ### Memory Allocation 應用程式擺最上層 random >AS >OS >SS > BS Bootstrap、Driver 固定 * Nest call巢狀呼叫 Main .... A() leaf proce ....↓ B() ....↓ --- ## 期末考範圍分界 sum of product product of sum ![](https://i.imgur.com/mE1miTQ.png) ![](https://i.imgur.com/5Lu6tef.png) 水管理論 串接型前瞻加法器 多階層進位前瞻加法器 被乘數multiplicand 乘數multiplier 乘積product t1 t2 第一步 確認 被乘數的LSB 第二步 if M=1 add multiplicand + original product M=0 M的LSB shift left 第三 Sum Product ![](https://i.imgur.com/PTaHgtV.png) ![](https://i.imgur.com/fym6Twd.png) ![](https://i.imgur.com/8aaQMT9.png) ![](https://i.imgur.com/zXzL0d8.png) ![](https://i.imgur.com/QpgnYkF.png) * 小數轉10100010101 ![](https://i.imgur.com/1GsLfGs.png) ![](https://i.imgur.com/NBdEgmX.png) ![](https://i.imgur.com/qayErXT.png) 指數次方要大於零 浮點點數轉ieee 127 要加127 round bit guard bit stucky bit ![](https://i.imgur.com/XWv8XuO.png) ![](https://i.imgur.com/zGwQO35.png) ![](https://i.imgur.com/kBuWr07.png) 往後看一位 2.6125*10=26.15 =>11010.001 = 1.1010001*2 SIMD ### CPU design process ![](https://hackmd.io/_uploads/SkJaVtw4n.png) --- control fun3 fun7 opcode 1. analyze instruction set ![](https://hackmd.io/_uploads/S1n2gsgSn.png) mux位置 alu src/MemtoReg/PcSrc =>Mulitplier RegWrite/MemRead/MemWrite =>Store element Aluop/Equal =>combination element store status > negate 0 > assert 1:被設定 cpu速度 給指令每個段的時間 找ld的時間當作它單一指令的時間 datapath of load instruction =>critial datapath 包含CPU Execution Cycle 1. Instruction Fetch 2. indirect-addressing 3. pc-based addressing 4. presudo addressing

    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