Skip to content

Commit 06f2dd1

Browse files
authored
Merge pull request #325 from BombaxCeiba/popcnt_cause_crash
Add a CMake option to support disabling the popcnt instruction
2 parents 2170036 + ddb7713 commit 06f2dd1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ foreach(name
179179
configure_file("${name}.in" "${name}" @ONLY)
180180
endforeach()
181181

182+
if(NOT ENABLE_POPCNT)
183+
add_definitions(-DDISABLE_POPCNT)
184+
endif()
185+
182186
if(ENABLE_SHARED_LIB AND ENABLE_STATIC_LIB AND MSVC AND NOT STATIC_LIB_SUFFIX)
183187
set(STATIC_LIB_SUFFIX "_static")
184188
endif()
@@ -213,6 +217,8 @@ message(STATUS "summary of build options:
213217
CXXFLAGS: ${CMAKE_CXX_FLAGS_${_build_type}} ${CMAKE_CXX_FLAGS}
214218
WARNCFLAGS: ${WARNCFLAGS}
215219
WARNCXXFLAGS: ${WARNCXXFLAGS}
220+
SIMD instruction:
221+
Enable popcnt: ${ENABLE_POPCNT}
216222
Library:
217223
Shared: ${ENABLE_SHARED_LIB}
218224
Static: ${ENABLE_STATIC_LIB}

CMakeOptions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ option(ENABLE_LIB_ONLY "Build libnghttp3 only" OFF)
77
option(ENABLE_STATIC_LIB "Build libnghttp3 as a static library" ON)
88
option(ENABLE_SHARED_LIB "Build libnghttp3 as a shared library" ON)
99
option(ENABLE_STATIC_CRT "Build libnghttp3 against the MS LIBCMT[d]")
10+
option(ENABLE_POPCNT "Enable popcnt instruction" ON)
1011
cmake_dependent_option(BUILD_TESTING "Enable tests" ON "ENABLE_STATIC_LIB" OFF)
1112

1213
# vim: ft=cmake:

lib/nghttp3_ringbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535

3636
#ifndef NDEBUG
3737
static int ispow2(size_t n) {
38-
# if defined(_MSC_VER) && !defined(__clang__) && \
39-
(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
38+
# if defined(DISABLE_POPCNT) || \
39+
(defined(_MSC_VER) && !defined(__clang__) && \
40+
(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941)))
4041
return n && !(n & (n - 1));
4142
# elif defined(WIN32)
4243
return 1 == __popcnt((unsigned int)n);

0 commit comments

Comments
 (0)