5.5  Rebiasing Exponents

A common task performed by floating-point units is the conversion of an encoding from one format to another, which generally requires the rebiasing of the exponent field. If $ e$ is the value of an exponent field of width $ m$, then the actual exponent of the encoded number is $ e-bias(m)$. The result of rebiasing this value for a field of width $ n$ is given by the following definition.

Definition 5.5.1   (rebias-expo) For all $ e \in \mathbb{N}$, $ m \in \mathbb{N}$, and $ n \in \mathbb{N}$,

$\displaystyle rebias$-$\displaystyle expo(e,m,n) = e+2^{n-1}-2^{m-1}.$

When the target exponent field is wider than that of the source, rebiasing is always possible.

  (rebias-up) Let $ m \in \mathbb{N}$ and $ n \in \mathbb{N}$ with $ 1 < m < n$. If $ e$ is an $ m$-bit vector, then

$\displaystyle rebias$-$\displaystyle expo(e,m,n) = \{e[m-1], \{(n-m)\{\verb! !e[m-1]\}\}, e[m-2:0]\}.$

PROOF: First suppose that $ e[m-1] = 1$. Then by Lemmas 2.2.5 and 2.3.17,

$\displaystyle e = e[m-1:0] = 2^{m-1} + e[m-2:0]$

and

$\displaystyle rebias$-$\displaystyle expo(e,m,n) = 2^{n-1} - 2^{m-1} + 2^{m-1} + e[m-2:0] = 2^{n-1} + e[m-2:0].$

On the other hand, by Definition 2.4.1 and Lemma 2.4.18,
$\displaystyle \{e[m-1], \{(n-m)\{\verb! !e[m-1]\}\}, e[m-2:0]\}$ $\displaystyle =$ $\displaystyle 2^{n-1}\cdot 1 + 2^{m-1}\{(n-m)\{0\}\} + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle 2^{n-1} + e[m-2:0].$  

Now suppose $ e[m-1] = 0$. Then

$\displaystyle rebias$-$\displaystyle expo(e,m,n) = 2^{n-1} - 2^{m-1} + e = 2^{n-1} - 2^{m-1} + e[m-2:0]$

and by Definition 2.4.1 and Lemma 2.4.19,
$\displaystyle \{e[m-1], \{(n-m)\{\verb! !e[m-1]\}\}, e[m-2:0]\}$ $\displaystyle =$ $\displaystyle 2^{n-1}\cdot 0 + 2^{m-1}\{(n-m)\{1\}\} + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle 2^{m-1}(2^{n-m}-1) + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle 2^{n-1} - 2^{m-1} + e[m-2:0].$  

Corollary 5.5.2   (bvecp-rebias-up) Let $ m \in \mathbb{N}$ and $ n \in \mathbb{N}$ with $ 0 < m \leq n$. If $ e$ is an $ m$-bit vector, then $ rebias$-$ expo(e,m,n)$ is an $ n$-bit vector.

Now suppose that $ e$ is an $ n$-bit biased exponent to be rebiased to fit into a smaller $ m$-bit field. In order for this to be possible,

$\displaystyle rebias$-$\displaystyle expo(e,n,m) = e+bias(m)-bias(n)$

must be an $ m$-bit vector, i.e.,

$\displaystyle 0 \leq e+bias(m)-bias(n) = e + 2^{m-1} - 2^{n-1} < 2^m,$

or equivalently,

$\displaystyle 2^{n-1}-2^{m-1} \leq e < 2^{n-1}+2^{m-1}.$

  (rebias-down) Let $ m \in \mathbb{N}$ and $ n \in \mathbb{N}$ with $ 1 < m < n$. If $ e$ is an $ n$-bit vector and

$\displaystyle 2^{n-1}-2^{m-1} \leq e < 2^{n-1}+2^{m-1},$

then

$\displaystyle rebias$-$\displaystyle expo(e,n,m) = \{e[n-1], e[m-2:0]\}.$

PROOF: The hypothesis implies that $ e$ is an $ n$-bit vector, and hence, by Lemmas 2.2.5, 2.3.17, and 2.2.22,

$\displaystyle e = e[n-1:0] = 2^{n-1}e[n-1] + 2^{m-1}e[n-2:m-1] + e[m-2:0].$

Suppose first that $ e[n-1] = 1$. Then $ e[n-2:m-1] = 0$, for otherwise $ e[n-2:m-1] \geq 1$ and $ e \geq 2^{n-1} + 2^{m-1}$. Thus, $ e = 2^{n-1} + e[m-2:0]$ and
$\displaystyle rebias$-$\displaystyle expo(e,n,m)$ $\displaystyle =$ $\displaystyle 2^{m-1} + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle 2^{m-1}e[n-1] + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle \{e[n-1], e[m-2:0]\}.$  

Now suppose $ e[n-1] = 0$. Then $ e[n-2:m-1] = 2^{n-m}-1$, for otherwise, by Lemma 2.2.1, $ e[n-2:m-1] \leq 2^{n-m}-2$ and
$\displaystyle e$ $\displaystyle \leq$ $\displaystyle 2^{m-1}(2^{n-m}-2) + e[m-2:0]$  
  $\displaystyle \leq$ $\displaystyle 2^{m-1}(2^{n-m}-2) + e[m-2:0]$  
  $\displaystyle <$ $\displaystyle 2^{n-1} - 2^m + 2^{m-1}$  
  $\displaystyle =$ $\displaystyle 2^{n-1} - 2^{m-1}.$  

Therefore,

$\displaystyle e = 2^{m-1}(2^{n-m}-1) + e[m-2:0] = 2^{n-1} - 2^{m-1} + e[m-2:0]$

and
$\displaystyle rebias$-$\displaystyle expo(e,n,m)$ $\displaystyle =$ $\displaystyle e[m-2:0]$  
  $\displaystyle =$ $\displaystyle 2^{m-1}e[n-1] + e[m-2:0]$  
  $\displaystyle =$ $\displaystyle \{e[n-1], e[m-2:0]\}.$  

Corollary 5.5.4   (bvecp-rebias-down) Let $ m \in \mathbb{N}$ and $ n \in \mathbb{N}$ with $ 0 < m \leq n$. If $ e$ is an $ n$-bit vector and

$\displaystyle 2^{n-1}-2^{m-1} \leq e < 2^{n-1}+2^{m-1},$

then $ rebias$-$ expo(e,n,m)$ is an $ m$-bit vector.

David Russinoff 2017-08-01