<style> .reveal .slides { text-align: left; } </style> # NTNU CS:APP 讀書會 第3週 --- # Chapter 1 ## Instruction-level parallelism ---- ## Pipeline - instruction 在處理時被分解成多個子動作 - e.g `add Mem₆₄, %rax` **可能**被分解成 - 取得指令 - 指令解碼 - 執行指令 - 寫回 register / memory - 各個動作使用不同的 circuit - 平行使用這些 circuit 加速 ---- - 前後 instruction 依賴可能造成錯誤 ?! - `add $1, %rax` - `mov %rax %rbx` - 如果 add 還沒進行到真正算出結果的動作 - mov 就開始移動 - ::::)))) Data hazard 資料~~燒起來~~ - 分析執行流找出依賴關係 - Operand forwarding 讓依賴的指令等到結果,不等他寫入 register 就直接將結果 pass 給對應的電路做後續處理 - Out-of-order execution 讓沒有依賴關係的指令先做 ---- ## Superscalar - What is scalar? - a+b, a-b, a*b, a/b - What is not scalar? - [a, b, c] + [d, e, f] - What the fuck is superscalar - ~~super power + scalar~~ - 多個 ALU / FPU 同時處理多個 instruction - `add %rax, %rbx` -> `mov %rbx, Mem₆₄` 怎麼平行阿你給我說說看 - 仰賴執行時期對執行流的分析 (對分支與依賴關係的分析) ---- ## Data hazard - 平行意味著 race conditon 藏在其中 - 資料被 parallelism 搞到燒起來怎麼辦? - 聽說第四章會講我就不破梗ㄌ XD ---- ## 總結 - Instruction-level parallelism 就是同時多處理一些 instruction - pipeline 進可能利用每個可以利用的電路 - superscalar 多加~~幾個電路~~更多運算單元 - 需要對執行流做依賴與分支分析 - 一直堆 ALU / FPU 終究會碰到瓶頸 --- # Chapter 2 ## 基礎算數 ---- <!-- .slide: data-background="https://cdn2.ettoday.net/images/2869/d2869328.jpg" style="backdrop-filter: blur(3px) brightness(50%);" --> ## 聽說有人要求實驗 XD ~~既然你誠心誠意的發問了 就只好大發慈悲的給你了~~ ---- ## Unsign to Signed conversion <iframe frameborder="0" width="100%" height="500px" src="https://replit.com/@jw910731/UnsignSignConversion?lite=true#main.c"></iframe> ---- ## Numeric Conversion Truncate <iframe frameborder="0" width="100%" height="500px" src="https://replit.com/@jw910731/IntegerTruncate?lite=true#main.c"></iframe> ---- ## Accurate float point arithmetic <iframe frameborder="0" width="100%" height="500px" src="https://replit.com/@jw910731/FloatArithmetic?lite=true#main.c"></iframe> ---- ## 乘法加速? [mul_acc.c](https://github.com/aokblast/NTNU_CSAPP_Example_Code/blob/main/ch2/mul_acc/mul_acc.c) ---- ## Normalize 符點數 [normalize.c](https://github.com/aokblast/NTNU_CSAPP_Example_Code/blob/main/ch2/normalize/normalize.c) --- # CH3-浮點數的部份 ---- ## 先來跟浮點數問個好吧 [./hello_fp](https://github.com/aokblast/NTNU_CSAPP_Example_Code/tree/main/ch3/hello_fp) ---- ## Register * ymm 0-15(256bit) * xmm 0-15(128) 0 做回傳值 0-7 做函式參數 8-15 做caller-saved ---- ## Move * movsd * movss * movapd * movaps ---- ## Truncate and Expand ![](https://i.imgur.com/DFou3hs.jpg) ![](https://i.imgur.com/4S5GZzE.jpg) ---- ## 來點小實驗 [./move_fp](https://github.com/aokblast/NTNU_CSAPP_Example_Code/tree/main/ch3/move_fp) ---- ## Function pass parameter 從xmm0-xmm7 獨立register, 不與原本的衝突 回傳xmm0 什麼?你像要多於8個參數? 使用 stack 空間吧 記得自己管理 `%rsp` 不要搞爛 stack 喔 :) ---- ## 再來點小實驗 [./print_floatpoint/](https://github.com/aokblast/NTNU_CSAPP_Example_Code/tree/main/ch3/print_floatpoint) ---- ## arthmetic instruction ![](https://i.imgur.com/BdiHkeX.jpg) ---- 這邊牽扯到數值轉換跟編譯器優化, 所以沒有特別寫asm [./arith_fp/](https://github.com/aokblast/NTNU_CSAPP_Example_Code/tree/main/ch3/arith_fp) ---- ## Bitwise ![](https://i.imgur.com/WWSbsDI.jpg) ---- ## Compare ![](https://i.imgur.com/qrFhKf0.jpg) ![](https://i.imgur.com/DUmLX39.jpg) **Use unsigned compare flag** 應使用 `ja` 等 unsigned conditional jump instruction ---- ## Compare [./float_compare/](https://github.com/aokblast/NTNU_CSAPP_Example_Code/blob/main/ch3/float_compare/float_cmp.s) 如果你想問為什麼是 Gnu as 的話 因為我想念 AT&T Assembly 了
{"metaMigratedAt":"2023-06-16T05:03:00.046Z","metaMigratedFrom":"YAML","title":"CS:APP Chapter 1-3 補充 (重講)","breaks":true,"slideOptions":"{\"transition\":\"fade\"}","contributors":"[{\"id\":\"61ca4dc9-8746-43ef-8a00-8c9b80b292c0\",\"add\":2967,\"del\":79},{\"id\":\"3c6a5dd2-0fad-46b4-86b7-399891d935fc\",\"add\":660,\"del\":38}]"}
    315 views
   Owned this note