From: Steven Stallion <sstallion@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] ureg alignment
Date: Fri, 9 May 2014 09:28:53 -0500 [thread overview]
Message-ID: <CAGGHmKF-upNXMZjzhrmp4zGsFvS25hx2BJeZapndYB0QbusgJw@mail.gmail.com> (raw)
In-Reply-To: <51d4d8ec419f841a99baf30ede300c25@brasstown.quanstro.net>
On Fri, May 9, 2014 at 9:21 AM, erik quanstrom <quanstro@quanstro.net> wrote:
> on 64-bit machines, the unions in the ureg.h can lead to
> internal padding. (power64 avoids this issue because everything
> is 64-bit aligned anyway.) to sidestep the issue, i think
> it might make sense to use #defines. for example, for arm
> the conversion would look something like this:
>
> typedef struct Ureg {
> ulong r0;
> ulong r1;
> ulong r2;
> ulong r3;
> ulong r4;
> ulong r5;
> ulong r6;
> ulong r7;
> ulong r8;
> ulong r9;
> ulong r10;
> ulong r11;
> ulong r12; /* sb */
> ulong r13;
> #define sp r13
> ulong r14;
> #define link r14
> ulong type; /* of exception */
> ulong psr;
> ulong pc; /* interrupted addr */
> } Ureg;
>
> is there any reason not to do this?
Ugh, no! Is there a case where the padding is a problem? Normally
registers belonging to the same union are uniform in size. Those
defines will expand anywhere and not behave as expected:
ulong sp = ureg->sp;
This could lead to all sorts of entertaining problems.
Steve
next prev parent reply other threads:[~2014-05-09 14:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-09 14:21 erik quanstrom
2014-05-09 14:28 ` Steven Stallion [this message]
2014-05-09 14:31 ` erik quanstrom
2014-05-09 14:56 ` Charles Forsyth
2014-05-09 15:29 ` erik quanstrom
2014-05-09 15:45 ` Charles Forsyth
2014-05-09 15:52 ` erik quanstrom
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=CAGGHmKF-upNXMZjzhrmp4zGsFvS25hx2BJeZapndYB0QbusgJw@mail.gmail.com \
--to=sstallion@gmail.com \
--cc=9fans@9fans.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).