您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

41 行
705B

  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. }