2
0

IceUtils.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #include "../Opcode.h"
  11. using namespace IceCore;
  12. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. /**
  14. * Returns the alignment of the input address.
  15. * \fn Alignment()
  16. * \param address [in] address to check
  17. * \return the best alignment (e.g. 1 for odd addresses, etc)
  18. */
  19. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  20. udword IceCore::Alignment(udword address)
  21. {
  22. // Returns 0 for null addresses
  23. if(!address) return 0;
  24. // Test all bits
  25. udword Align = 1;
  26. for(udword i=1;i<32;i++)
  27. {
  28. // Returns as soon as the alignment is broken
  29. if(address&Align) return Align;
  30. Align<<=1;
  31. }
  32. // Here all bits are null, except the highest one (else the address would be null)
  33. return Align;
  34. }