From fd8f5b5af7d73f697fe9654ad8ed7953cd597287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:51:07 -0700 Subject: [PATCH] [release/8.0] disable optimizations for PopCount (#99832) (#99926) * disable optimizations for PopCount avoid using an optimization which might fail on non-SSE4 cpus. * remove whitespace for jit-format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Manish Godse <61718172+mangod9@users.noreply.github.com> --- src/coreclr/jit/utils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 2e1c0a52a3d81..4c9fe6479eca4 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -3192,6 +3192,11 @@ uint32_t BitOperations::Log2(uint64_t value) // Return Value: // The population count (number of bits set) of value // +#if defined(_MSC_VER) +// Disable optimizations for PopCount to avoid the compiler from generating intrinsics +// not supported on all platforms. +#pragma optimize("", off) +#endif // _MSC_VER uint32_t BitOperations::PopCount(uint32_t value) { #if defined(_MSC_VER) @@ -3244,6 +3249,9 @@ uint32_t BitOperations::PopCount(uint64_t value) return static_cast(result); #endif } +#if defined(_MSC_VER) +#pragma optimize("", on) +#endif // _MSC_VER //------------------------------------------------------------------------ // BitOperations::ReverseBits: Reverses the bits in an integer value