Skip to content

Make sibling twiddle lookup branchless#40

Merged
falseywinchnet merged 1 commit into
mainfrom
cvyk8z-main/refactor-twiddle-functions-for-branchless-lookup
Jun 21, 2026
Merged

Make sibling twiddle lookup branchless#40
falseywinchnet merged 1 commit into
mainfrom
cvyk8z-main/refactor-twiddle-functions-for-branchless-lookup

Conversation

@falseywinchnet

Copy link
Copy Markdown
Owner

Motivation

  • Prevent the compiler from lowering scalar twiddle selection into large conditional decision trees by making sibling twiddle lookup data-driven and branchless while preserving the mapping 0 -> 0, 1 -> 1, and m > 1 -> m ^ 1.

Description

  • Replaced s_twiddle and sf_twiddle in src/detail/bruun_kernel.hpp with a branchless selector that computes u = static_cast<unsigned>(m), flip = static_cast<unsigned>(-(m > 1)) & 1u, and returns C[u ^ flip] / CF[u ^ flip] so sibling lookups become index operations instead of explicit m == 0 / m == 1 branches.

Testing

  • Ran make test asm-check; build/tests/correctness and build/tests/api_c completed successfully and the generated SSE2/AVX2 assembly shows twiddle lookup lowering to setg/xor/load patterns instead of helper-level conditional branches.

Codex Task

@falseywinchnet falseywinchnet merged commit f8c8f02 into main Jun 21, 2026
4 checks passed
@falseywinchnet falseywinchnet deleted the cvyk8z-main/refactor-twiddle-functions-for-branchless-lookup branch June 23, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant