Chapter 3 Arithmetic for Computer

6 Design Ideas for Computer Organization

image-20220307111033265

bit

Byte =8bit

word =32bit =4Byte

计组中,一个word就是一个指令多少

1 bit ALU

Addition Subtraction

  1. Overflow: a xor b == 0, a and b are carryout bits.
  2. Adder: G_i=generator, P_i=propagator.

Carry Lookahead Adder (CLA)

用G和P项进行同步进位,位数过大使用多级CLA结构
G是自身进位因素,P是上一级进位因素

Carry Select Adder (CSA)

提前算好两种进位的结果,最后根据实际结果进行选择

Multiplication

Use multiplier who use adder and shifter.

Actually: Multiplier for 64bit and 64bit
Only use 64+128 bits register. Store other 64bit number into the Product Result Location.

For signed multiply: count sign first and multiply their abs value.

Booth Algorithm for Multiply

Division

Unsigned division

divisor {remainder, result}

方法是:

bool result[32],remain[32],remainder[64],divisor[32];
for(size_t i=0;i<divisor.size;i++)
{
if(divisor<=remainder.high)
remainder.left_shift(1);
else
remainder.left_shift(0);
}
result=remainder.low;
remain=remainder.high.right_shift(0);

问题:很难硬件层并行(课后参考: SRT division)

Floating Point numbers

IEEE 754

Form: 1.xxxxxx*2^(yyyyyy)

Single Precision
31 30……23 (8bits) 22……0 (23bits)
sign exponent (without 0...000and1...111) fraction
Double Precision
63 62……52 (11bits) 51……0 (52bits)
sign exponent (without 0...000and1...111) fraction
Exponent is Bias

指数位你想用X,但是实际表示的[x]=2^n-1+X

Bias 127 for single precision.
Bias 1023 for double precision.
So, the value of floating point number is: $(-1)^{sign}\cdot (1+significand)\cdot 2^{exponent-bias}$

Single-precision Range:

Smallest value $\pm 1.0\times 2^{-126}\approx \pm 1.2\times 10^{-38}$
Largest value $\pm 2.0\times 2^{127}\approx \pm 3.4\times 10^{38}$

#####Relative precision:
Single$\approx \mathbf{6 decimal}$
Double$\approx \mathbf{16 decimal}$

Limitation and Over/Underflow & Infinities and “Not a Number”s

overflow是指太大了表达不了,underflow是指太小了表达不了

Exponent = 11...1111, Fraction = 00...0000
$\approx \mathbf{infinity}$

Algorithm of ADD/SUB: with Hardware
Multiply

$\mathbf{s_1s_22^{ex_1+ex_2-bias}}$

浮点数取舍问题TBD

# 其实也很简单
| Gurad bit | Round bit | Sticky bit |
| 0 | x | x | 约去
| 1 | 0 | 0 | 约到偶数
| 1 | x | x | 其他情况就进位