-
Notifications
You must be signed in to change notification settings - Fork 22
/
radix_bitpack.c
58 lines (42 loc) · 1.93 KB
/
radix_bitpack.c
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
/*
* Copyright (c) 2018, Conor McCarthy
* All rights reserved.
*
* This source code is licensed under both the BSD-style license (found in the
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
*/
#include "mem.h" /* U32, U64 */
#include "fl2_threading.h"
#include "fl2_internal.h"
#include "radix_internal.h"
#undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define RMF_BITPACK
#define RADIX_MAX_LENGTH BITPACK_MAX_LENGTH
#define InitMatchLink(pos, link) tbl->table[pos] = link
#define GetMatchLink(link) (tbl->table[link] & RADIX_LINK_MASK)
#define GetInitialMatchLink(pos) tbl->table[pos]
#define GetMatchLength(pos) (tbl->table[pos] >> RADIX_LINK_BITS)
#define SetMatchLink(pos, link, length) tbl->table[pos] = (link) | ((U32)(length) << RADIX_LINK_BITS)
#define SetMatchLength(pos, link, length) tbl->table[pos] = (link) | ((U32)(length) << RADIX_LINK_BITS)
#define SetMatchLinkAndLength(pos, link, length) tbl->table[pos] = (link) | ((U32)(length) << RADIX_LINK_BITS)
#define SetNull(pos) tbl->table[pos] = RADIX_NULL_LINK
#define IsNull(pos) (tbl->table[pos] == RADIX_NULL_LINK)
BYTE* RMF_bitpackAsOutputBuffer(FL2_matchTable* const tbl, size_t const pos)
{
return (BYTE*)(tbl->table + pos);
}
/* Restrict the match lengths so that they don't reach beyond pos */
void RMF_bitpackLimitLengths(FL2_matchTable* const tbl, size_t const pos)
{
DEBUGLOG(5, "RMF_limitLengths : end %u, max length %u", (U32)pos, RADIX_MAX_LENGTH);
SetNull(pos - 1);
for (U32 length = 2; length < RADIX_MAX_LENGTH && length <= pos; ++length) {
U32 const link = tbl->table[pos - length];
if (link != RADIX_NULL_LINK)
tbl->table[pos - length] = (MIN(length, link >> RADIX_LINK_BITS) << RADIX_LINK_BITS) | (link & RADIX_LINK_MASK);
}
}
#include "radix_engine.h"