Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1988-1992 Microsoft Corporation
  3. Module Name:
  4. Align.h
  5. Abstract:
  6. Author:
  7. John Rogers (JohnRo) 15-May-1991
  8. Environment:
  9. This code assumes that sizeof(DWORD) >= sizeof(LPVOID).
  10. Revision History:
  11. 15-May-1991 JohnRo
  12. Created align.h for NT/LAN from OS/2 1.2 HPFS pbmacros.h.
  13. 19-Jun-1991 JohnRo
  14. Make sure pointer-to-wider-then-byte doesn't get messed up.
  15. 10-Jul-1991 JohnRo
  16. Added ALIGN_BYTE and ALIGN_CHAR for completeness.
  17. 21-Aug-1991 CliffV
  18. Fix ROUND_DOWN_* to include ~
  19. 03-Dec-1991 JohnRo
  20. Worst-case on MIPS is 8-byte alignment.
  21. Added COUNT_IS_ALIGNED() and POINTER_IS_ALIGNED() macros.
  22. 26-Jun-1992 JohnRo
  23. RAID 9933: ALIGN_WORST should be 8 for x86 builds.
  24. --*/
  25. #ifndef _ALIGN_
  26. #define _ALIGN_
  27. // BOOL
  28. // COUNT_IS_ALIGNED(
  29. // IN DWORD Count,
  30. // IN DWORD Pow2 // undefined if this isn't a power of 2.
  31. // );
  32. //
  33. #define COUNT_IS_ALIGNED(Count,Pow2) \
  34. ( ( ( (Count) & (((Pow2)-1)) ) == 0) ? TRUE : FALSE )
  35. // BOOL
  36. // POINTER_IS_ALIGNED(
  37. // IN LPVOID Ptr,
  38. // IN DWORD Pow2 // undefined if this isn't a power of 2.
  39. // );
  40. //
  41. #define POINTER_IS_ALIGNED(Ptr,Pow2) \
  42. ( ( ( ((ULONG_PTR)(Ptr)) & (((Pow2)-1)) ) == 0) ? TRUE : FALSE )
  43. #define ROUND_DOWN_COUNT(Count,Pow2) \
  44. ( (Count) & (~(((LONG)(Pow2))-1)) )
  45. #define ROUND_DOWN_POINTER(Ptr,Pow2) \
  46. ( (LPVOID) ROUND_DOWN_COUNT( ((ULONG_PTR)(Ptr)), (Pow2) ) )
  47. // If Count is not already aligned, then
  48. // round Count up to an even multiple of "Pow2". "Pow2" must be a power of 2.
  49. //
  50. // DWORD
  51. // ROUND_UP_COUNT(
  52. // IN DWORD Count,
  53. // IN DWORD Pow2
  54. // );
  55. #define ROUND_UP_COUNT(Count,Pow2) \
  56. ( ((Count)+(Pow2)-1) & (~(((LONG)(Pow2))-1)) )
  57. // LPVOID
  58. // ROUND_UP_POINTER(
  59. // IN LPVOID Ptr,
  60. // IN DWORD Pow2
  61. // );
  62. // If Ptr is not already aligned, then round it up until it is.
  63. #define ROUND_UP_POINTER(Ptr,Pow2) \
  64. ( (LPVOID) ( (((ULONG_PTR)(Ptr))+(Pow2)-1) & (~(((LONG)(Pow2))-1)) ) )
  65. // Usage: myPtr = ROUND_UP_POINTER( unalignedPtr, ALIGN_LPVOID )
  66. #define ALIGN_BYTE sizeof(UCHAR)
  67. #define ALIGN_CHAR sizeof(CHAR)
  68. #define ALIGN_DESC_CHAR sizeof(DESC_CHAR)
  69. #define ALIGN_DWORD sizeof(DWORD)
  70. #define ALIGN_LONG sizeof(LONG)
  71. #define ALIGN_LPBYTE sizeof(LPBYTE)
  72. #define ALIGN_LPDWORD sizeof(LPDWORD)
  73. #define ALIGN_LPSTR sizeof(LPSTR)
  74. #define ALIGN_LPTSTR sizeof(LPTSTR)
  75. #define ALIGN_LPVOID sizeof(LPVOID)
  76. #define ALIGN_LPWORD sizeof(LPWORD)
  77. #define ALIGN_TCHAR sizeof(TCHAR)
  78. #define ALIGN_WCHAR sizeof(WCHAR)
  79. #define ALIGN_WORD sizeof(WORD)
  80. //
  81. // For now, use a hardcoded constant. however, this should be visited again
  82. // and maybe changed to sizeof(QUAD).
  83. //
  84. #define ALIGN_QUAD 8
  85. #if defined(_X86_)
  86. #define ALIGN_WORST 8
  87. #elif defined(_AMD64_)
  88. #define ALIGN_WORST 8
  89. #elif defined(_ALPHA_)
  90. //
  91. // Worst-case alignment on ALPHA is 8 bytes (for double). Specify this here,
  92. // in case our allocator is used for structures containing this. (That is,
  93. // even though NT/LAN doesn't need this for our data structures, let's be
  94. // permissive.) The alignment requirements apply to Alpha.
  95. //
  96. #define ALIGN_WORST 8
  97. #elif defined(_IA64_)
  98. //
  99. // IA64 note for QUAD: The NT QUAD type definition is NOT the EM 16byte quad type.
  100. // Because of some NT constraints, QUAD type size cannot be changed.
  101. //
  102. #define ALIGN_WORST 16
  103. #else // none of the above
  104. #error "Unknown alignment requirements for align.h"
  105. #endif // none of the above
  106. #endif // _ALIGN_