Subject: Re: Need help figuring out a way to convert IEEE 754 representation to Posit
To: Unum Computing <
unum-computing@googlegroups.com>
Note: This is untested and "just a guess".
On Saturday, February 18, 2023 at 4:41:05 PM UTC-6 johngustafson wrote:
My approach in converting a float to a posit is to first separate the sign from the magnitude (note the sign, then set the bit to zero); then check if the magnitude is zero, in which case return posit zero (all 0 bits).
I would separate into S, E, and 1.F (I am a HW guy so this is the way I think)
Access a table[E] containing {pE, pEs, pF} pE is the posit regime+exponent, pF is a shift applied to 1.F to put it in the proper position in the posit.
pFr = pF > 0 : 1.F >> pF /*you could add rounding on the bits falling off the end here */ : 1.F << -pF;
Now::
p = {S<<63 | pE << pEs | pFr}; is the posit when no boundary conditions are encountered.
Now we make the table values handle certain special cases::
E = all 1s -> {NaN or Infinity} pF = 63 (thus the shift will eliminate all 1.F bits without making shifters on various architectures cranky)
E = all 0s -> denormalized {and I don't remember what posits do with denorms}
The table[2048] is easy to construct. Using E directly as an index to the table eliminates having to understand the bias, it is just mapping E to pE<<pEs. If you are going to have to consume (blow) a doubleword for regime+exponent then you can eliminate the shift (saving an instruction (below)).
Milan Kloewer's use of posits has in a very restricted range, so his table[E] will hardly damage his cache's
data footprint. He may ignore infinities and underflow conditions due to his restricted range.
In my ISA, this is 14 instructions (less rounding).
Best,
John
Mitch