Skip to content

Commit

Permalink
Simplify for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jun 26, 2024
1 parent d1b04e0 commit c637dae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libpopcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
}
}

for (; i < size - size % 8; i += 8)
for (; i + 8 <= size; i += 8)
cnt += popcnt64(*(const uint64_t*)(ptr + i));

if (i < size)
Expand Down Expand Up @@ -659,7 +659,7 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
}
}

for (; i < size - size % 8; i += 8)
for (; i + 8 <= size; i += 8)
cnt += popcnt64_bitwise(*(const uint64_t*)(ptr + i));

if (i < size)
Expand Down Expand Up @@ -810,7 +810,7 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
}
}

for (; i < size - size % 8; i += 8)
for (; i + 8 <= size; i += 8)
cnt += popcnt64(*(const uint64_t*)(ptr + i));

if (i < size)
Expand Down Expand Up @@ -857,7 +857,7 @@ static inline uint64_t popcnt(const void* data, uint64_t size)
}
}

for (; i < size - size % 8; i += 8)
for (; i + 8 <= size; i += 8)
cnt += popcnt64(*(const uint64_t*)(ptr + i));

if (i < size)
Expand Down

0 comments on commit c637dae

Please sign in to comment.