Skip to content

Mark OASIS reader error branches as unlikely - #2512

Open
nikosavola wants to merge 1 commit into
KLayout:masterfrom
nikosavola:pr-oasis-hints
Open

nikosavola wants to merge 1 commit into
KLayout:masterfrom
nikosavola:pr-oasis-hints

Conversation

@nikosavola

@nikosavola nikosavola commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Marks the error branches in the OASIS varint and coordinate readers as cold paths.

  • Adds TL_IF_UNLIKELY to tlCpp.h: an if statement whose body is a cold path. It expands to if (cond) [[unlikely]] where the standard provides the attribute (C++20 and up, through __has_cpp_attribute), to __builtin_expect on gcc and clang below C++20, and to a plain if elsewhere.
  • Uses it on the end-of-file, overflow and divider checks in get_uint64, get_uint32, and the coordinate and delta readers. error() is virtual and not noreturn, so a compiler cannot tell these branches are cold from the call graph.
  • On current gcc and clang the generated code is the same with or without the markers, so this mainly records the intent in the source.

- Add TL_IF_UNLIKELY to tlCpp.h: an if statement whose body is a cold path, [[unlikely]] where C++20 provides it, __builtin_expect on older gcc and clang
- error() is virtual and not noreturn, so the compiler cannot tell the EOF and overflow checks in the varint and coordinate readers are cold
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