Rizin
unix-like reverse engineering framework and cli tools
fastpos_tablegen.c File Reference

Generates the lzma_fastpos[] lookup table. More...

#include <inttypes.h>
#include <stdio.h>
#include "fastpos.h"

Go to the source code of this file.

Functions

int main (void)
 

Detailed Description

Generates the lzma_fastpos[] lookup table.

Definition in file fastpos_tablegen.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 20 of file fastpos_tablegen.c.

21 {
22  uint8_t fastpos[1 << FASTPOS_BITS];
23 
24  const uint8_t fast_slots = 2 * FASTPOS_BITS;
25  uint32_t c = 2;
26 
27  fastpos[0] = 0;
28  fastpos[1] = 1;
29 
30  for (uint8_t slot_fast = 2; slot_fast < fast_slots; ++slot_fast) {
31  const uint32_t k = 1 << ((slot_fast >> 1) - 1);
32  for (uint32_t j = 0; j < k; ++j, ++c)
33  fastpos[c] = slot_fast;
34  }
35 
36  printf("/* This file has been automatically generated "
37  "by fastpos_tablegen.c. */\n\n"
38  "#include \"common.h\"\n"
39  "#include \"fastpos.h\"\n\n"
40  "const uint8_t lzma_fastpos[1 << FASTPOS_BITS] = {");
41 
42  for (size_t i = 0; i < (1 << FASTPOS_BITS); ++i) {
43  if (i % 16 == 0)
44  printf("\n\t");
45 
46  printf("%3u", (unsigned int)(fastpos[i]));
47 
48  if (i != (1 << FASTPOS_BITS) - 1)
49  printf(",");
50  }
51 
52  printf("\n};\n");
53 
54  return 0;
55 }
lzma_index ** i
Definition: index.h:629
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
const char * k
Definition: dsignal.c:11
#define FASTPOS_BITS
Definition: fastpos.h:92
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define c(i)
Definition: sha256.c:43

References c, FASTPOS_BITS, i, k, and printf().