blob: 97a7f34e718cfd12a7d6479142836006a228ac8f (
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
|
/*
bug-2931.c - segfault in codegen for stack results in shift for pdk.
*/
#include <testfwk.h>
#include <stdbool.h>
struct cvu_huffman_node
{
unsigned char left; /* Position of left node in tree or character. */
unsigned char right; /* Position of right node in tree or character. */
};
struct cvu_huffman_state
{
unsigned char (*input)(void);
const struct cvu_huffman_node *nodes; /* Array of nodes */
unsigned char root; /* Position of root node among nodes */
unsigned char ls, bs, rs;
unsigned char bit; /* Position of currently processed bit */
unsigned char buffer; /* Currently processed input byte */
unsigned char current; /* Currently processed node for recursive algorithm */
};
unsigned char cvu_get_huffman_recursive(struct cvu_huffman_state *state) __reentrant
{
bool direction;
unsigned char ret;
state->buffer >>= 1;
if(state->bit == 8)
{
state->buffer = (state->input)();
state->bit = 0;
}
direction = state->buffer & 0x01;
state->bit++;
if(!direction) /* Left */
{
if(state->current >= state->ls && state->current < state->rs)
{
ret = state->nodes[state->current].left;
state->current = state->root;
}
else
{
state->current = state->nodes[state->current].left;
ret = cvu_get_huffman_recursive(state);
}
}
else /* Right */
{
if(state->current >= state->bs)
{
ret = state->nodes[state->current].right;
state->current = state->root;
}
else
{
state->current = state->nodes[state->current].right;
ret = cvu_get_huffman_recursive(state);
}
}
return(ret);
}
void testBug(void)
{
}
|