This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


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

Re: COMMON requires 4 bytes of padding at start


Janus Weil wrote:
>> d) Action items: I suggest
>> (i) To add an option to optionally do no padding [for COMMON] and enable
>> that option by default (I think we can ignore SEQUENCE)
>>     
> Here is a patch which changes the default behaviour, so that no
> padding is done in COMMON blocks. In addition a flag -falign-commons
> is introduced, which restores the old behaviour (i.e. automatic
> padding).
>   
You need to document the option in invoke.texi; and you should write
what the option implies; especially, one should mention that one should
compile all files which use same (named or blank) common with the same
option -- either -fnoalign-commons (default) or with -falign-commons.

I would also update the warnings. Instead of:
   Warning: COMMON 'com' at (1) requires 4 bytes of padding at start

I would use (for -fnoalign-commons) something like
  Warning: COMMON 'com' at (1) has unfavorable alignment for
performance; reorder elements or use -falign-commons

and with -falign-commons:
  Warning: COMMON 'com' at (1) uses 4 bytes of padding at start which
might give wrong results; reorder elements or use -fno-align-commons

One can argue whether the message for -fnoalign-commons should be
printed by default; maybe one offers a -Walign-commons (e.g. on by
default) which one can then be turned off if wanted. Maybe you can also
come up with a better warning message.

Mentioning the align-commons option allows the user to find an
explanation in the manual. One could even include an example like:

"Example: In the following program, the variable "r" is not aligned,
which slows down the memory access.
  integer(4) :: i
  real(8) :: r
  common /com/ i, r
This can be solved by swapping "i" and "r" (which has to be done in all
scopes of "com") or by using -falign-commons. However, then the
definition of all commons with the same name needs to be identical;
otherwise this leads to wrong code; for "com" an example would be to use
in another scope
  integer(4) :: i
  common /com/ i"

> With this patch one gets the expected output "2 3" for Tobias' test
> case when omitting -falign-commons. Including the flag gives the old
> output "0 2".
>   
For completeness: I think my test was invalid ISO Fortran but I think
the following is valid (additional trailing variables need not to be
present in all COMMONs, though I'm not positive):

subroutine one()
  common /com/ i
  print *, i
end subroutine one

real*8 r
common /com/ i, r
i = 5
call one()
end

Tobias


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