Skip to content

Commit 7dede32

Browse files
committed
Add initial compression support
1 parent a012a96 commit 7dede32

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

zmij.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,11 @@ template <typename Float> struct float_traits : std::numeric_limits<Float> {
332332
// 128-bit significands of powers of 10 rounded down.
333333
// Generated using 192-bit arithmetic method by Dougall Johnson.
334334
struct pow10_significands_table {
335+
static constexpr bool compress = false;
335336
static constexpr bool split_tables = ZMIJ_AARCH64 != 0;
336337
static constexpr int num_pow10 = 617;
337-
uint64_t data[num_pow10 * 2] = {};
338+
static constexpr int compression_ratio = compress ? 27 : 1;
339+
uint64_t data[(num_pow10 / compression_ratio + compress) * 2] = {};
338340

339341
ZMIJ_CONSTEXPR auto operator[](int dec_exp) const noexcept -> uint128 {
340342
constexpr int dec_exp_min = -292;
@@ -361,13 +363,17 @@ struct pow10_significands_table {
361363
uint192 current = {0xe000000000000000, 0x25e8e89c13bb0f7a,
362364
0xff77b1fcbebcdc4f};
363365
uint64_t ten = 0xa000000000000000;
366+
constexpr int table_size = sizeof(data) / (sizeof(*data) * 2);
364367
for (int i = 0; i < num_pow10; ++i) {
365-
if (split_tables) {
366-
data[num_pow10 - i - 1] = current.w2;
367-
data[num_pow10 * 2 - i - 1] = current.w1;
368-
} else {
369-
data[i * 2] = current.w2;
370-
data[i * 2 + 1] = current.w1;
368+
if (i % compression_ratio == 0) {
369+
int index = i / compression_ratio;
370+
if (split_tables) {
371+
data[table_size - index - 1] = current.w2;
372+
data[table_size * 2 - index - 1] = current.w1;
373+
} else {
374+
data[index * 2] = current.w2;
375+
data[index * 2 + 1] = current.w1;
376+
}
371377
}
372378

373379
uint64_t h0 = umul128_hi64(current.w0, ten);

0 commit comments

Comments
 (0)