fastpos_tablegen.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <sys/types.h>
  14. #include <inttypes.h>
  15. #include <stdio.h>
  16. #include "fastpos.h"
  17. int
  18. main(void)
  19. {
  20. uint8_t fastpos[1 << FASTPOS_BITS];
  21. const uint8_t fast_slots = 2 * FASTPOS_BITS;
  22. uint32_t c = 2;
  23. fastpos[0] = 0;
  24. fastpos[1] = 1;
  25. for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
  26. const uint32_t k = 1 << ((slot_fast >> 1) - 1);
  27. for (uint32_t j = 0; j < k; ++j, ++c)
  28. fastpos[c] = slot_fast;
  29. }
  30. printf("/* This file has been automatically generated "
  31. "by fastpos_tablegen.c. */\n\n"
  32. "#include \"common.h\"\n"
  33. "#include \"fastpos.h\"\n\n"
  34. "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
  35. for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
  36. if (i % 16 == 0)
  37. printf("\n\t");
  38. printf("%3u", (unsigned int)(fastpos[i]));
  39. if (i != (1 << FASTPOS_BITS) - 1)
  40. printf(",");
  41. }
  42. printf("\n};\n");
  43. return 0;
  44. }