summaryrefslogtreecommitdiffstats
path: root/util.h
blob: 3d440f822358f6565c441b0c3bdadc67848a7635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef _UTILS_H
#define _UTILS_H

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include <stdint.h>

/******************************************************************************
 * UTILITY/MATH FUNCTIONS 
 ******************************************************************************/

uint8_t read_byte(FILE *file);
uint32_t read_word(FILE *file);
void ilog_init(void);
int ilog(uint16_t x);
int llog(uint32_t x);
int squash(int d);
int stretch_init(void);
int stretch(int p);
int min(int a, int b);
int max(int a, int b);
void print_status(int bytes);
int file_length(FILE *file);
void *calloc_align(int boundary, size_t size);

/******************************************************************************
 * MACROS FOR PRINTING BYTES 
 ******************************************************************************/

#define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d"
#define BYTETOBINARY(byte)  \
  (byte & 0x80 ? 1 : 0), \
  (byte & 0x40 ? 1 : 0), \
  (byte & 0x20 ? 1 : 0), \
  (byte & 0x10 ? 1 : 0), \
  (byte & 0x08 ? 1 : 0), \
  (byte & 0x04 ? 1 : 0), \
  (byte & 0x02 ? 1 : 0), \
  (byte & 0x01 ? 1 : 0) 

#define FMT_U8  "%d%d%d%d%d%d%d%d"
#define FMT_U16 FMT_U8  FMT_U8
#define FMT_U32 FMT_U16 FMT_U16 

#define FMT_U8S  "%d%d%d%d%d%d%d%d "
#define FMT_U16S FMT_U8S  FMT_U8S
#define FMT_U32S FMT_U16S FMT_U16S

#define VAL_U8(u8)   BYTETOBINARY(u8)
#define VAL_U16(u16) BYTETOBINARY(u16>>8),  BYTETOBINARY(u16)
#define VAL_U32(u32) BYTETOBINARY(u32>>24), BYTETOBINARY(u32>>16), VAL_U16(u32) 

/******************************************************************************
 * SOME GLOBAL STUFF 
 ******************************************************************************/

#define MEM (0x10000<<level)
#define MEM_MAX (0x10000<<9)

#ifndef DEFAULT_OPTION
#define DEFAULT_OPTION 5
#endif

#define COMPRESS   1
#define DECOMPRESS 0

extern int MODE;   /* COMPRESS or DECOMPRESS, set in main() (main.c) */
extern int level;  /* Compression level (0-9), set in main() (main.c) */ 

void log_init(void);
void log_msg(FILE *file, const char *fmt, ...);
void log_close(void);

extern FILE *LOG_AC;
extern FILE *LOG_NN;
extern FILE *LOG_SSE;
extern FILE *LOG_MODEL;
//extern FILE *LOG_PRAW;
//extern FILE *LOG_PSMOOTH;
extern FILE *LOG_PRAW[8];
extern FILE *LOG_PSMOOTH[8];
extern FILE *LOG_AVG_PRAW[8];
extern FILE *LOG_AVG_PSMOOTH[8];

extern FILE *LOG_ERR_PRAW[8];
extern FILE *LOG_ERR_PSMOOTH[8];

extern FILE *LOG_AVG_BYTE_PRAW;
extern FILE *LOG_AVG_BYTE_PSMOOTH;
extern FILE *LOG_ERR_BYTE_PRAW;
extern FILE *LOG_ERR_BYTE_PSMOOTH;

extern FILE *LOG_WIN_PRAW[8];
extern FILE *LOG_WIN_PSMOOTH[8];

extern FILE *LOG_LOSS_PRAW[8];
extern FILE *LOG_LOSS_PSMOOTH[8];

#endif