Skip to content

Commit

Permalink
Fix BLAKE3 compilation on 32-bit x86
Browse files Browse the repository at this point in the history
Submitted upstream in BLAKE3-team/BLAKE3#38
  • Loading branch information
erijo committed Jan 22, 2020
1 parent 10d9b0f commit 9339442
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/third_party/blake3/blake3_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ static const uint8_t MSG_SCHEDULE[7][16] = {
{11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13},
};

INLINE uint32_t counter_low(uint64_t counter) { return (uint32_t)counter; }

INLINE uint32_t counter_high(uint64_t counter) {
return (uint32_t)(counter >> 32);
}

// Count the number of 1 bits.
INLINE uint8_t popcnt(uint64_t x) {
#if __POPCNT__
#ifdef __x86_64__
return (uint8_t)_mm_popcnt_u64(x);
#else
return (uint8_t)(_mm_popcnt_u32(counter_low(x)) + _mm_popcnt_u32(counter_high(x)));
#endif
#else
uint8_t count = 0;
while (x > 0) {
Expand All @@ -57,12 +67,6 @@ INLINE uint8_t popcnt(uint64_t x) {
#endif
}

INLINE uint32_t counter_low(uint64_t counter) { return (uint32_t)counter; }

INLINE uint32_t counter_high(uint64_t counter) {
return (uint32_t)(counter >> 32);
}

INLINE uint32_t load32(const void *src) {
const uint8_t *p = (const uint8_t *)src;
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
Expand Down

0 comments on commit 9339442

Please sign in to comment.