Discussion:
gcc Sparc alignment problems
Phil Prentice
2004-04-19 19:38:28 UTC
Permalink
Hi

Does anyone know of a gcc compiler flag or option that would enable us to
compile and successfully run 'C' code that will access mis-aligned integers
or dioubles which runs on a SPARC workstation running Solaris.

The Sun compiler achieves this by means of the -misalign flag

If you are able to help, I would be grateful to hear from you

Many thanks.

Regards

Phil
Dale Johannesen
2004-04-19 20:58:52 UTC
Permalink
Post by Phil Prentice
Does anyone know of a gcc compiler flag or option that would enable us to
compile and successfully run 'C' code that will access mis-aligned integers
or dioubles which runs on a SPARC workstation running Solaris.
The Sun compiler achieves this by means of the -misalign flag
If you are able to help, I would be grateful to hear from you
Many thanks.
The documentation lists -munaligned-doubles . I don't know how well it
works.
Jim Wilson
2004-04-19 23:10:52 UTC
Permalink
Post by Dale Johannesen
The documentation lists -munaligned-doubles . I don't know how well it
works.
This is something completely different.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com
Mike Stump
2004-04-19 21:41:56 UTC
Permalink
Post by Phil Prentice
Does anyone know of a gcc compiler flag or option that would enable us to
compile and successfully run 'C' code that will access mis-aligned integers
or dioubles which runs on a SPARC workstation running Solaris.
A trap handler that does the unaligned load might be best, gcc
generally doesn't support doing this without typing information, and
even when that is used, you cannot violate the type system and expect
it to work.

This could be done be changing your port to generate the unaligned
loads and store all the time instead of the aligned versions, but, this
would cause generated code to suffer significant performance
degradation, which is why in general, people don't do this.
Jim Wilson
2004-04-19 23:20:23 UTC
Permalink
Post by Phil Prentice
Does anyone know of a gcc compiler flag or option that would enable us to
compile and successfully run 'C' code that will access mis-aligned integers
or dioubles which runs on a SPARC workstation running Solaris.
The Sun compiler achieves this by means of the -misalign flag
The Sun -misalign flag was originally added for people migrating from
Sun3 (m68k) systems to Sun4 (sparc) systems. m68k systems only align
data to 2 bytes, whereas sparc systems align data to 4 bytes. So if you
have existing data created on a m68k system, you might not be able to
read it on a sparc system. -misalign adds the assumption that all
pointers point to unaligned data, and thus we use byte loads and shift
to access all data. This allows use of m68k created data on a sparc system.

The m68k to sparc switchover happened so long ago that people really
shouldn't need the -misalign flag anymore. Use of this option will
seriously hurt performance. You would be much better off if you use
attribute packed and/or attribute aligned to make your data structures
match your data.

I did once add an equivalent option to gcc at Cygnus a long time ago,
but I never cleaned it up to the point where I felt confident that it
would be accepted into the FSF gcc sources. It wasn't hard to add it.
You just add another flags to MEM to indicate that they are unaligned.
You set this flag when expanding an INDIRECT_REF in expand_expr. In
emit_move_insn, if the source is a MEM with this flag set, then you call
extract_bitfield. If the dest is a MEM with this flag set, then you
call store_bitfield.

As a bonus, one can use this to implement unaligned pointers. Just add
an attribute unaligned, and when we deference a pointer with this
attribute set, we set the MEM unaligned flag.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com
Loading...