public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yaro Pollak <yarop@altair-semi.com>
To: gcc-help@gcc.gnu.org
Subject: [Re: Unaligned access to packed structs on ppc405]
Date: Wed, 01 Feb 2006 12:03:00 -0000	[thread overview]
Message-ID: <43E0A378.6060607@altair-semi.com> (raw)

> Yaro Pollak writes:

> I am cross-compiling on GCC 3.4.1 for the PowerPC 405, which can handle 
> unaligned accesses in hardware.
> Whenever I am accessing members of a packed bit-struct by pointer, the 
> compiler produces byte accesses, instead of 4-byte accesses.
> I've tried to use -mstrict-align but to no avail.

Hi everyone,
I still didn't resolve this problem, and frankly, I am lost.
I was using GCC 3.4.1, so I've compiled GCC 4.0.1 and tried to compile the code with it, and the results were exactly the same.
I've tried to use -mno-strict-align and -mstrict-align and there was no effect on the assembly produced.

The code that I'm trying to compile is 

struct Test {
	unsigned	b	: 4;
	unsigned	c	: 8;
	unsigned	d	: 6;
	unsigned	e	: 3;
	unsigned	f	: 7;
	unsigned	g	: 6;
	unsigned	h	: 2;
}__attribute__((__packed__));

int main (void) {
	Test* pt = (Test*)1234;
	return pt->b + pt->c + pt->d;
}

and the resulting assembly from g++ -mcpu=405 -O3 - S -c -mno-strict-align looks like:
	li 9,1234
	lbz 11,0(9)
	lbz 10,1(9)
	rlwinm 8,11,4,24,27
	srwi 0,10,4
	lbz 3,2(9)
	or 0,0,8
	rlwinm 11,11,28,28,31
	add 11,11,0
	rlwinm 10,10,2,26,29
	lwz 0,12(1)
	srwi 3,3,6
	or 3,3,10
	add 3,11,3
	mtlr 0
	addi 1,1,8
	blr 


Note the 3 lbz.
If on the other hand I compile:

	Test pt;
	return pt.b + pt.c + pt.d;

The assembly looks like this:
	lwz 3,8(1)
	rlwinm 0,3,4,28,31
	rlwinm 9,3,12,24,31
	add 0,0,9
	rlwinm 3,3,18,26,31
	add 3,0,3
	lwz 0,28(1)
	addi 1,1,24
	mtlr 0
	blr 


Does anyone have any idea about this? This is a rather trivial problem, I MUST be doing something wrong, please help me.

Thanks,
Yaro


             reply	other threads:[~2006-02-01 12:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-01 12:03 Yaro Pollak [this message]
2006-02-04  4:25 ` Unaligned access to packed structs on ppc405 David Edelsohn

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=43E0A378.6060607@altair-semi.com \
    --to=yarop@altair-semi.com \
    --cc=gcc-help@gcc.gnu.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).