Integer Addition
Integer Substraction
Multiplication
- Multiplicand: 계속 더해지는 수
- Multiplier: 각 bit를 보면서 몇 번 더할지 결정하는 수
이진수 곱셈은 multiplier의 각 bit를 보면서
해당 bit가 이면, multiplicand를 더하고.
이면, 아무것도 안한다.
그리고 한 칸씩 shift한다.
예를 들어 다음 수식을 계산해 보자.
맨 오른쪽 bit부터 본다. (i.e. Big endian)
1000
× 1001
--------
1000
0000
0000
1000
--------
1001000
즉 결과는 이다.
결과를 보면 알겠지만, 길이가 2배가 되었다.
그래서 n-bit x n-bit = 2n이 필요하다.
Improved Multiplier
Product 회로가 Right shift를 수행하기 때문에 곱셈하면서 오른쪽 레지스터까지 사용할 경우가 없다.
때문에 오른쪽 부분에 multiplier를 배치함으로써, 회로 최적화가 가능하다.
+-------------------+
Multiplicand --->| Multiplicand Reg |-------------------+
+-------------------+ |
v
+-----------+
| Adder |
+-----------+
|
v
+---------------------------------------------------------------+
| Product / Multiplier Register |
| [ upper half: partial product | lower half: multiplier ] |
+---------------------------------------------------------------+
|
v
Right Shift Control
Division
Floating Point
IEEE 754 Floating-Point Format
single 4-byte(32 bits) 기준
| S | Exponent | Fraction |
| 1bit | 8bits | 23bits |
Bias: 127
double 8-byte(64 bits) 기준
| S | Exponent | Fraction |
| 1bit | 11bits | 52bits |
Bias: 1023
- Fraction: 소수 부분
- Exponent: 2를 몇 번 곱할지 정함
- Bias: 음수를 위해 필요함
음수처리를 위해 Bias를 사용한다.
예를 들어 single precision 기준에서, exponent가 이면 로 저장된다.
때문에 실제 사용할 때 bias 만큼 빼주어야 한다.
이를 이해했다면 실제 exponent 범위를 알 수 있다.
여기서 왜? 이 아니고, 인지 의문이 든다.
IEEE 754 기준에서 exponent가 인 값은 special case로 처리되어서,
최소 부터 시작이기 때문이다.