public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* Proposal: (u)intptr_t replaces (unsigned) long as opaque type
@ 2010-09-18 21:42 Greg McGary
  2010-09-18 23:54 ` Matthew Wilcox
  2010-09-19  4:33 ` Alexey Zaytsev
  0 siblings, 2 replies; 10+ messages in thread
From: Greg McGary @ 2010-09-18 21:42 UTC (permalink / raw)
  To: linux-arch

  I am porting Linux to a new architecture (a massively multi-threaded network processor), which has a unique and bothersome characteristic: sizeof (void*) > sizeof (long).  In most regards, it is a 32-bit machine, but pointers and all GPRs are 48 bit.  Pointers occupy 64 bits in memory, with 16 bits ignored by load/store.

Unfortunately, the kernel is thick with pointer/int casts and universally assumes that sizeof (void*) == sizeof(long).  The first phase of the port is s/long/intptr_t/ and s/unsigned long/uintptr_t/ for data that hold addresses and for casts to/from address data.  I think it improves code comprehensibility to use (u)intptr_t for opaque types and for address arithmetic.  I'm three weeks into the project and have almost 5000 changes.  I probably have another week and a few thousand more to go before I have eliminated the pointer/int cast warnings and can work on more substantive phases.

For most (all?) existing ports, (u)intptr_t=(unsigned) long, so in theory there should be zero change to the compiled Linux image for conventional ILP=32 LP=64 architectures.

If the intent is really to extend or truncate with a cast between pointer and integer, it can be done like so:

     void *ptr;
     long l;
     int i;
     long long ll;

     ptr = (void *)(intptr_t) l;
     l = (long)(intptr_t) ptr;

     ptr = (void *)(intptr_t) ll;
     ll = (long long)(intptr_t) ptr;

     ptr = (void *)(intptr_t) i;
     i = (int)(intptr_t) ptr;

Are maintainers willing to accept patches to covert from (unsigned) long and (u)intptr_t ?  I propose to do this in many small installments for digestibility and to moderate the downstream impact of merge conflicts.

G

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-09-21  6:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-18 21:42 Proposal: (u)intptr_t replaces (unsigned) long as opaque type Greg McGary
2010-09-18 23:54 ` Matthew Wilcox
2010-09-19  2:43   ` Greg McGary
2010-09-19  4:06     ` Matthew Wilcox
2010-09-19 16:53       ` Greg McGary
2010-09-20  9:30         ` Arnd Bergmann
2010-09-20 20:28           ` Greg McGary
2010-09-21  6:32             ` Arnd Bergmann
2010-09-19  4:33 ` Alexey Zaytsev
2010-09-19  6:50   ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox