| 85 | } |
| 86 | |
| 87 | static void CompressValue(CHIMP_TYPE in, State& state) { |
| 88 | |
| 89 | CHIMP_TYPE xor_result; |
| 90 | uint8_t previous_index; |
| 91 | uint32_t trailing_zeros = 0; |
| 92 | bool trailing_zeros_exceed_threshold = false; |
| 93 | |
| 94 | xor_result = (CHIMP_TYPE)in ^ state.previous_value; |
| 95 | |
| 96 | // Compress the value |
| 97 | if (xor_result == 0) { |
| 98 | state.flag_buffer.Insert(ChimpConstants::Flags::VALUE_IDENTICAL); |
| 99 | // state.output.template WriteValue<uint8_t, INDEX_BITS_SIZE>(previous_index); |
| 100 | state.SetLeadingZeros(); |
| 101 | } else { |
| 102 | // Values are not identical |
| 103 | auto leading_zeros_raw = CountZeros<CHIMP_TYPE>::Leading(xor_result); |
| 104 | uint8_t leading_zeros = ChimpConstants::Compression::LEADING_ROUND[leading_zeros_raw]; |
| 105 | |
| 106 | trailing_zeros = CountZeros<CHIMP_TYPE>::Trailing(xor_result); |
| 107 | trailing_zeros_exceed_threshold = trailing_zeros > 6; |
| 108 | |
| 109 | if (trailing_zeros_exceed_threshold) { |
| 110 | uint32_t significant_bits = BIT_SIZE - leading_zeros - trailing_zeros; |
| 111 | state.flag_buffer.Insert(ChimpConstants::Flags::TRAILING_EXCEEDS_THRESHOLD); |
| 112 | state.leading_zero_buffer.Insert(ChimpConstants::Compression::LEADING_REPRESENTATION[leading_zeros]); |
| 113 | state.output.template WriteValue<uint8_t, SIGNIFICANT_BITS_SIZE>(significant_bits); |
| 114 | state.output.template WriteValue<CHIMP_TYPE>(xor_result >> trailing_zeros, significant_bits); |
| 115 | state.SetLeadingZeros(); |
| 116 | } else if (leading_zeros == state.previous_leading_zeros) { |
| 117 | state.flag_buffer.Insert(ChimpConstants::Flags::LEADING_ZERO_EQUALITY); |
| 118 | int32_t significant_bits = BIT_SIZE - leading_zeros; |
| 119 | state.output.template WriteValue<CHIMP_TYPE>(xor_result, significant_bits); |
| 120 | } else { |
| 121 | state.flag_buffer.Insert(ChimpConstants::Flags::LEADING_ZERO_LOAD); |
| 122 | const int32_t significant_bits = BIT_SIZE - leading_zeros; |
| 123 | state.leading_zero_buffer.Insert(ChimpConstants::Compression::LEADING_REPRESENTATION[leading_zeros]); |
| 124 | state.output.template WriteValue<CHIMP_TYPE>(xor_result, significant_bits); |
| 125 | state.SetLeadingZeros(leading_zeros); |
| 126 | } |
| 127 | } |
| 128 | state.previous_value = in; |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | //===--------------------------------------------------------------------===// |
nothing calls this directly
no test coverage detected