Ch3 Arithmetic for Computers
本章節主要在探討電腦如何用硬體電路來執行加減乘除與浮點數運算,並延伸到「平行化算術加速」與錯誤處理。這一章的內容是從「數字如何表示」一路講到「怎麼加快算術運算效率」。
3-2 加法與減法
- 加法:直接加起來就好
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 減法:加上負數就是減法
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Overflow:
- 當計算結果超過儲存大小,就會產生 overflow
- Saturating Operation:
- 當 overflow 產生時,只儲存最大的資料型態
- e.g. 7(4-bits) +12(4-bits) = 15(4-bits, saturating operations)
3-3 乘法
可以參考這位大佬寫的筆記:連結
一般乘法器
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 流程:
- 先初始化 multiplicand(被除數)與 multiplier(除數),product 預設為 0
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 當 multiplier 的最低位是 1 時,product 加上 multiplicand 的值
- 如果是 0,則跳過這一步
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 計算完成後,multiplicand 左移一位,multiplier 右移一位
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 會執行 n 次循環:n = multiplicand 的位數
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 優化版本:
- 直接將 multiplier 存在 product 中
- 每次做完一個循環,multiplicand 左移一位,product 右移一位
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
快速乘法器
- 使用多重的 ALU:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 可以透過平行化處理來加快運算
MIPS 實作
- 64-bits Product:
- 因為 MIPS register 只能存 32 bit,因此要分兩個 register 存放
- HI:most-significant 32 bits
- LO:least-significant 32 bits
- 指令:
- mult, multu:
- mfhi, mflo:
- mul:
- least-significant 32 bits of product ->
rd
3-4 除法
一般除法器
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 流程:
- 循環會經過 n 次(n = divisor 的次數)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 優化版本:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
MIPS 除法指令
- 使用 HI/LO register 來儲存結果
- div:
- divu:
3-5 Float Point
- 用來表示非整數型態的數字
- 使用科學記號表示
- In binary:
- 使用 IEEE 754 標準
Single precision
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Sign = 0, 1
- Exponent = 次方數 + 127
- Fraction = 小數點後的數
Double precision
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Sign = 0, 1
- Exponent = 次方數 + 1023
- Fraction = 小數點後的數