LzHash.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (c) 1999-2008 Igor Pavlov
  4. * Copyright (C) 2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
  21. * to adapt it to GRUB's requirement.
  22. *
  23. * See <http://www.7-zip.org>, for more information about LZMA.
  24. */
  25. #ifndef __LZHASH_H
  26. #define __LZHASH_H
  27. #define kHash2Size (1 << 10)
  28. #define kHash3Size (1 << 16)
  29. #define kHash4Size (1 << 20)
  30. #define kFix3HashSize (kHash2Size)
  31. #define kFix4HashSize (kHash2Size + kHash3Size)
  32. #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
  33. #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
  34. #define HASH3_CALC { \
  35. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  36. hash2Value = temp & (kHash2Size - 1); \
  37. hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
  38. #define HASH4_CALC { \
  39. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  40. hash2Value = temp & (kHash2Size - 1); \
  41. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  42. hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
  43. #define HASH5_CALC { \
  44. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  45. hash2Value = temp & (kHash2Size - 1); \
  46. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  47. hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
  48. hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
  49. hash4Value &= (kHash4Size - 1); }
  50. /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
  51. #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
  52. #define MT_HASH2_CALC \
  53. hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
  54. #define MT_HASH3_CALC { \
  55. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  56. hash2Value = temp & (kHash2Size - 1); \
  57. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
  58. #define MT_HASH4_CALC { \
  59. UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
  60. hash2Value = temp & (kHash2Size - 1); \
  61. hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
  62. hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
  63. #endif