[LMH]BIGNUM format?

Steve Krueger stevelisp@grape-krueger.com
Mon Jun 16 20:05:02 2003


Good questions.  The answers are:

Nyef wrote:

>Hello all.
>
>Can I have a reality check? SSDN2, section 7.8.6.1 appears to say that 
>BIGNUMs are stored in sign-magnitude format. Section 7.5.1 says that 
>FIXNUMs are stored in 2s-complement format. ClTl says (I forget where) 
>that LDB and DPB treat all integers as being in 2s-complement form.
>
>My questions are:
>
>    Are BIGNUMs -really- stored as sign-magnitude, and not 2s-complement?
>
Yes.  It is easier to construct the extended precision number from the 
sign-magnitude parts than from 2's-complement parts.  So SSDN2 is indeed 
correct.  BTW, I don't think the bignum format (other than the DTP and 
header type encodings) changed from the SSDN1 or MIT encodings.  The 
zero in bit 037 is used for overflow detection in arithmetic.

>
>    Do LDB and DPB behave, to a user, as if BIGNUMs are stored as 
>2s-complement, as per ClTl, or does the abstraction break down there?
>
>  
>
I think that the LDB and DPB microcode converts the relevant part of the 
number to 2s-complement for this operation.  I'm looking into the 
microcode for BIGNUM-LDB now.

OK.  The microcode has about 45 instructions.

1. SS must encode a number <= (pointer_width - 1)
2. Find which word of bignum by dividing PP by 31. (microcode uses 
repeated subtraction).
3. If PP puts the field off the end of the bignum, field extracted is 
one is the bignum is negative and zeros otherwise.
4. If PP is within the bignum,  read the index word of the bignum.
5. Extract the portion of the field within this bignum word.
6. If the field crosses words of the bignum, read the next word (unless 
this is the last, then use zeros), extract the remaining bits and 
concatenate.
7. If the bignum is positive, return this field as a fixnum.
8. If the bignum is negative, take the two's complement and return as a 
fixnum.

Undoubtedly, DPB is similar.

Yes the microcode is really full of this kind of twisty, very 
conditional code.

    -Steve