public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Bad offset to struct member in generated code
@ 2007-12-05  0:55 Paul Zimmerman
  2007-12-05  1:21 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Zimmerman @ 2007-12-05  0:55 UTC (permalink / raw)
  To: gcc

Hi,

I have a problem while porting gcc to a custom processor. Here is a
simplified example:

struct big_struct {
	...
	int a;
	char b;
	char c;
	...
} testme;

char char_tmp;
int int_tmp;

int testit(void)
{
	char_tmp = testme.c;
	int_tmp = testme.a;
}

For the first line of code in testit(), gcc will load the address of
'testme.c' into a register, then do an indirect 8-bit load with an
offset of 0 to fetch the value of 'testme.c'. This is fine.

For the second line, gcc will reuse the same address register, and
generate an indirect 32-bit load with an offset of -5 to fetch the
value of 'testme.a'. But on our custom processor, the offsets of
indirect load instructions are scaled by the size of the data item.
So the assembly instruction generated for the second line is something
like "ld32 %r1, %r0, -5/4", which can not be translated by the
assembler.

So when accessing a data structure, we need gcc to always use a base
address that is a multiple of 4, to prevent this from happening.

So how do I tell gcc about this limitation of our architecture? Do I do
this somehow using the REG_MODE_OK_FOR_BASE_P or
GO_IF_MODE_DEPENDENT_ADDRESS macros in our architecture's .h file? I am
using the gcc 4.0.2 sources if that matters.

Thanks,
Paul
paulz at synopsys dot com

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

* Re: Bad offset to struct member in generated code
  2007-12-05  0:55 Bad offset to struct member in generated code Paul Zimmerman
@ 2007-12-05  1:21 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2007-12-05  1:21 UTC (permalink / raw)
  To: Paul Zimmerman; +Cc: gcc

"Paul Zimmerman" <Paul.Zimmerman@synopsys.com> writes:

> For the second line, gcc will reuse the same address register, and
> generate an indirect 32-bit load with an offset of -5 to fetch the
> value of 'testme.a'. But on our custom processor, the offsets of
> indirect load instructions are scaled by the size of the data item.
> So the assembly instruction generated for the second line is something
> like "ld32 %r1, %r0, -5/4", which can not be translated by the
> assembler.
> 
> So when accessing a data structure, we need gcc to always use a base
> address that is a multiple of 4, to prevent this from happening.
> 
> So how do I tell gcc about this limitation of our architecture? Do I do
> this somehow using the REG_MODE_OK_FOR_BASE_P or
> GO_IF_MODE_DEPENDENT_ADDRESS macros in our architecture's .h file? I am
> using the gcc 4.0.2 sources if that matters.

You need to fix this in GO_IF_LEGITIMATE_ADDRESS.  It may help to look
at thumb1_legitimate_address_p and thumb_legitimate_offset_p in
config/arm/arm.c.

Ian

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

end of thread, other threads:[~2007-12-05  1:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-05  0:55 Bad offset to struct member in generated code Paul Zimmerman
2007-12-05  1:21 ` Ian Lance Taylor

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