This is the mail archive of the crossgcc@sourceware.org mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FW: ARM packed structures


 
Miller, Carl wrote: 
>Dimitry Andric wrote:
>>
>> Caputo, Tim wrote:
>>
>> >I am having a problem with structures using the arm cross complier 
>> >I've built.  Initially I noticed that my structures were not being 
>> >packed in memory.  I realize now that this is meant to be efficient,

>> >however, I need to share these structures with legacy code on 
>> >another processor and with specialty hardware that both expect/need 
>> >them to be packed.  I tried the pragma route, the attribute route 
>> >and finally was successful packing my structures with the directive
-fpack_struct.
>> 
>> Don't do that.  Read the gcc manual, and use __attribute__((packed)) 
>> instead.

When I mentioned that I tried using __attribute__((packed)) I failed to
say that I get a warning from gcc (version 3.4.5) that the 'packed'
attribute is ignored.

>
> Another alternative is -mstructure-size-boundary={8,32}, depending on 
> the types of alignment issues you're having.  Tagging all your struct 
> definitions with __attribute__((__packed__)) may solve a larger set of
issues.
>
>> >Unfortunately this resulted the compiler being extremely 
>> >conservative in how it accessed elements of the struct.  It now 
>> >reads one byte at a time from memory and reconstructs longwords in 
>> >registers (I assume it is worried about the whole structure being 
>> >unaligned in memory.)
>> 
>> It is not "worried", arm processors just *require* you to do this 
>> dance.  It depends on the specific cpu model how complicated the 
>> dance is. :)
>
> To get the minimum size dance required by your particular CPU, tell 
> GCC which architecture or which particular core it is with -march= or 
> -mcpu=.
>
>                         -----Carl

I am have been using -mcpu-arm926ejs (straight out of the gcc manual).
I understand that if the structures were actually unaligned that there
were have to be multiple accesses from memory to retrieve the data.
However, they are not and I am at a loss as to how to the compiler to
understand that that is the case.  As I mentioned earlier I have tried
to explicitly align instances of the structure and the struct itself
through attributes (per the manual) and have seen no difference.

Lastly, I tried -mstructure-size-boundary and it is an "invalid option"
in both 3.4.5 and 3.2 (I moved from 2.9.3 due to it inability to handle
a long_call attribute for functions).

Thanks,
Tim

--
For unsubscribe information see http://sourceware.org/lists.html#faq


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]