No Description
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.

MemoryUtils.h 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <stdint.h>
  3. #include "xxhash.h"
  4. namespace il2cpp
  5. {
  6. namespace utils
  7. {
  8. class MemoryUtils
  9. {
  10. public:
  11. template<typename T>
  12. static int32_t MemCmpRef(T* left, T* right)
  13. {
  14. return memcmp(left, right, sizeof(T));
  15. }
  16. };
  17. #define DECL_MEMCMP_NUM(typ) template<> inline int32_t MemoryUtils::MemCmpRef<typ>(typ* left, typ* right) { return (*right > *left) ? -1 : (*right < *left) ? 1 : 0; }
  18. DECL_MEMCMP_NUM(int8_t)
  19. DECL_MEMCMP_NUM(int16_t)
  20. DECL_MEMCMP_NUM(int32_t)
  21. DECL_MEMCMP_NUM(int64_t)
  22. DECL_MEMCMP_NUM(uint8_t)
  23. DECL_MEMCMP_NUM(uint16_t)
  24. DECL_MEMCMP_NUM(uint32_t)
  25. DECL_MEMCMP_NUM(uint64_t)
  26. // don't think this will give the right result for NaNs and such
  27. DECL_MEMCMP_NUM(float)
  28. DECL_MEMCMP_NUM(double)
  29. #undef DECL_MEMCMP_NUM
  30. #define DECL_MEMHASH_NUM(typ) template<> inline int32_t MemoryUtils::MemHashRef(typ* val) { return (int32_t)(*val); }
  31. DECL_MEMHASH_NUM(int8_t)
  32. DECL_MEMHASH_NUM(int16_t)
  33. DECL_MEMHASH_NUM(int32_t)
  34. DECL_MEMHASH_NUM(uint8_t)
  35. DECL_MEMHASH_NUM(uint16_t)
  36. DECL_MEMHASH_NUM(uint32_t)
  37. DECL_MEMHASH_NUM(float)
  38. #undef DECL_MEMHASH_NUM
  39. template<> inline int32_t MemoryUtils::MemHashRef(int64_t* val) { int64_t k = *val; return (int32_t)(k & 0xffffffff) ^ (int32_t)((k >> 32) & 0xffffffff); }
  40. template<> inline int32_t MemoryUtils::MemHashRef(uint64_t* val) { return MemHashRef(reinterpret_cast<int64_t*>(val)); }
  41. template<> inline int32_t MemoryUtils::MemHashRef(double* val) { return MemHashRef(reinterpret_cast<int64_t*>(val)); }
  42. } // namespace utils
  43. } // namespace il2cpp