Skip to content

bgsegm: Enable __popcnt intrinsic for MSVC on ARM to fix LSBP test failure #3953

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

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from
Open
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion modules/bgsegm/src/bgfg_gsoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const float LSBPtau = 0.05f;
inline int LSBPDist32(unsigned n) {
#if defined(__GNUC__) || defined(__clang__)
return __builtin_popcount(n);
#elif defined(_MSC_VER)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why "less" in _MSC_VER < 1941? Most probably it's a mistake.

Copy link
Author

Choose a reason for hiding this comment

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

Why "less" in _MSC_VER < 1941? Most probably it's a mistake.

The condition _MSC_VER < 1941 was added to exclude _M_ARM64 only on older MSVC versions where __popcnt isn’t supported. The logic ensures that __popcnt is used only when compiling with MSVC 1941 or newer on ARM64.

#elif defined(_MSC_VER) && !(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
return __popcnt(n);
#else
// Taken from http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
Expand Down
Loading