public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* Re: [ECOS] data alignment issues
@ 2001-08-09  0:56 rob.wj.jansen
  2001-08-09  7:44 ` Trenton D. Adams
  0 siblings, 1 reply; 10+ messages in thread
From: rob.wj.jansen @ 2001-08-09  0:56 UTC (permalink / raw)
  To: tadams; +Cc: ecos-discuss

> Any comments on this alignment?  I thought the gcc compiler didn't do
> any alignment?

The compiler has to perform alignment since the ARM processor used will only read 32 bit words
on a 4 bytes boundary. As already written in one of the previous posts, a fetch of a 32 bit words
from a non aligned boundary will result in an exception.
To prevent any alignment problems, gcc will align all members on a word boundary (which is
a 4 byte boundary for the ARM core).

> Anyhow, I just ran a test.  I have the structure below.  All the char
> fields are just dummy values to test data alignment issues when sending
> the structure over the network to my PC.  Apparently, the PC compiler

You should never send structures to another platform in the hope that the alignment of structures
(and data widths of the members) are the same.
If both targets use the same alignment style and endianes this might work, you could check this
by populating a structure on both targets in the same way and comparing the actual memory content.

> I've forgotten how to read floats in hex! :)

That what computers are for:

     float f = 10.0;

     if(sizeof(f) == 4)
          printf("Your float reads %08X in hex.\n", *(int *) &f);

(you C ...)

Regards,

     Rob Jansen

Software Engineer
Competence Center Platforms
BU Mobile Communications
Meijhorst 60-10, 6537 KT Nijmegen, The Netherlands
Tel: +31-24-353-6329
Fax: +31-24-353-3613
mailto:Rob.WJ.Jansen@philips.com



^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: [ECOS] data alignment issues
@ 2001-08-09  8:19 rob.wj.jansen
  0 siblings, 0 replies; 10+ messages in thread
From: rob.wj.jansen @ 2001-08-09  8:19 UTC (permalink / raw)
  To: tadams; +Cc: ecos-discuss

Trenton,

> Why not send structures if it works?  After all, if I've tested it and

Oops, this is where I hit the send button too fast. What I meant is that you should not do this right away
but first check what happens (as you did). I am used to have a seperate versions of structs for file/network
I/O and internal use, the same program on a different platform will only need the I/O one - plus functions
to populate - to be changed.

Depending on the compiler used (both are gcc I think) you could use a packed structure by using the
"__attribute__ ((packed))" on the struct definition. When you are using lots of chars and shorts this will
really make some impact on the size of the struct.

> I didn't mean I couldn't read a float in hex.  I mean I don't know how
> it's stored in binary.  As in 00001000.10000000 would be 8.5, but I

Thanks, you got me scared for a minute :-) I wrote a MC68000 floating point library in assembly and
this is not something you want to remember too long ...

Regards,

Rob Jansen

Software Engineer
Competence Center Platforms
BU Mobile Communications
Meijhorst 60-10, 6537 KT Nijmegen, The Netherlands
Tel: +31-24-353-6329
Fax: +31-24-353-3613
mailto:Rob.WJ.Jansen@philips.com



^ permalink raw reply	[flat|nested] 10+ messages in thread
* [ECOS] data alignment issues
@ 2001-08-08 10:00 Trenton D. Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Trenton D. Adams @ 2001-08-08 10:00 UTC (permalink / raw)
  To: 'eCos discussion'

I figured I should start a new thread for this since it's slightly off
topic for that other question.

For those of you that are searching the archives, there's a bunch of
data alignment discussions under the subject "Network programming for
eCos under Linux". :)

Anyhow, I just ran a test.  I have the structure below.  All the char
fields are just dummy values to test data alignment issues when sending
the structure over the network to my PC.  Apparently, the PC compiler
and the arm-elf-gcc compiler align the floats the same because I didn't
have a problem at all.  I believe it was aligning them to 4-byte
boundaries because the sizeof () the structure was 40 where it should
have been 28.  So, that means 3 extra padding bytes per char.  I never
bothered to look at it in memory because I've forgotten how to read
floats in hex! :)

Any comments on this alignment?  I thought the gcc compiler didn't do
any alignment?

typedef struct
{
    /* version minor */
    unsigned short versionLS,
    /* version major */
        versionMS;

    /* current accelerometer voltage level */
    float accelerometerVoltage;
    char test1;
    /* current analog 1 voltage level */
    float analogVoltage1;
    char test2;
    /* current analog 2 voltage level */
    float analogVoltage2;
    char test3;
    /* current digital board voltage level */
    float boardVoltage;
    char test4;
    /* current rig temperature level */
     float rigTemperature;
} TStatusSignals;


Trenton D. Adams
Extreme Engineering
#17, 6025 - 12 St. SE
Calgary, Alberta, Canada
T2H 2K1

Phone: 403 640 9494 ext-208
Fax: 403 640 9599

http://www.extremeeng.com


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

end of thread, other threads:[~2001-08-09 11:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-09  0:56 [ECOS] data alignment issues rob.wj.jansen
2001-08-09  7:44 ` Trenton D. Adams
2001-08-09  7:55   ` Andrew Lunn
2001-08-09  7:59     ` Trenton D. Adams
2001-08-09  8:49     ` Trenton D. Adams
2001-08-09  9:05       ` Andrew Lunn
2001-08-09  9:11         ` Trenton D. Adams
2001-08-09 11:42   ` Grant Edwards
  -- strict thread matches above, loose matches on Subject: below --
2001-08-09  8:19 rob.wj.jansen
2001-08-08 10:00 Trenton D. Adams

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