Skip to content

Commit

Permalink
turn CDIV macro into a proper function
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn authored and hoffmang9 committed Oct 5, 2020
1 parent bb554ef commit ae6d509
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class BitsGeneric {
}

Util::IntToEightBytes(tmp, values_[i] << (64 - last_size_));
memcpy(buffer + i * 8, tmp, CDIV(last_size_, 8));
memcpy(buffer + i * 8, tmp, cdiv(last_size_, 8));
}

std::string ToString() const
Expand Down
4 changes: 2 additions & 2 deletions src/calculate_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class FxCalculator {
input.ToBytes(input_bytes);

blake3_hasher_init(&hasher);
blake3_hasher_update(&hasher, input_bytes, CDIV(input.GetSize(), 8));
blake3_hasher_update(&hasher, input_bytes, cdiv(input.GetSize(), 8));
blake3_hasher_finalize(&hasher, hash_bytes, sizeof(hash_bytes));

f = Util::EightBytesToInt(hash_bytes) >> (64 - (k_ + kExtraBits));
Expand All @@ -287,7 +287,7 @@ class FxCalculator {
uint8_t len = kVectorLens[table_index_ + 1];
uint8_t start_byte = (k_ + kExtraBits) / 8;
uint8_t end_bit = k_ + kExtraBits + k_ * len;
uint8_t end_byte = CDIV(end_bit, 8);
uint8_t end_byte = cdiv(end_bit, 8);

// TODO: proper support for partial bytes in Bits ctor
c = Bits(hash_bytes + start_byte, end_byte - start_byte, (end_byte - start_byte) * 8);
Expand Down
2 changes: 1 addition & 1 deletion src/phase3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void WriteParkToFile(
park_stubs_bits.AppendValue(stub, (k - kStubMinusBits));
}
uint32_t stubs_size = EntrySizes::CalculateStubsSize(k);
uint32_t stubs_valid_size = CDIV(park_stubs_bits.GetSize(), 8);
uint32_t stubs_valid_size = cdiv(park_stubs_bits.GetSize(), 8);
park_stubs_bits.ToBytes(index);
memset(index + stubs_valid_size, 0, stubs_size - stubs_valid_size);
index += stubs_size;
Expand Down
4 changes: 2 additions & 2 deletions src/phase4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ void RunPhase4(uint8_t k, uint8_t pos_size, FileDisk &tmp2_disk, Phase3Results &

uint64_t begin_byte_C1 = res.final_table_begin_pointers[7] + number_of_p7_parks * P7_park_size;

uint64_t total_C1_entries = CDIV(res.final_entries_written, kCheckpoint1Interval);
uint64_t total_C1_entries = cdiv(res.final_entries_written, kCheckpoint1Interval);
uint64_t begin_byte_C2 = begin_byte_C1 + (total_C1_entries + 1) * (Util::ByteAlign(k) / 8);
uint64_t total_C2_entries = CDIV(total_C1_entries, kCheckpoint2Interval);
uint64_t total_C2_entries = cdiv(total_C1_entries, kCheckpoint2Interval);
uint64_t begin_byte_C3 = begin_byte_C2 + (total_C2_entries + 1) * (Util::ByteAlign(k) / 8);

uint32_t size_C3 = EntrySizes::CalculateC3Size(k);
Expand Down
3 changes: 2 additions & 1 deletion src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include <utility>
#include <vector>

#define CDIV(a, b) (((a) + (b)-1) / (b))
template <typename Int>
constexpr inline Int cdiv(Int a, int b) { return (a + b - 1) / b; }

#ifdef _WIN32
#include "uint128_t.h"
Expand Down

0 comments on commit ae6d509

Please sign in to comment.