At 06:11 PM 9/12/2001 -0500, Gibbs Tanton - tgibbs wrote:
>
>I hate to ask such a stupid question, but what is a power of two boundry and
>why do we want it to be aligned on one?  I was assuming a power of two
>boundry to be some memory address N such that N = 2 ** i, but this
>apparently is not the case.  Sorry for asking such a rudimentary question,
>but I'm trying to understand the memory allocation logic and failing
>miserably.

The boundary I'm looking for is one where all the low bits of the address 
are zeroes. Basically take the size of an object, round it up to a 
power-of-two size (256, 512, 1024, whatever) and make sure that you can 
mask out the low bits with no problem. So for an up to 256-byte thing the 
low 8 bits are zero, for a thing that's between 257 and 512 the low 9 bits 
are zero, and so on.

The reason for this is nasty, and basically speed. If I'm aligned properly, 
and I have an address in the middle of one of my aligned structures, I can 
mask the low bits off and find the base of the whole structure without 
needing embedded pointers or anything.

Register frames work like this, for example. The first chunk of the 
register frame is some meta-information (forward and back pointers, frames 
used, and so forth) while the rest is sets of register arrays. If I have an 
address of one of the register arrays in the frame (which I do) I can find 
the base structure by lopping the low bits off. Cheaper in memory terms 
than having lots of back pointers. (Time, too, since I don't have to fill 
those back-pointers in)

It is a hack that might go if it turns out that having the back pointers is 
cheaper, though.

>-----Original Message-----
>From: Dan Sugalski
>To: Hong Zhang; 'Philip Kendall'; [EMAIL PROTECTED]
>Sent: 9/12/2001 12:19 PM
>Subject: RE: Parrot coredumps on Solaris 8
>
>At 09:57 AM 9/12/2001 -0700, Hong Zhang wrote:
> > > Now works on Solaris and i386, but segfaults at the GRAB_IV call in
> > > read_constants_table on my Alpha. Problems with the integer-pointer
> > > conversions in memory.c? (line 29 is giving me a warning).
> >
> >The line 29 is extremely wrong. It assigns IV to void* without casting.
>
>True. I'll go fix it.
>
> >The alignment calculation is very wrong too. Using classic alignment,
> >it should read as:
> >
> >         mem = (void*) (((IV)mem + mask) & ~mask);
>
>Nope. We're trying to align to a power-of-two boundary, and mask is set
>to
>chop off the low bits, not the high ones. It should be something like:
>
>     111111110000
>
>The calc:
>
>      mem & mask + (~mask + 1)
>
>will chop the low bits off of mem, making it too small, but power-of-two
>
>aligned. Then we add in the inverse of mask + 1 (in the above example,
>that'd be 10000) to jump it to the next power-of-two boundary.
>
>Horribly wasteful of memory, definitely, and the final allocation system
>
>will do things better, but this is OK to start.
>
>                                         Dan
>
>--------------------------------------"it's like
>this"-------------------
>Dan Sugalski                          even samurai
>[EMAIL PROTECTED]                         have teddy bears and even
>                                       teddy bears get drunk


                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to