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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reza Roboubi <reza@xxxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux