fastpos_tablegen.c revision 259065
10Sstevel@tonic-gate/////////////////////////////////////////////////////////////////////////////// 20Sstevel@tonic-gate// 30Sstevel@tonic-gate/// \file fastpos_tablegen.c 40Sstevel@tonic-gate/// \brief Generates the lzma_fastpos[] lookup table 52912Sartem/// 62912Sartem// Authors: Igor Pavlov 70Sstevel@tonic-gate// Lasse Collin 80Sstevel@tonic-gate// 90Sstevel@tonic-gate// This file has been put into the public domain. 100Sstevel@tonic-gate// You can do whatever you want with this file. 110Sstevel@tonic-gate// 120Sstevel@tonic-gate/////////////////////////////////////////////////////////////////////////////// 130Sstevel@tonic-gate 140Sstevel@tonic-gate#include <sys/types.h> 150Sstevel@tonic-gate#include <inttypes.h> 160Sstevel@tonic-gate#include <stdio.h> 170Sstevel@tonic-gate#include "fastpos.h" 180Sstevel@tonic-gate 190Sstevel@tonic-gate 200Sstevel@tonic-gateint 210Sstevel@tonic-gatemain(void) 229956SWilliam.Roche@Sun.COM{ 230Sstevel@tonic-gate uint8_t fastpos[1 << FASTPOS_BITS]; 240Sstevel@tonic-gate 250Sstevel@tonic-gate const uint8_t fast_slots = 2 * FASTPOS_BITS; 260Sstevel@tonic-gate uint32_t c = 2; 270Sstevel@tonic-gate 280Sstevel@tonic-gate fastpos[0] = 0; 290Sstevel@tonic-gate fastpos[1] = 1; 300Sstevel@tonic-gate 310Sstevel@tonic-gate for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) { 320Sstevel@tonic-gate const uint32_t k = 1 << ((slot_fast >> 1) - 1); 330Sstevel@tonic-gate for (uint32_t j = 0; j < k; ++j, ++c) 340Sstevel@tonic-gate fastpos[c] = slot_fast; 350Sstevel@tonic-gate } 360Sstevel@tonic-gate 370Sstevel@tonic-gate printf("/* This file has been automatically generated " 380Sstevel@tonic-gate "by fastpos_tablegen.c. */\n\n" 390Sstevel@tonic-gate "#include \"common.h\"\n" 400Sstevel@tonic-gate "#include \"fastpos.h\"\n\n" 410Sstevel@tonic-gate "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {"); 420Sstevel@tonic-gate 430Sstevel@tonic-gate for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) { 440Sstevel@tonic-gate if (i % 16 == 0) 450Sstevel@tonic-gate printf("\n\t"); 460Sstevel@tonic-gate 470Sstevel@tonic-gate printf("%3u", (unsigned int)(fastpos[i])); 480Sstevel@tonic-gate 490Sstevel@tonic-gate if (i != (1 << FASTPOS_BITS) - 1) 500Sstevel@tonic-gate printf(","); 510Sstevel@tonic-gate } 520Sstevel@tonic-gate 530Sstevel@tonic-gate printf("\n};\n"); 540Sstevel@tonic-gate 550Sstevel@tonic-gate return 0; 560Sstevel@tonic-gate} 570Sstevel@tonic-gate