Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * Copyright 2013, GitHub, Inc |
3 | | * Copyright 2009-2013, Daniel Lemire, Cliff Moon, |
4 | | * David McIntosh, Robert Becho, Google Inc. and Veronika Zenz |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU General Public License |
8 | | * as published by the Free Software Foundation; either version 2 |
9 | | * of the License, or (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | | */ |
19 | | #ifndef __EWOK_RLW_H__ |
20 | | #define __EWOK_RLW_H__ |
21 | | |
22 | | #include "ewok.h" |
23 | | |
24 | 0 | #define RLW_RUNNING_BITS (sizeof(eword_t) * 4) |
25 | 0 | #define RLW_LITERAL_BITS (sizeof(eword_t) * 8 - 1 - RLW_RUNNING_BITS) |
26 | | |
27 | 0 | #define RLW_LARGEST_RUNNING_COUNT (((eword_t)1 << RLW_RUNNING_BITS) - 1) |
28 | 0 | #define RLW_LARGEST_LITERAL_COUNT (((eword_t)1 << RLW_LITERAL_BITS) - 1) |
29 | | |
30 | 0 | #define RLW_LARGEST_RUNNING_COUNT_SHIFT (RLW_LARGEST_RUNNING_COUNT << 1) |
31 | | |
32 | 0 | #define RLW_RUNNING_LEN_PLUS_BIT (((eword_t)1 << (RLW_RUNNING_BITS + 1)) - 1) |
33 | | |
34 | | static inline int rlw_get_run_bit(const eword_t *word) |
35 | 0 | { |
36 | 0 | return *word & (eword_t)1; |
37 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_get_run_bit Unexecuted instantiation: ewah_rlw.c:rlw_get_run_bit |
38 | | |
39 | | static inline void rlw_set_run_bit(eword_t *word, int b) |
40 | 0 | { |
41 | 0 | if (b) { |
42 | 0 | *word |= (eword_t)1; |
43 | 0 | } else { |
44 | 0 | *word &= (eword_t)(~1); |
45 | 0 | } |
46 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_set_run_bit Unexecuted instantiation: ewah_rlw.c:rlw_set_run_bit |
47 | | |
48 | | static inline void rlw_xor_run_bit(eword_t *word) |
49 | 0 | { |
50 | 0 | if (*word & 1) { |
51 | 0 | *word &= (eword_t)(~1); |
52 | 0 | } else { |
53 | 0 | *word |= (eword_t)1; |
54 | 0 | } |
55 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_xor_run_bit Unexecuted instantiation: ewah_rlw.c:rlw_xor_run_bit |
56 | | |
57 | | static inline void rlw_set_running_len(eword_t *word, eword_t l) |
58 | 0 | { |
59 | 0 | *word |= RLW_LARGEST_RUNNING_COUNT_SHIFT; |
60 | 0 | *word &= (l << 1) | (~RLW_LARGEST_RUNNING_COUNT_SHIFT); |
61 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_set_running_len Unexecuted instantiation: ewah_rlw.c:rlw_set_running_len |
62 | | |
63 | | static inline eword_t rlw_get_running_len(const eword_t *word) |
64 | 0 | { |
65 | 0 | return (*word >> 1) & RLW_LARGEST_RUNNING_COUNT; |
66 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_get_running_len Unexecuted instantiation: ewah_rlw.c:rlw_get_running_len |
67 | | |
68 | | static inline eword_t rlw_get_literal_words(const eword_t *word) |
69 | 0 | { |
70 | 0 | return *word >> (1 + RLW_RUNNING_BITS); |
71 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_get_literal_words Unexecuted instantiation: ewah_rlw.c:rlw_get_literal_words |
72 | | |
73 | | static inline void rlw_set_literal_words(eword_t *word, eword_t l) |
74 | 0 | { |
75 | 0 | *word |= ~RLW_RUNNING_LEN_PLUS_BIT; |
76 | 0 | *word &= (l << (RLW_RUNNING_BITS + 1)) | RLW_RUNNING_LEN_PLUS_BIT; |
77 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_set_literal_words Unexecuted instantiation: ewah_rlw.c:rlw_set_literal_words |
78 | | |
79 | | static inline eword_t rlw_size(const eword_t *self) |
80 | 0 | { |
81 | 0 | return rlw_get_running_len(self) + rlw_get_literal_words(self); |
82 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlw_size Unexecuted instantiation: ewah_rlw.c:rlw_size |
83 | | |
84 | | struct rlw_iterator { |
85 | | const eword_t *buffer; |
86 | | size_t size; |
87 | | size_t pointer; |
88 | | size_t literal_word_start; |
89 | | |
90 | | struct { |
91 | | const eword_t *word; |
92 | | int literal_words; |
93 | | int running_len; |
94 | | int literal_word_offset; |
95 | | int running_bit; |
96 | | } rlw; |
97 | | }; |
98 | | |
99 | | void rlwit_init(struct rlw_iterator *it, struct ewah_bitmap *bitmap); |
100 | | void rlwit_discard_first_words(struct rlw_iterator *it, size_t x); |
101 | | size_t rlwit_discharge( |
102 | | struct rlw_iterator *it, struct ewah_bitmap *out, size_t max, int negate); |
103 | | |
104 | | static inline size_t rlwit_word_size(struct rlw_iterator *it) |
105 | 0 | { |
106 | 0 | return it->rlw.running_len + it->rlw.literal_words; |
107 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlwit_word_size Unexecuted instantiation: ewah_rlw.c:rlwit_word_size |
108 | | |
109 | | static inline size_t rlwit_literal_words(struct rlw_iterator *it) |
110 | 0 | { |
111 | 0 | return it->pointer - it->rlw.literal_words; |
112 | 0 | } Unexecuted instantiation: ewah_bitmap.c:rlwit_literal_words Unexecuted instantiation: ewah_rlw.c:rlwit_literal_words |
113 | | |
114 | | #endif |