This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: short pointers (32 bit) in 64 bit apps


Reza Roboubi <reza@parvan.net> writes:

> And that gets your ALU's doing a lot of unneeded additions and
> subtractions, every time you access such pointers.

I don't see how you can possibly avoid ALU operations given your
design goals (i.e., permitting the pointers to exist in memory areas
other than the low 4GB).  You are just asking for a way to make the
compiler generate them automatically.

Heck, even if you don't like C++, you can do it yourself with macros.

struct s
{
  uint32_t ps; /* Pseudo-pointer to next struct in list.  */
  ...
};

#define GET_SPS(p) \
  ((struct s *) ((p)->ps | ((uintptr_t) (p) & 0xffffffff00000000ULL)))
#ifdef NDEBUG
#define SET_SPS(p, q) \
  ((p)->ps = (uint32_t) ((uintptr_t) q & 0xffffffff))
#else
#define SET_SPS(p, q) \
  (assert (((uintptr_t) (p) & 0xffffffff00000000ULL)
           == (uintptr_t) (q) & 0xffffffff00000000ULL),
   (p)->ps = (uint32_t) ((uintptr_t) (q) & 0xffffffff))
#endif

For extra credit use statement expressions to avoid multiple
evaluation of the macro arguments.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]