Eight-byte alignment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Voigt [C++ MVP]

    #16
    Re: Ben, how do you explain " Implicit_Size_o f_Int32 == 8 " ?


    "Jeff?Relf" <Jeff_Relf@Yaho o.COMwrote in message
    news:Jeff_Relf_ 2007_Dec_5__1_3 7_P7@Cotse.NET. ..
    ?_Ben_Voigt_C, _D71eGS.Airband .NET Phx.GBL
    2.48 Hours, Outlook_O19, Dec 5, 2007, 11._1 A, BS99eu
    >
    Re: This VC++ 8 code of mine, without the " /O2 " compiler option:
    " #pragma warning( disable: 4007 4189 4430 4508 )
    WinMain( int, int, int, int ) {
    const __int32 Int32 = 0 ; const __int64 Int64 = 0 ;
    >
    int Implicit_Size_o f_Int32 = int( & Int64 ) - int( & Int32 );
    // Breaking here, ' Implicit_Size_o f_Int32 == 8 '.
    } ".
    >
    Implicit_Size_o f_Int32 is 8 --because <-- VC++ aligned Int64.
    Yes, that created some padding, but that's not the issue.
    Alignment creates padding, but padding does not create alignment.

    By measuring padding, you have not measured alignment. Really.
    >
    As I recently said in " news:Jeff_Relf_ 2007_Dec_5__1_2 9_Pw@Cotse.NET ",
    the " /O2 " compiler option f u c k s things up.
    >
    You mean it shows that your assertion that the VC++ compiler always aligns
    to 8 byte boundaries is wrong.


    Comment

    • Ben Voigt [C++ MVP]

      #17
      Re: Eight-byte alignment


      <glchin@hotmail .comwrote in message
      news:6d36462e-28fe-4db8-83a5-9c5d65836384@b4 0g2000prf.googl egroups.com...
      Does a compiler guarantee that the variable w below is placed on an
      eight-byte aligned address?
      >
      >
      void myFunction( long iFreq )
      {
      const double w = two_pi * iFreq;
      ...
      ...
      }
      http://msdn2.microsoft.com/en-us/lib...ignment_topic2


      Comment

      • =?UTF-8?Q?Jeff=E2=98=A0Relf?=

        #18
        Show me the mis-alignment.

        Given VC++ 8.0 without so-called “ optimizations ” or packing rules,
        You can't show me a __int64 static, local or const
        that isn't aligned on an 8-byte-boundry. I rest my case.

        Comment

        • James Kanze

          #19
          Re: Show me the mis-alignment.

          On Dec 6, 4:13 am, Jeff?Relf <Jeff_R...@Yaho o.COMwrote:
          Given VC++ 8.0 without so-called ? optimizations ? or packing rules,
          You can't show me a __int64 static, local or const
          that isn't aligned on an 8-byte-boundry. I rest my case.
          aligne.cc:

          #include <iostream>

          double two_pi = 6.28 ;

          void
          f( long ifreq )
          {
          __int64 w = two_pi * ifreq ;
          std::cout << &w << std::endl ;
          }

          void
          g()
          {
          f( 20 ) ;
          }

          template< size_t N >
          void
          h()
          {
          char dummy[ N ] ;
          f( 20 ) ;
          }

          template< size_t N >
          void
          i()
          {
          char dummy[ N ] ;
          __int64 w ;
          std::cout << &w << std::endl ;
          }

          int
          main()
          {
          f( 20 ) ;
          g() ;
          h< 1 >() ;
          h< 2 >() ;
          h< 3 >() ;
          h< 4 >() ;
          h< 5 >() ;
          h< 6 >() ;
          h< 7 >() ;
          h< 8 >() ;
          i< 1 >() ;
          i< 2 >() ;
          i< 3 >() ;
          i< 4 >() ;
          i< 5 >() ;
          i< 6 >() ;
          i< 7 >() ;
          i< 8 >() ;
          return 0 ;
          }

          Compiled with:
          cl /vmg /GR /Gy /EHs /J /nologo /D_CRT_SECURE_NO _DEPRECATE /MTd /
          GS- /Zi /w /D_DEBUG align.cc

          Output:
          0012FF40
          0012FF38
          0012FF34
          0012FF34
          0012FF34
          0012FF34
          0012FF30
          0012FF30
          0012FF30
          0012FF30
          0012FF44
          0012FF44
          0012FF44
          0012FF44
          0012FF44
          0012FF44
          0012FF44
          0012FF44

          Note that the original question concerned double, and this is
          just a quick edit of the program which I used to verify that
          VC++ doesn't guarantee alignment of double. I don't know why
          the discussion changed type---double is C++, __int64 isn't, and
          VC++ is the only compiler at my disposition which will compile
          the above. The fact remains that VC++ doesn't guarantee
          alignment of more than 4, ever.

          --
          James Kanze (GABI Software) email:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          • =?UTF-8?Q?Jeff=E2=98=A0Relf?=

            #20
            VC++ 8.0 does not aways 8-byte-align __int64.

            Although I couldn't get an unaligned “ __int64 ” in “ WinMain() ”,
            this “ Ch ” parameter unaligns it:

            “ #pragma warning( disable: 4100 4189 4430 4508 )
            F( char Ch ) { __int64 Int64 = 0x1234567812345 678 ;
            // Breaking here, ‘ & Int64 == 0x0012fef4 ’
            }

            int _stdcall WinMain( int, int, int, int ) { F( 'A' ); } ”.

            So you're right, James ( and the rest ),
            VC++ 8.0 does not aways 8-byte-align __int64.

            Comment

            Working...