[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::fortran

Title:Digital Fortran
Notice:Read notes 1.* for important information
Moderator:QUARK::LIONEL
Created:Thu Jun 01 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1333
Total number of notes:6734

1183.0. "Compile time alignment warning, but no run time problem?" by PEACHS::LAMPERT (Pat Lampert, UNIX Applications Support, 343-1050) Tue Feb 18 1997 18:29

The Fortran User Manual says that an alignment warning
will be generated if commons are not "naturally aligned".
On page 4-17 "naturally aligned" means that the starting
address of the data item is an exact multiple of the
data item size.

Based on this I can see that the warnings generated 
when the code snippet below is compiled, are valid per 
the documentation. 

My question is; why are warnings generated when the
data is still at least longword aligned? As far as 
I can tell no PAL fixup is needed for this code to
run. Is there some other way that non-naturally aligned
data foils optimization?

Thanks.

Pat

------------------------


c       program unal

        double  precision       foo1
        double  precision       foo2
        integer                 foo3
        double  precision       foo4
        integer                 foo5
        common /x/ foo1,foo2,foo3,foo4,foo5

        foo1 = 1
        foo2 = 1
        foo3 = 1
        foo4 = 1
        foo5 = 1


        call doit()

        end

        subroutine doit()
        double precision        foo1
        double precision        foo2
        integer                 foo3
        double precision        foo4
        integer                 foo5
        common /x/ foo1,foo2,foo3,foo4,foo5

        foo1 = 1
        foo2 = 1
        foo3 = 1
        foo4 = 1
        foo5 = 1

        return
        end
opus.alf.dec.com> f77 -o unal unal.f
fort: Warning: unal.f, line 6: Alignment of variable or array is inconsistent wi
        double  precision       foo4
--------------------------------^
fort: Warning: unal.f, line 24: Alignment of variable or array is inconsistent w
        double precision        foo4
--------------------------------^
opus.alf.dec.com> unal
opus.alf.dec.com>


T.RTitleUserPersonal
Name
DateLines
1183.1No trap needed if the compiler knows it's misalignedWIBBIN::NOYCEPulling weeds, pickin' stonesWed Feb 19 1997 08:3211
Since foo4 is not quadword-aligned, the compiler doesn't generate a simple
load-double-precision or store-double-precision instruction to access it.
When it's accessing foo4 directly, it generates code to copy it one longword
at a time to/from a buffer on the stack, so it can access the stack buffer
directly.  This is a significant cost, but at least the compiler avoids
taking a trap.

Much worse is the overhead that arises if you pass foo4 as a parameter to
a subroutine that expects all parameters to be aligned.  The subroutine will
use a load-double or store-double instruction, which will incur a trap, to
be fixed up by the operating system at a cost of several hundred instructions.
1183.2TLE::EKLUNDAlways smiling on the inside!Wed Feb 19 1997 09:5423
    	The warning is issued at compile time for two reasons -
    to alert the user that there MAY be very serious performance
    consequences (as Bill mentioned in the last reply), and to
    let the user know that the code generated might be improved
    if they could arrange to improve the alignment of the variable
    somehow.  In ALL cases, the code should execute properly,
    whether or not the variables are aligned properly (except for
    very unusual cases with volatile accesses), but performance
    will suffer to some degree.  If the compiler can see all of
    what's happening, it produces code to avoid the traps - but
    this code is not quite as good as if the variable were
    aligned properly.  If the compiler cannot see all the code,
    then a very significant penalty may occur (the trap).  The
    most common case of the latter is when an actual argument is
    assumed to be aligned, but it turns out that it is not.
    Anyway, the bottom line is that the compiler should always
    issue the warning when it can see the misalignment so that
    the user can improve the accesses.
    
    Cheers!
    Dave Eklund
    
                                                    
1183.3Thanks.PEACHS::LAMPERTPat Lampert, UNIX Applications Support, 343-1050Wed Feb 19 1997 12:543
Thanks for the very complete reply.

Pat