public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [Re: Unaligned access to packed structs on ppc405]
@ 2006-02-01 12:03 Yaro Pollak
  2006-02-04  4:25 ` Unaligned access to packed structs on ppc405 David Edelsohn
  0 siblings, 1 reply; 2+ messages in thread
From: Yaro Pollak @ 2006-02-01 12:03 UTC (permalink / raw)
  To: gcc-help

> 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


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

end of thread, other threads:[~2006-02-04  4:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-01 12:03 [Re: Unaligned access to packed structs on ppc405] Yaro Pollak
2006-02-04  4:25 ` Unaligned access to packed structs on ppc405 David Edelsohn

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).