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.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * This file is a part of SMalloc.
  3. * SMalloc is MIT licensed.
  4. * Copyright (c) 2017 Andrey Rys.
  5. */
  6. #include "smalloc_i.h"
  7. /* An adopted Jenkins one-at-a-time hash */
  8. #define UIHOP(x, s) do { \
  9. hash += (x >> s) & 0xff;\
  10. hash += hash << 10; \
  11. hash ^= hash >> 6; \
  12. } while (0)
  13. uintptr_t smalloc_uinthash(uintptr_t x)
  14. {
  15. uintptr_t hash = 0;
  16. UIHOP(x, 0);
  17. UIHOP(x, 8);
  18. UIHOP(x, 16);
  19. UIHOP(x, 24);
  20. hash += hash << 3;
  21. hash ^= hash >> 11;
  22. hash += hash << 15;
  23. return hash;
  24. }
  25. #undef UIHOP
  26. uintptr_t smalloc_mktag(struct smalloc_hdr *shdr)
  27. {
  28. uintptr_t r = smalloc_uinthash(PTR_UINT(shdr));
  29. r += shdr->rsz;
  30. r = smalloc_uinthash(r);
  31. r += shdr->usz;
  32. r = smalloc_uinthash(r);
  33. return r;
  34. }