public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: m68k structure packing
@ 1997-10-01 12:16 Mike Stump
  1997-10-01 12:39 ` Joel Sherrill
  1997-10-02 18:37 ` Jim Wilson
  0 siblings, 2 replies; 26+ messages in thread
From: Mike Stump @ 1997-10-01 12:16 UTC (permalink / raw)
  To: egcs

> Date: Tue, 30 Sep 1997 23:05:48 -0600
> From: Jeffrey A Law <law@hurl.cygnus.com>

>   In message <199710010315.UAA28203@kankakee.wrs.com>you write:
>   > Don't know how.  All I can do it try a couple of testcases that should
>   > expose the tricky parts, I have done that.
> Read the docs for PCC_BITFIELD_MATTERS.

Sorry I have given the impression that I haven't read that, that isn't
the case.

> It describes a very particular problem (bitfields crossing certain
> alignment boundaries).

Yes.  Again, sorry I gave the impression that I didn't read, understand
and try the case discussed, as that isn't the case.

> It even includes code which attempts to set up this situation;

Yes...

> Then look at the resulting output

I must admit I didn't do that before because I didn't see that it
could offer any additional insight.  But, since you think it has some
relevance, I took a look at the output (and a few variations on it)
and I still don't see how it can offer any additional insight.  I did
see what I consider some additional minor nits... like padding at the
end when :0 is used, that we may want to go ahead and remove (padding
on a packed structure isn't desired or useful), and undesired
alignment when :0 is used, and because of the presence of the
undesired alignment, aligned loads and stores are generated, since the
data is aligned.  This, while it is a bug, won't cause codegen
problems, just incompatibilities if/when we fix that problem.

> and verify that you don't have any unaligned loads/stores.

Sorry I gave the impression that I haven't tested it, as that is not true.

> Doesn't seem all that hard to me.

Nor to me, as I I have already done all the testing that you seem to
imply.  Let me put it another way, I am to the point of happiness with
the code, that I don't know of any additional way to test it by hand.

> I think if you do that and can show Jim that it works then you'll
> both be happy.

Ah, now here is something I didn't do.  I have not shown you all all
the testcases I have looked at, nor all the resulting code...  I'll
see about putting together another mail message with all that you
request, but in general this isn't how I normally operate.  I normally
keep that level of detail to myself, and when the code is as I want,
then I submit the patches I've developed enmass.

I don't think we should force authors of code to prove to kenner that
a change is good enough for the FSF's compiler, and then force them to
go through the pain again to get it into the egcs compiler.  I think
we risk faster divergence that way, and keeping them converged is
better.  I thought that kenner would be generally be harder to deal
with, and while I may still generally think that is true, it wasn't in
this case.

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: m68k structure packing
@ 1997-10-01 15:08 Mike Stump
  1997-10-01 15:56 ` Peter Barada
  1997-10-02 20:01 ` Jim Wilson
  0 siblings, 2 replies; 26+ messages in thread
From: Mike Stump @ 1997-10-01 15:08 UTC (permalink / raw)
  To: pbarada, wilson; +Cc: egcs

> Date: Wed, 1 Oct 1997 11:52:44 -0400
> From: Peter Barada <pbarada@wavemark.com>
> To: wilson@cygnus.com

> If you have a short in the struct:

> struct {
> 	short b;
> 	char a;
> } z, list[10];

> then sizeof(z) could be 3 but is 4 due to alignment requirements(i.e
> malloc(n*sizeof(z))) and sizeof(list) is 40.

Is this fact, or theory?  On the sparc, which is unaffacted by my
change, with -fpack-struct we get 3 bytes.

struct foo1
{
  short b;
  char a;
} f[2] = {{ 1, 2}, {3, 4}}, b;

short i, *ip;

main () {
  ip = &f[1].b;
  i = *ip;
}

fails.  My patches may help the m68k fail in the same way I suspect.

> And obviously if you have a long, then the sizeof has to round up to a
> long.

That isn't what the code today does.

> Even if you pack the structure, you have to allow for alignment
> requirements.

That isn't what the code today does.


This issue is 100% independent of the issue I was interested in, but
since we are talking about it, it makes since to bring this issue up,
and see what others think about it.

Should the above code fail at runtime?  (You have to have a
STRICT_ALIGNMENT machine, pack a structure, and you may have to use
int or long or float or double to make it fail).  If not, should we
make it work by aligning it or by requiring what the pointer points to
is a packed short, then on dereference of a pointer to a packed short,
we could know to do byte accesses.

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: m68k structure packing
@ 1997-09-30 21:42 Jim Wilson
  1997-10-01  5:44 ` Kamil Iskra
  0 siblings, 1 reply; 26+ messages in thread
From: Jim Wilson @ 1997-09-30 21:42 UTC (permalink / raw)
  To: rth; +Cc: egcs

	> Gcc knows that it needs to access bitfields differently when a structure
	> is packed.  It may be that gcc will generate correct code with your patch
	> for cases that would ordinarily fail ...

	Yes it will.  I've used this on a number of occasions to get
	machine independant unaligned loads.  It works on all machines,
	even if gcc has to resort to byte loads and shifts.

I know that bitfield references to packed structures work.  This has never
been in doubt.

However, there remains a specific question here as to how this affects the
m68k port with respect to the known and documented problems with
PCC_BITFIELD_TYPE_MATTERS and STRUCTURE_SIZE_BOUNDARY.  It is not obvious
what the interaction is.  But as I mentioned in my previous mail, I am starting
to suspect that improvements to the unaligned/packed structure field support
over the years has accidentally solved this known problem, in which case this
may now be a `historical' problem.  If you haven't done so already, and if
you really care about this problem, take a look at the
PCC_BITFIELD_TYPE_MATTERS documentation.

Jim

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: m68k structure packing
@ 1997-09-30 20:16 Mike Stump
  1997-09-30 22:03 ` Jeffrey A Law
  0 siblings, 1 reply; 26+ messages in thread
From: Mike Stump @ 1997-09-30 20:16 UTC (permalink / raw)
  To: wilson; +Cc: egcs

> Date: Tue, 30 Sep 1997 19:57:52 -0700
> From: Jim Wilson <wilson@cygnus.com>

> It may be that gcc will generate correct code with your patch
> [ ... ] because the structure is marked as packed.  Can you please
> check?

Don't know how.  All I can do it try a couple of testcases that should
expose the tricky parts, I have done that.  The code works flawlessly.
Storing a bitfield, loading from a bitfield, incing a bitfield....
a long long bitfield, an int bitfield...  I cannot get it to fail,
therefore I cannot fix it.  My working assumption is there are
no bugs.

If we find one, I know how to fix it, but I just need a pointer to
the failure.  I have generally reviewed the code, and it all seems
reasonable.

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: m68k structure packing
@ 1997-09-30 16:58 Mike Stump
  1997-09-30 18:20 ` Jim Wilson
  0 siblings, 1 reply; 26+ messages in thread
From: Mike Stump @ 1997-09-30 16:58 UTC (permalink / raw)
  To: wilson; +Cc: egcs

> Date: Tue, 30 Sep 1997 14:55:51 -0700
> From: Jim Wilson <wilson@cygnus.com>

> With this patch, gcc will pack structures regardless of what
> STRUCTURE_SIZE_BOUNDARY is set to, but will now in some cases
> silently generate code that fails at run time.

I would be interested in any such cases that you know of.  This cannot
happen on the arm, if we are to believe the arm coff or netbsd ports
for the arm, as they reset STRUCTURE_SIZE_BOUNDARY to 8.  This cannot
happen on the sh, if we are to believe the sh ports, as
STRUCTURE_SIZE_BOUNDARY defaults to 8.  Only with -mpadstruct option
does the value change.  elxsi doesn't count because it was copied
wholesale from the VAX, and I suspect at the time, vax had it as 32,
also it doesn't count because I don't think a machine is left in the
world that can run.  dsp16xx, fx80, mn10200, pyr, spur, tahoe and
we32k I cannot comment on, other than to say I think we32k is dead.

That leaves m68k.  On the m68k the compiler did seem to go out of it's
way to generate correct code.  Further, Kamil has claimed that the
amiga m68k port works fine with STRUCTURE_SIZE_BOUNDARY as 8.

Why do you think generated code will fail?  Because of unaligned reads
and writes?  I see many popular machines, and ones that I know have
been tested well, that define STRICT_ALIGNMENT and have
STRUCTURE_SIZE_BOUNDARY set to 8.  Maybe if you describe that case I
can hunt for it.

If one goes back though the old ChangeLogs, one sees that many ports
used to have values other than 8, but over time, they were changed to
8.

I think that in the absence a bug that can be reproduced, and since it
has been accepted by the FSF for inclusion in the next FSF gcc
release, that it be included in egcs.

If people that have access to m68000 (not a 030 or a 020) could try
out -fpack-struct (with -O, without -O) with my changes, and try and
make it fail, that would be a big help in ensuring that no bug is
introduced.  It is probably imporant that the code run on a m68k that
requires alignment (if I understand Jim's concerns).

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: m68k structure packing
@ 1997-09-30 13:32 Mike Stump
  1997-09-30 14:56 ` Jim Wilson
  0 siblings, 1 reply; 26+ messages in thread
From: Mike Stump @ 1997-09-30 13:32 UTC (permalink / raw)
  To: mycroft; +Cc: egcs

> To: mrs@wrs.com (Mike Stump)
> From: mycroft@mit.edu (Charles M. Hannum)
> Date: 30 Sep 1997 16:01:24 -0400

> Um, doesn't this *severely* break compatibility?

I guess it depends upon how you use the words and what they mean to
you.  Yes, this work causes the compiler to not have a bug that it had
before, and lack of that bug makes some objects not binary compatible
with prior objects on some systems.  For completeness the systems are:

config/arm/arm.h:#define STRUCTURE_SIZE_BOUNDARY 32
config/dsp16xx/dsp16xx.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/elxsi/elxsi.h:#define STRUCTURE_SIZE_BOUNDARY 32
config/fx80/fx80.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/3b1g.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/a-ux.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/altos3068.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/apollo68.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/ccur-GAS.h:#define STRUCTURE_SIZE_BOUNDARY 16 
config/m68k/crds.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/hp2bsd.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/hp320.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/hp3bsd.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/hp3bsd44.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/isi.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/lynx-ng.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/lynx.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/mot3300.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/netbsd.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/next.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/pbb.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/plexus.h:#define STRUCTURE_SIZE_BOUNDARY 16 /* for compatibility with cc */
config/m68k/sun2.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/sun3.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/tower.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/m68k/vxm68k.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/mn10200/mn10200.h:#define STRUCTURE_SIZE_BOUNDARY 16
config/pyr/pyr.h:#define STRUCTURE_SIZE_BOUNDARY 32
config/sh/sh.h:#define STRUCTURE_SIZE_BOUNDARY (TARGET_PADSTRUCT ? 32 : 8)
config/spur/spur.h:#define STRUCTURE_SIZE_BOUNDARY 32
config/tahoe/tahoe.h:#define STRUCTURE_SIZE_BOUNDARY 32
config/we32k/we32k.h:#define STRUCTURE_SIZE_BOUNDARY 32

Note that only code that specifies -fpack-struct, or attribute
((packed)) on only the above systems is broken by the change, code
that does not, cannot be broken.  The code that specifies either of
these two mechanisms, is now more compatible across platforms
(desirable), where as before, the compiler would just do the wrong
thing on some platforms.  I think the consistency across platforms,
and providing a way for a programmer to customize structure layout to
his liking is more important than allowing this bug to continue to
live.  Be aware, that the people using -fpack-struct or attribute
((packed)) are exactly the people that would want this problem fixed,
so to them, they can tolerate the incompatibility.

Do you use -fpack-struct or attribute ((packed))?

^ permalink raw reply	[flat|nested] 26+ messages in thread
* m68k structure packing
@ 1997-09-30 12:08 Mike Stump
  1997-09-30 12:57 ` Charles M. Hannum
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Mike Stump @ 1997-09-30 12:08 UTC (permalink / raw)
  To: egcs

Could you fold in this work from the FSF sources?  Thanks.


Fri Sep 26 14:06:45 1997  Mike Stump  <mrs@wrs.com>

	* c-decl.c (start_struct): Ensure that structs with forward
	declarations are in fact packed when -fpack-struct is given.

Wed Sep 24 11:31:24 1997  Mike Stump  <mrs@wrs.com>

	* stor-layout.c (layout_record): Ignore STRUCTURE_SIZE_BOUNDARY if
	we are packing a structure.  This allows a structure with only
	bytes to be aligned on a byte boundary and have no padding on a
	m68k.

Index: stor-layout.c
===================================================================
RCS file: /folk/mrs/.cvsroot/egcs/gcc/stor-layout.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -p -r1.1.1.1 -r1.2
*** stor-layout.c	1997/08/15 18:56:53	1.1.1.1
--- stor-layout.c	1997/09/24 18:41:48	1.2
*************** layout_record (rec)
*** 306,316 ****
       tree rec;
  {
    register tree field;
- #ifdef STRUCTURE_SIZE_BOUNDARY
-   unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
- #else
    unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
- #endif
    /* These must be laid out *after* the record is.  */
    tree pending_statics = NULL_TREE;
    /* Record size so far is CONST_SIZE + VAR_SIZE bits,
--- 306,312 ----
*************** layout_record (rec)
*** 324,329 ****
--- 320,330 ----
       that we know VAR_SIZE has.  */
    register int var_align = BITS_PER_UNIT;
  
+ #ifdef STRUCTURE_SIZE_BOUNDARY
+   /* Packed structures don't need to have minimum size.  */
+   if (! TYPE_PACKED (rec))
+     record_align = MAX (record_align, STRUCTURE_SIZE_BOUNDARY);
+ #endif
  
    for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
      {
*************** layout_union (rec)
*** 563,579 ****
       tree rec;
  {
    register tree field;
- #ifdef STRUCTURE_SIZE_BOUNDARY
-   unsigned union_align = STRUCTURE_SIZE_BOUNDARY;
- #else
    unsigned union_align = BITS_PER_UNIT;
- #endif
  
    /* The size of the union, based on the fields scanned so far,
       is max (CONST_SIZE, VAR_SIZE).
       VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
    register int const_size = 0;
    register tree var_size = 0;
  
    /* If this is a QUAL_UNION_TYPE, we want to process the fields in
       the reverse order in building the COND_EXPR that denotes its
--- 564,582 ----
       tree rec;
  {
    register tree field;
    unsigned union_align = BITS_PER_UNIT;
  
    /* The size of the union, based on the fields scanned so far,
       is max (CONST_SIZE, VAR_SIZE).
       VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
    register int const_size = 0;
    register tree var_size = 0;
+ 
+ #ifdef STRUCTURE_SIZE_BOUNDARY
+   /* Packed structures don't need to have minimum size.  */
+   if (! TYPE_PACKED (rec))
+     union_align = STRUCTURE_SIZE_BOUNDARY;
+ #endif
  
    /* If this is a QUAL_UNION_TYPE, we want to process the fields in
       the reverse order in building the COND_EXPR that denotes its
Index: c-decl.c
===================================================================
RCS file: /folk/mrs/.cvsroot/egcs/gcc/c-decl.c,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -c -p -r1.1.1.4 -r1.2
*** c-decl.c	1997/09/16 02:07:07	1.1.1.4
--- c-decl.c	1997/09/26 21:09:25	1.2
*************** start_struct (code, name)
*** 5527,5532 ****
--- 5527,5533 ----
    if (ref && TREE_CODE (ref) == code)
      {
        C_TYPE_BEING_DEFINED (ref) = 1;
+       TYPE_PACKED (ref) = flag_pack_struct;
        if (TYPE_FIELDS (ref))
  	error ((code == UNION_TYPE ? "redefinition of `union %s'"
  		: "redefinition of `struct %s'"),
------

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

end of thread, other threads:[~1997-10-02 21:40 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-01 12:16 m68k structure packing Mike Stump
1997-10-01 12:39 ` Joel Sherrill
1997-10-02 18:37 ` Jim Wilson
  -- strict thread matches above, loose matches on Subject: below --
1997-10-01 15:08 Mike Stump
1997-10-01 15:56 ` Peter Barada
1997-10-01 16:16   ` Per Bothner
1997-10-02 20:14     ` Jim Wilson
1997-10-02  6:49   ` Paul Koning
1997-10-02 20:09   ` Jim Wilson
1997-10-02 20:01 ` Jim Wilson
1997-10-02 21:40   ` Richard Henderson
1997-09-30 21:42 Jim Wilson
1997-10-01  5:44 ` Kamil Iskra
1997-09-30 20:16 Mike Stump
1997-09-30 22:03 ` Jeffrey A Law
1997-09-30 16:58 Mike Stump
1997-09-30 18:20 ` Jim Wilson
1997-10-01  9:02   ` Peter Barada
1997-09-30 13:32 Mike Stump
1997-09-30 14:56 ` Jim Wilson
1997-09-30 12:08 Mike Stump
1997-09-30 12:57 ` Charles M. Hannum
1997-09-30 19:58 ` Jim Wilson
1997-09-30 21:13   ` Richard Henderson
1997-09-30 21:22   ` Jim Wilson
1997-10-01 15:14 ` Jim Wilson

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