IceUtils.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /**
  3. * Contains misc. useful macros & defines.
  4. * \file IceUtils.cpp
  5. * \author Pierre Terdiman (collected from various sources)
  6. * \date April, 4, 2000
  7. */
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // Precompiled Header
  11. #include "Stdafx.h"
  12. using namespace IceCore;
  13. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. /**
  15. * Returns the alignment of the input address.
  16. * \fn Alignment()
  17. * \param address [in] address to check
  18. * \return the best alignment (e.g. 1 for odd addresses, etc)
  19. */
  20. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  21. udword IceCore::Alignment(udword address)
  22. {
  23. // Returns 0 for null addresses
  24. if(!address) return 0;
  25. // Test all bits
  26. udword Align = 1;
  27. for(udword i=1;i<32;i++)
  28. {
  29. // Returns as soon as the alignment is broken
  30. if(address&Align) return Align;
  31. Align<<=1;
  32. }
  33. // Here all bits are null, except the highest one (else the address would be null)
  34. return Align;
  35. }