I've given a lot of thought to doing something similar myself, but I
haven't tried anything yet.
Maurizio Vitale wrote:
is there a way to have 4 byte (data) pointers without resorting to
-m32?
I'm nearly certain there is not.
I'd like to have 64 bit code, but for a specific library I'm writing
cache behaviour
would improve if pointers were smaller. Pointers to code would stay at
8 bytes.
I can't tell whether you are asking for more than would be practical
without changing GCC itself.
What I had in mind was to have pointers to just a few specific data
types be 32 bit and in all the source code accessing those data types I
would need to declare pointers as xxx_ptr instead of xxx*
Each xxx would then be given a fixed (source code) assignment to one of
a few pools, and each pool would be allocated 4GB of virtual address
space at program startup (which doesn't become actual virtual memory
until used).
Then you need appropriate override of new (I don't know those details
myself without a little research) to get xxx object allocated into the
pools and of course the source code must never use xxx_ptr pointing to
and xxx objects allocated on the stack (function locals).
If GCC dowsn't support this mode (and I couldn't find anything in the
documentation)
How could it? Even if you force the heap to be contained that way, what
about the stack and static memory? It would be very hard to force all
those together into one 4GB area.
I'm thinking about using the linker scripts for forcing all data/heap
to be in 2Gb
Stack as well?
and then add the top 32 bits when dereferencing "pointers", if there's
a way to get
those 32 bits as a link time constant, rather than storing them in a
memory location.
Would that help much? The x86_64 instruction set doesn't have much
support for 64 bit integer constants. I'm far from sure, but I think
getting the top bits from a class static const variable would work
nearly as well as making the value known at link time.
If I wanted it known at link time, I think I would declare a global
(maybe class static would work) uninitialized array of 4G chars. It's
address would then be known at link time, then I'd force my override of
new to use that as the pool. Of course that is just for my idea of
xxx_ptr for a few important xxx classes.
For your idea of forcing more things together at link time, so all data
would be in one 4Gb area, if you know the linker well enough to do that,
don't you know it well enough to make it provide the link time address?