Skip to content

Commit

Permalink
Implement popcnt and lzcnt for windows arm64
Browse files Browse the repository at this point in the history
Fixes: #261
  • Loading branch information
jasnell authored and tatsuhiro-t committed Aug 21, 2020
1 parent 6e02c26 commit 576f2d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ngtcp2_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ static uint64_t ngtcp2_cbrt(uint64_t n) {
#if defined(_MSC_VER)
# if defined(_M_X64)
d = (int)__lzcnt64(n);
# elif defined(_M_ARM64)
{
unsigned long index;
d = sizeof(uint64_t) * CHAR_BIT;
if (_BitScanReverse64(&index, n)) {
d = d - 1 - index;
}
}
# else
if ((n >> 32) != 0) {
d = __lzcnt((unsigned int)(n >> 32));
Expand Down
10 changes: 10 additions & 0 deletions lib/ngtcp2_ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@

#include "ngtcp2_macro.h"

#if defined(_MSC_VER) && defined(_M_ARM64)
unsigned int __popcnt(unsigned int x) {
unsigned int c = 0;
for (; x; ++c) {
x &= x - 1;
}
return c;
}
#endif

int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size,
const ngtcp2_mem *mem) {
#ifdef WIN32
Expand Down

0 comments on commit 576f2d4

Please sign in to comment.