移码的位扩展

it2024-07-07  41

0. Background

​ The exponent part of the IEEE Floating-Point Representation is encoded in a biased form. During my design of the ALU for the floating point, I need to find a way to extend the biased form for one bit without change the actual value which it’s representing and make it easier to detect the overflow and underflow during the calculation.

​ By the way, a k k k-bit biased number’s bias in this article is B i a s = 2 k − 1 − 1 Bias = 2^{k - 1} - 1 Bias=2k11.

1. Conclusion & Provement

Suppose a k k k-bit biased numer and the actual value of its representation : X k X k − 1 . . . X 1 = ∑ n = 1 k X n ∗ 2 n − 1 − 2 k − 1 + 1 X_kX_{k-1}...X_1 = \sum_{n=1}^{k}{X_n*2^{n-1}} - 2^{k-1} + 1 XkXk1...X1=n=1kXn2n12k1+1

To extend it to a $ k+1$ -bit number and its actual value: X k X k ‾ X k − 1 . . . X 1 = ∑ n = 1 k + 1 X n ∗ 2 n − 1 − 2 k + 1 X_k\overline{X_k}X_{k-1}...X_1 = \sum_{n=1}^{k+1}{X_n*2^{n-1}} - 2^{k} + 1 XkXkXk1...X1=n=1k+1Xn2n12k+1

Subtract their actual value and we got: ∑ n = 1 k X n ∗ 2 n − 1 − 2 k − 1 + 1 − ( ∑ n = 1 k + 1 X n ∗ 2 n − 1 − 2 k + 1 ) = ( X k ∗ 2 k − 1 − X k ∗ 2 k ) − X k ‾ ∗ 2 k − 1 − 2 k − 1 + 2 k = − X k ∗ 2 k − 1 − X k ‾ ∗ 2 k − 1 + 2 k − 1 = 2 k − 1 ( 1 − ( X k + X k ‾ ) ) = 2 k − 1 ( 1 − 1 ) = 0 \begin{aligned} &\sum_{n=1}^{k}{X_n*2^{n-1}} - 2^{k-1} + 1 - (\sum_{n=1}^{k+1}{X_n*2^{n-1}} - 2^{k} + 1)\\ =&(X_k*2^{k-1} - X_k*2^k) - \overline{X_k}*2^{k - 1} - 2^{k - 1} + 2^{k}\\ =&-X_k*2^{k-1}-\overline{X_k}*2^{k-1} + 2^{k-1}\\ =&2^{k - 1}(1-(X_k + \overline{X_k}))\\ =&2^{k - 1}(1-1)\\ =&0\\ \end{aligned} =====n=1kXn2n12k1+1(n=1k+1Xn2n12k+1)(Xk2k1Xk2k)Xk2k12k1+2kXk2k1Xk2k1+2k12k1(1(Xk+Xk))2k1(11)0

2. Generalization

When it comes to extend more than one bit, just keep extending one bit at a time.

For example: O r i g i n a l ( k   b i t ) : X k X k − 1 . . . X 1 k + 1   b i t :    X k X k ‾ X k − 1 . . . X 1 k + 2   b i t :   X k X k ‾ X k ‾ X k − 1 . . . X 1 k + 3   b i t : X k X k ‾ X k ‾ X k ‾ X k − 1 . . . X 1 . . . . . . Original(k\ bit):\qquad\qquad\qquad X_kX_{k-1}...X_1\\ k+1\ bit:\qquad \qquad \ \ X_k\overline{X_k}X_{k-1}...X_1\\ k+2\ bit:\qquad \quad \ X_k\overline{X_k}\overline{X_k}X_{k-1}...X_1\\ k+3\ bit:\qquad X_k\overline{X_k}\overline{X_k}\overline{X_k}X_{k-1}...X_1\\ ...... Original(k bit):XkXk1...X1k+1 bit:  XkXkXk1...X1k+2 bit: XkXkXkXk1...X1k+3 bit:XkXkXkXkXk1...X1......

3. Shrink a biased form number

Consider the simplest case: shrink X k X k − 1 . . . X 1 X_kX_{k-1}...X_1 XkXk1...X1 to k − 1 k-1 k1 bit.

If X k X k − 1 X_kX_{k-1} XkXk1 can be represented as X k − 1 X k − 1 ‾ X_{k-1}\overline{X_{k-1}} Xk1Xk1 then it can be shrunk to one less bit without changing the actual value.

If X k X k − 1 X_kX_{k-1} XkXk1 equals 11, the this k − b i t k-bit kbit biased form number is bigger than the maximum which k − 1 k-1 k1 bit can represent.

If X k X k − 1 X_kX_{k-1} XkXk1 equals 00, the this k − b i t k-bit kbit biased form number is less than the minimum which k − 1 k-1 k1 bit can represent.

The complexer cases then is easy to generalize and understand.

最新回复(0)