Skip to content

Commit

Permalink
deps: fixup win arm64 build for ngtcp2/nghttp3
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Aug 24, 2020
1 parent aaaa51f commit 097e960
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions deps/nghttp3/lib/nghttp3_ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@

#include "nghttp3_macro.h"

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

int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size,
const nghttp3_mem *mem) {
if (nmemb) {
#ifdef WIN32
assert(1 == __popcnt((unsigned int)nmemb));
assert(1 == __nghttp3_popcnt((unsigned int)nmemb));
#else
assert(1 == __builtin_popcount((unsigned int)nmemb));
#endif
Expand Down Expand Up @@ -127,7 +131,7 @@ int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb) {
}

#ifdef WIN32
assert(1 == __popcnt((unsigned int)nmemb));
assert(1 == __nghttp3_popcnt((unsigned int)nmemb));
#else
assert(1 == __builtin_popcount((unsigned int)nmemb));
#endif
Expand Down
10 changes: 7 additions & 3 deletions deps/ngtcp2/lib/ngtcp2_ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,24 @@

#include "ngtcp2_macro.h"

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

int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size,
const ngtcp2_mem *mem) {
#ifdef WIN32
assert(1 == __popcnt((unsigned int)nmemb));
assert(1 == __ngtcp2_popcnt((unsigned int)nmemb));
#else
assert(1 == __builtin_popcount((unsigned int)nmemb));
#endif
Expand Down

0 comments on commit 097e960

Please sign in to comment.