public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Unaligned access to packed structs on ppc405
@ 2006-01-29 17:16 David Edelsohn
  2006-01-30 12:03 ` Yaro Pollak
  0 siblings, 1 reply; 10+ messages in thread
From: David Edelsohn @ 2006-01-29 17:16 UTC (permalink / raw)
  To: Yaro Pollak; +Cc: 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 acceses.
> I've tried to use |-mstrict-align but to no avail.

	What does "|-mstrict-align" mean?  -mstrict-align means "do not
assume that unaligned accesses are handled by the system."  You are
requesting that the compiler assume the target requires strict alignment
and then questioning why it is accessing a packed bit-struct assuming the
least alignment.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: Unaligned access to packed structs on ppc405
@ 2006-02-05 18:35 John Yates
  2006-02-05 21:02 ` David Edelsohn
  0 siblings, 1 reply; 10+ messages in thread
From: John Yates @ 2006-02-05 18:35 UTC (permalink / raw)
  To: David Edelsohn, Yaro Pollak; +Cc: gcc-help

David,

Do I read this correctly?  Are you truly saying that two structs
with identical layout will trigger different code sequences just
because one was declared packed?

(This is just the sort of thing that drives me crazy when trying
to coax a compiler into producing good code.)

/john

-----Original Message-----
From: David Edelsohn [mailto:dje@watson.ibm.com]
Sent: Friday, February 03, 2006 11:26 PM
To: Yaro Pollak
Cc: gcc-help@gcc.gnu.org
Subject: Re: Unaligned access to packed structs on ppc405


>>>>> Yaro Pollak writes:

> If on the other hand I compile:
> 
>    Test pt;
>    return pt.b + pt.c + pt.d;
> 
>    lwz 3,8(1)

	That is an artifact of the example.  If I declare "pt" as a global
variable, GCC 4.1 prerelease produces three lbz.

	The lbz has to do with the size and the packed alignment.  With
the packed structure, GCC chooses the smallest memory access that covers
the bitfield.  Once GCC has chosen bytes, it cannot merge the loads
together.  If the structure were not declared packed, GCC would use wider
loads with masking, and then determine that the loads refer to the same
object. 

David

^ permalink raw reply	[flat|nested] 10+ messages in thread
* [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; 10+ 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] 10+ messages in thread
* RE: Unaligned access to packed structs on ppc405
@ 2006-01-30 16:18 Matthew Jones
  2006-01-30 16:26 ` Yaro Pollak
  0 siblings, 1 reply; 10+ messages in thread
From: Matthew Jones @ 2006-01-30 16:18 UTC (permalink / raw)
  To: gcc-help

> From: Yaro Pollak
>
> Greetings,
> 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 acceses. I've tried to use |-mstrict-align but to
> no avail. Am I doing something wrong?

Are you sure it is the compiler? Are you looking at the generated
assembler, or inferring this from a logic analyser? If its the
second case, it could be the uP rather than gcc.

-- 
Matthew JONES
http://www.tandbergtv.com/

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Unaligned access to packed structs on ppc405
@ 2006-01-29 10:00 Yaro Pollak
  0 siblings, 0 replies; 10+ messages in thread
From: Yaro Pollak @ 2006-01-29 10:00 UTC (permalink / raw)
  To: gcc-help

Greetings,
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 acceses.
I've tried to use |-mstrict-align but to no avail.
Am I doing something wrong?

Thanks in advance,
Yaro
|

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

end of thread, other threads:[~2006-02-06 10:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-29 17:16 Unaligned access to packed structs on ppc405 David Edelsohn
2006-01-30 12:03 ` Yaro Pollak
2006-02-02 16:13   ` David Edelsohn
  -- strict thread matches above, loose matches on Subject: below --
2006-02-05 18:35 John Yates
2006-02-05 21:02 ` David Edelsohn
2006-02-06 10:18   ` Yaro Pollak
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
2006-01-30 16:18 Matthew Jones
2006-01-30 16:26 ` Yaro Pollak
2006-01-29 10:00 Yaro Pollak

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