Skip to content

Commit 69e263e

Browse files
committed
simplified code
1 parent 4ce00b0 commit 69e263e

File tree

2 files changed

+21
-48
lines changed

2 files changed

+21
-48
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ All details and experiments are provided in the following [technical report](htt
2525
Compiling the code
2626
------------------
2727

28-
The code is tested on Linux with `gcc` 7.3.0 and on Mac 10.14 with `clang` 10.0.0.
28+
The code is tested on Linux with `gcc` 7.3.0, 8.3.0, 9.2.1 and on Mac 10.14 with `clang` 10.0.0.
2929
To build the code, [`CMake`](https://cmake.org/) is required.
3030

3131
Clone the repository with
@@ -173,12 +173,12 @@ instructions and data.
173173
Both systems run Linux 4.4.0 and have 64 GB on RAM.
174174
The code was compiled with gcc 7.3.0 on the first
175175
system; with gcc 8.3.0 on the second.
176-
In both cases we used all optimizations
176+
In both cases we used all optimizations
177177
(see also `CMakeLists.txt`).
178178
179179
|**Method** |**bpi** | **ns/int (run-aware) on i7-7700** | **ns/int (not run-aware) on i7-7700**| **ns/int (run-aware) on i9-9900K** | **ns/int (not run-aware) on i9-9900K**|
180180
|:-----------------|:------:|:------------------:|:------:|:-----:|:-----:|
181-
|simple |3.532 | 3.45 | 4.65 | 2.52 | 3.37 |
181+
|simple |3.532 | 3.45 | 4.65 | 2.52 | 3.37 |
182182
|left-most minimal |3.362 | 5.78 | 7.07 | 4.18 | 5.28 |
183183
|centered minimal |3.361 | 5.78 | 7.07 | 4.24 | 5.33 |
184184

include/interpolative_coding.hpp

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ struct binary {
8484
#if RUNAWARE
8585
assert(r > 0);
8686
#else
87-
if (!r) {
88-
return;
89-
}
87+
if (!r) return;
9088
#endif
9189
assert(x <= r);
9290
uint32_t b = msb(r) + 1;
@@ -118,14 +116,11 @@ struct leftmost_minimal {
118116
#if RUNAWARE
119117
assert(r > 0);
120118
#else
121-
if (!r) {
122-
return;
123-
}
119+
if (!r) return;
124120
#endif
125121
assert(x <= r);
126-
uint32_t n = r + 1;
127-
uint32_t b = msb(n);
128-
uint32_t hi = (uint64_t(1) << (b + 1)) - n;
122+
uint32_t b = msb(r);
123+
uint32_t hi = (uint64_t(1) << (b + 1)) - r - 1;
129124
if (x < hi) {
130125
append(x, b);
131126
} else {
@@ -146,13 +141,10 @@ struct leftmost_minimal {
146141
#else
147142
if (!r) return 0;
148143
#endif
149-
uint32_t n = r + 1;
150-
uint32_t b = msb(n);
151-
uint32_t hi = (uint64_t(1) << (b + 1)) - n;
144+
uint32_t b = msb(r);
145+
uint32_t hi = (uint64_t(1) << (b + 1)) - r - 1;
152146
uint32_t x = take(b);
153-
if (x >= hi) {
154-
x = (x << 1) + take(1) - hi;
155-
}
147+
if (x >= hi) x = (x << 1) + take(1) - hi;
156148
assert(x <= r);
157149
return x;
158150
}
@@ -165,23 +157,16 @@ struct centered_minimal {
165157
#if RUNAWARE
166158
assert(r > 0);
167159
#else
168-
if (!r) {
169-
return;
170-
}
160+
if (!r) return;
171161
#endif
172-
uint32_t n = r + 1;
173-
uint32_t b = msb(n);
174-
uint32_t c = (uint64_t(1) << (b + 1)) - n;
175-
162+
uint32_t b = msb(r);
163+
uint32_t c = (uint64_t(1) << (b + 1)) - r - 1;
176164
int64_t half_c = c / 2;
177165
int64_t half_r = r / 2;
178166
int64_t lo, hi;
179167
lo = half_r - half_c;
180168
hi = half_r + half_c + 1;
181-
if (n % 2) {
182-
lo -= 1;
183-
}
184-
169+
if (r % 2 == 0) lo -= 1;
185170
if (x > lo and x < hi) {
186171
append(x, b);
187172
} else {
@@ -200,23 +185,15 @@ struct centered_minimal {
200185
#else
201186
if (!r) return 0;
202187
#endif
203-
uint32_t n = r + 1;
204-
uint32_t b = msb(n);
205-
uint32_t c = (uint64_t(1) << (b + 1)) - n;
206-
188+
uint32_t b = msb(r);
189+
uint32_t c = (uint64_t(1) << (b + 1)) - r - 1;
207190
int64_t half_c = c / 2;
208191
int64_t half_r = r / 2;
209-
int64_t lo, hi;
192+
int64_t lo;
210193
lo = half_r - half_c;
211-
hi = half_r + half_c + 1;
212-
if (n % 2) {
213-
lo -= 1;
214-
}
215-
194+
if (r % 2 == 0) lo -= 1;
216195
uint32_t x = take(b);
217-
if (x <= lo or x >= hi) {
218-
x += take(1) << b;
219-
}
196+
if (x <= lo) x += take(1) << b;
220197
assert(x <= r);
221198
return x;
222199
}
@@ -249,9 +226,7 @@ struct encoder {
249226
void encode(uint32_t const* input, uint32_t n, uint32_t lo, uint32_t hi) {
250227
if (!n) return;
251228
#if RUNAWARE
252-
if (hi - lo + 1 == n) { // run
253-
return;
254-
}
229+
if (hi - lo + 1 == n) return; // run
255230
#endif
256231
assert(lo <= hi);
257232
assert(hi - lo >= n - 1);
@@ -297,9 +272,7 @@ struct decoder {
297272
assert(lo <= hi);
298273
#if RUNAWARE
299274
if (hi - lo + 1 == n) { // run
300-
for (uint32_t i = 0; i != n; ++i) {
301-
out[i] = lo + i;
302-
}
275+
for (uint32_t i = 0; i != n; ++i) out[i] = lo++;
303276
return;
304277
}
305278
#endif

0 commit comments

Comments
 (0)