All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg McGary <greg@mcgary.org>
To: linux-arch@vger.kernel.org
Subject: Proposal: (u)intptr_t replaces (unsigned) long as opaque type
Date: Sat, 18 Sep 2010 14:42:35 -0700	[thread overview]
Message-ID: <4C95324B.2030707@mcgary.org> (raw)

  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

             reply	other threads:[~2010-09-18 21:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-18 21:42 Greg McGary [this message]
2010-09-18 23:54 ` Proposal: (u)intptr_t replaces (unsigned) long as opaque type 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C95324B.2030707@mcgary.org \
    --to=greg@mcgary.org \
    --cc=linux-arch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.