1207753Smm/////////////////////////////////////////////////////////////////////////////// 2207753Smm// 3207753Smm/// \file fastpos_tablegen.c 4207753Smm/// \brief Generates the lzma_fastpos[] lookup table 5207753Smm/// 6207753Smm// Authors: Igor Pavlov 7207753Smm// Lasse Collin 8207753Smm// 9207753Smm// This file has been put into the public domain. 10207753Smm// You can do whatever you want with this file. 11207753Smm// 12207753Smm/////////////////////////////////////////////////////////////////////////////// 13207753Smm 14207753Smm#include <sys/types.h> 15207753Smm#include <inttypes.h> 16207753Smm#include <stdio.h> 17207753Smm#include "fastpos.h" 18207753Smm 19207753Smm 20207753Smmint 21207753Smmmain(void) 22207753Smm{ 23207753Smm uint8_t fastpos[1 << FASTPOS_BITS]; 24207753Smm 25207753Smm const uint8_t fast_slots = 2 * FASTPOS_BITS; 26207753Smm uint32_t c = 2; 27207753Smm 28207753Smm fastpos[0] = 0; 29207753Smm fastpos[1] = 1; 30207753Smm 31207753Smm for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) { 32207753Smm const uint32_t k = 1 << ((slot_fast >> 1) - 1); 33207753Smm for (uint32_t j = 0; j < k; ++j, ++c) 34207753Smm fastpos[c] = slot_fast; 35207753Smm } 36207753Smm 37207753Smm printf("/* This file has been automatically generated " 38207753Smm "by fastpos_tablegen.c. */\n\n" 39207753Smm "#include \"common.h\"\n" 40207753Smm "#include \"fastpos.h\"\n\n" 41207753Smm "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {"); 42207753Smm 43207753Smm for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) { 44207753Smm if (i % 16 == 0) 45207753Smm printf("\n\t"); 46207753Smm 47207753Smm printf("%3u", (unsigned int)(fastpos[i])); 48207753Smm 49207753Smm if (i != (1 << FASTPOS_BITS) - 1) 50207753Smm printf(","); 51207753Smm } 52207753Smm 53207753Smm printf("\n};\n"); 54207753Smm 55207753Smm return 0; 56207753Smm} 57