| 107 | |
| 108 | template <bool T_COMBINE_HASHES> |
| 109 | void Hashing32::HashFixedLenImp(uint32_t num_rows, uint64_t key_length, |
| 110 | const uint8_t* keys, uint32_t* hashes) { |
| 111 | // Calculate the number of rows that skip the last 16 bytes |
| 112 | // |
| 113 | uint32_t num_rows_safe = num_rows; |
| 114 | while (num_rows_safe > 0 && (num_rows - num_rows_safe) * key_length < kStripeSize) { |
| 115 | --num_rows_safe; |
| 116 | } |
| 117 | |
| 118 | // Compute masks for the last 16 byte stripe |
| 119 | // |
| 120 | uint64_t num_stripes = bit_util::CeilDiv(key_length, kStripeSize); |
| 121 | uint32_t mask1, mask2, mask3, mask4; |
| 122 | StripeMask(((key_length - 1) & (kStripeSize - 1)) + 1, &mask1, &mask2, &mask3, &mask4); |
| 123 | |
| 124 | for (uint32_t i = 0; i < num_rows_safe; ++i) { |
| 125 | const uint8_t* key = keys + static_cast<uint64_t>(i) * key_length; |
| 126 | uint32_t acc1, acc2, acc3, acc4; |
| 127 | ProcessFullStripes(num_stripes, key, &acc1, &acc2, &acc3, &acc4); |
| 128 | ProcessLastStripe(mask1, mask2, mask3, mask4, key + (num_stripes - 1) * kStripeSize, |
| 129 | &acc1, &acc2, &acc3, &acc4); |
| 130 | uint32_t acc = CombineAccumulators(acc1, acc2, acc3, acc4); |
| 131 | acc = Avalanche(acc); |
| 132 | |
| 133 | if (T_COMBINE_HASHES) { |
| 134 | hashes[i] = CombineHashesImp(hashes[i], acc); |
| 135 | } else { |
| 136 | hashes[i] = acc; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | uint32_t last_stripe_copy[4]; |
| 141 | for (uint32_t i = num_rows_safe; i < num_rows; ++i) { |
| 142 | const uint8_t* key = keys + static_cast<uint64_t>(i) * key_length; |
| 143 | uint32_t acc1, acc2, acc3, acc4; |
| 144 | ProcessFullStripes(num_stripes, key, &acc1, &acc2, &acc3, &acc4); |
| 145 | memcpy(last_stripe_copy, key + (num_stripes - 1) * kStripeSize, |
| 146 | key_length - (num_stripes - 1) * kStripeSize); |
| 147 | ProcessLastStripe(mask1, mask2, mask3, mask4, |
| 148 | reinterpret_cast<const uint8_t*>(last_stripe_copy), &acc1, &acc2, |
| 149 | &acc3, &acc4); |
| 150 | uint32_t acc = CombineAccumulators(acc1, acc2, acc3, acc4); |
| 151 | acc = Avalanche(acc); |
| 152 | |
| 153 | if (T_COMBINE_HASHES) { |
| 154 | hashes[i] = CombineHashesImp(hashes[i], acc); |
| 155 | } else { |
| 156 | hashes[i] = acc; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | template <typename T, bool T_COMBINE_HASHES> |
| 162 | void Hashing32::HashVarLenImp(uint32_t num_rows, const T* offsets, |
nothing calls this directly
no test coverage detected