fastpos_tablegen.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file fastpos_tablegen.c
  4. /// \brief Generates the lzma_fastpos[] lookup table
  5. ///
  6. // Authors: Igor Pavlov
  7. // Lasse Collin
  8. //
  9. // This file has been put into the public domain.
  10. // You can do whatever you want with this file.
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #include <inttypes.h>
  14. #include <stdio.h>
  15. #include "fastpos.h"
  16. int
  17. main(void)
  18. {
  19. uint8_t fastpos[1 << FASTPOS_BITS];
  20. const uint8_t fast_slots = 2 * FASTPOS_BITS;
  21. uint32_t c = 2;
  22. fastpos[0] = 0;
  23. fastpos[1] = 1;
  24. for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
  25. const uint32_t k = 1 << ((slot_fast >> 1) - 1);
  26. for (uint32_t j = 0; j < k; ++j, ++c)
  27. fastpos[c] = slot_fast;
  28. }
  29. printf("/* This file has been automatically generated "
  30. "by fastpos_tablegen.c. */\n\n"
  31. "#include \"common.h\"\n"
  32. "#include \"fastpos.h\"\n\n"
  33. "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
  34. for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
  35. if (i % 16 == 0)
  36. printf("\n\t");
  37. printf("%3u", (unsigned int)(fastpos[i]));
  38. if (i != (1 << FASTPOS_BITS) - 1)
  39. printf(",");
  40. }
  41. printf("\n};\n");
  42. return 0;
  43. }