Skip to content

fix(field_encoder): replace __builtin_expect with C++20 [[likely]]/[[unlikely]] for MSVC#115

Merged
facontidavide merged 1 commit into
mainfrom
fix/msvc-builtin-expect
Jun 4, 2026
Merged

fix(field_encoder): replace __builtin_expect with C++20 [[likely]]/[[unlikely]] for MSVC#115
facontidavide merged 1 commit into
mainfrom
fix/msvc-builtin-expect

Conversation

@facontidavide
Copy link
Copy Markdown
Owner

What

Replace __builtin_expect with the C++20 [[likely]]/[[unlikely]] attributes in FieldEncoderFloatN_Lossy::encode (cloudini_lib/src/field_encoder.cpp).

Why

__builtin_expect is a GCC/Clang builtin; MSVC doesn't provide it. The hint in the always-compiled NaN fallback path breaks every MSVC build (the one in the SIMD fast path additionally breaks under /arch:AVX). This is the only blocker preventing cloudini_lib from compiling under MSVC — the rest of the library is already portable: intrinsics.hpp falls back to scalar when __SSE__/__AVX__ aren't defined, and the contrib headers (unordered_dense.h, nanocdr.hpp, span.hpp) are MSVC-safe.

Since cloudini already requires C++20 (check_min_cppstd(20)), [[likely]]/[[unlikely]] is an equivalent, fully portable replacement with no behavior change on GCC/Clang.

Testing

  • cloudini_lib rebuilds clean on GCC 13 (Linux) — no regression.
  • ⏳ MSVC verification pending a Conan package build; this change unblocks it (the recipe's is_msvc ConanInvalidConfiguration gate is being removed separately).

Context

Surfaced while consuming cloudini from PlotJuggler 4, whose Windows CI failed at conan install on cloudini's MSVC rejection. This is the upstream code fix that makes MSVC support real.

🤖 Generated with Claude Code

…iltin_expect

__builtin_expect is a GCC/Clang builtin that MSVC does not provide. The hint in
the always-compiled NaN fallback path (and the SIMD fast path under /arch:AVX)
made FieldEncoderFloatN_Lossy::encode fail to compile under MSVC.

cloudini already requires C++20, so the standard [[likely]]/[[unlikely]]
attributes are an equivalent, fully portable replacement — no behavior change on
GCC/Clang, and the library now compiles under MSVC.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@facontidavide facontidavide merged commit 294ad91 into main Jun 4, 2026
5 checks passed
@facontidavide facontidavide deleted the fix/msvc-builtin-expect branch June 4, 2026 12:51
@facontidavide facontidavide mentioned this pull request Jun 4, 2026
facontidavide added a commit that referenced this pull request Jun 4, 2026
Bump cloudini_lib + cloudini_ros (package.xml) and the Foxglove extension
(package.json/lock) to 1.2.2, with CHANGELOG entries. The library change in
this release is the MSVC __builtin_expect -> [[likely]]/[[unlikely]] fix (#115);
the rest are dev-dependency bumps.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant