Re: 64 bit->48 bit pointer hacks...
"Dale E. Martin" <dale@the-martins.org> writes:
>> The current generation AMD64 MMUs can only handle 64-bit pointers in
>> which the high-order 17 bits are all the same (40 bits of information).
>
> I was mulling this over the other day... Say I've got a string class that
> looks like this:
>
> class string {
> class shortString {
> char flag;
> char [7] smallString;
> };
>
> class {
> union {
> char *ptr;
> shortString;
> } shortStringOrPtr;
> } data;
> };
>
> Is there some magic value I can write into "flag", that in combination with
> the understanding of how 64 bit pointers get truncated down to 48 bit
> virtual addresses that will allow me to store either a 7 byte string or a
> char * in the same space?
>
> Thanks,
> Dale
Since any address would have leading 0 bits any flag != 0 would work,
for now, till bigger CPUs are build.
A much better way is to ensure all pointers are even and use the
lowest bit as flag, as most languages with garbage collectors do:
class shortString {
char [7] smallString;
uint8_t padding:7;
uint8_t tag:1;
}
This costs you pointers into the middle of strings though but you kind
of loose those for small strings already.
MfG
Goswin
Reply to: