Low Zero Limbs

LingWitt@insightbb.com LingWitt@insightbb.com
Mon, 23 Jun 2003 23:31:27 -0400


--Apple-Mail-2-808876470
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

> (If you're not sure what you're doing with this you're probably better
> off to leave it alone.  What was the aim anyway?  Speed?  Correctness
> is not affected by low zeros, or shouldn't be.)

I want to minimize the amount of unused memory. If a number needs more 
to accurately represent itself, then it should get more. If it doesn't 
need so much, it should deallocate it. I am under the impression that 
only floats created by strings are over-allocated, so I figure that 
shaving off the zero limbs upon initialization will do the trick.

There might be 1 000 000 floats allocated at a max precision of 2000 
bits. In this case, there are 65 limbs allocated to each mpf_t. On my 
system --like most--each limb is 4 bytes, so that comes out to 2.6e+08 
bytes, or a little under 248 MB, when under 8 MB might do.

> No, don't change f->_mp_d, copy the limbs down within that data space.

I don't know what you mean --delete the whole mp_d array and make a new 
one? --I've never worked with such low-level operations. Please give me 
a little help so I can learn:

Why doesn't this work:

unsigned int stripLowZeroLimbs(mpf_ptr f)
{
     unsigned 	sizeNew, sizeOld;
     sizeNew = sizeOld = f->_mp_size;
     mp_ptr	limbs			= f->_mp_d;
     mp_ptr	limb			= 0;

     while (*(limb = limbs++) == 0 && sizeNew > 1)
         sizeNew--;

     if (++sizeNew == sizeOld)
         return 0;

     f->_mp_size = sizeNew;

     mp_ptr newLimbs = static_cast<mp_ptr>(calloc(sizeNew, 
sizeof(mp_ptr)));
     sizeNew--;
     for (unsigned int indexOld = sizeOld - sizeNew, indexNew = 0; 
indexNew < sizeNew; indexOld++, indexNew++)
         newLimbs[indexNew] = limbs[indexOld];

     free(f->_mp_d);
     f->_mp_d = newLimbs;

     return sizeOld - f->_mp_size;
}

On Monday, Jun 23, 2003, at 20:43 America/New_York, Kevin Ryde wrote:
--Apple-Mail-2-808876470
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

<excerpt>(If you're not sure what you're doing with this you're
probably better

off to leave it alone.  What was the aim anyway?  Speed?  Correctness

is not affected by low zeros, or shouldn't be.)

</excerpt>

I want to minimize the amount of unused memory. If a number needs more
to accurately represent itself, then it should get more. If it doesn't
need so much, it should deallocate it. I am under the impression that
only floats created by strings are over-allocated, so I figure that
shaving off the zero limbs upon initialization will do the trick.


There might be 1 000 000 floats allocated at a max precision of 2000
bits. In this case, there are 65 limbs allocated to each mpf_t. On my
system --like most--each limb is 4 bytes, so that comes out to 2.6e+08
bytes, or a little under 248 MB, when under 8 MB might do.


<excerpt>No, don't change f->_mp_d, copy the limbs down within that
data space.

</excerpt>

I don't know what you mean --delete the whole mp_d array and make a
new one? --I've never worked with such low-level operations. Please
give me a little help so I can learn:


Why doesn't this work:


<fixed><color><param>7674,0F0D,504E</param>unsigned</color> int
stripLowZeroLimbs(mpf_ptr f)</fixed>

<fixed>{

    <color><param>7676,0F0F,5050</param>unsigned</color> 	sizeNew,
sizeOld;

    sizeNew = sizeOld = f->_mp_size;

    mp_ptr	limbs			= f->_mp_d;

    mp_ptr	limb			= <color><param>0000,0000,FFFF</param>0</color>;

    

    <color><param>7676,0F0F,5050</param>while</color> (*(limb =
limbs++) == <color><param>0000,0000,FFFF</param>0</color> && sizeNew >
<color><param>0000,0000,FFFF</param>1</color>)

        sizeNew--;

    

    <color><param>7676,0F0F,5050</param>if</color> (++sizeNew ==
sizeOld)

        <color><param>7676,0F0F,5050</param>return</color>
<color><param>0000,0000,FFFF</param>0</color>;

    

    f->_mp_size = sizeNew;

    

    mp_ptr newLimbs =
<color><param>7676,0F0F,5050</param>static_cast</color><<mp_ptr>(calloc(sizeNew,
<color><param>7676,0F0F,5050</param>sizeof</color>(mp_ptr)));

    sizeNew--;

    <color><param>7676,0F0F,5050</param>for</color>
(<color><param>7676,0F0F,5050</param>unsigned</color>
<color><param>7676,0F0F,5050</param>int</color> indexOld = sizeOld -
sizeNew, indexNew = <color><param>0000,0000,FFFF</param>0</color>;
indexNew << sizeNew; indexOld++, indexNew++)

        newLimbs[indexNew] = limbs[indexOld];

    

    free(f->_mp_d);

    f->_mp_d = newLimbs;

    

    <color><param>7676,0F0F,5050</param>return</color> sizeOld -
f->_mp_size;

}</fixed>


On Monday, Jun 23, 2003, at 20:43 America/New_York, Kevin Ryde wrote:
--Apple-Mail-2-808876470--