Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CMake option to support disabling the popcnt instruction #325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ foreach(name
configure_file("${name}.in" "${name}" @ONLY)
endforeach()

option(ENABLE_POPCNT "Enable popcnt instruction" ON)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to CMakeOptions.txt?


if(NOT ENABLE_POPCNT)
add_definitions(-DDISABLE_POPCNT)
endif()

if(ENABLE_SHARED_LIB AND ENABLE_STATIC_LIB AND MSVC AND NOT STATIC_LIB_SUFFIX)
set(STATIC_LIB_SUFFIX "_static")
endif()
Expand Down Expand Up @@ -213,6 +219,8 @@ message(STATUS "summary of build options:
CXXFLAGS: ${CMAKE_CXX_FLAGS_${_build_type}} ${CMAKE_CXX_FLAGS}
WARNCFLAGS: ${WARNCFLAGS}
WARNCXXFLAGS: ${WARNCXXFLAGS}
SIMD instruction:
Enable popcnt: ${ENABLE_POPCNT}
Library:
Shared: ${ENABLE_SHARED_LIB}
Static: ${ENABLE_STATIC_LIB}
Expand Down
5 changes: 3 additions & 2 deletions lib/nghttp3_ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@

#ifndef NDEBUG
static int ispow2(size_t n) {
# if defined(_MSC_VER) && !defined(__clang__) && \
(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
# if defined(DISABLE_POPCNT) || \
(defined(_MSC_VER) && !defined(__clang__) && \
(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941)))
return n && !(n & (n - 1));
# elif defined(WIN32)
return 1 == __popcnt((unsigned int)n);
Expand Down
Loading