Skip to content

[libcu++] Optimize cuda::std::rotl and cuda::std::rotr#10004

Open
davebayer wants to merge 3 commits into
NVIDIA:mainfrom
davebayer:optimize_bit_rotations
Open

[libcu++] Optimize cuda::std::rotl and cuda::std::rotr#10004
davebayer wants to merge 3 commits into
NVIDIA:mainfrom
davebayer:optimize_bit_rotations

Conversation

@davebayer

@davebayer davebayer commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

This PR optimizes cuda::std::rotl and cuda::std::rotr for 8, 16, 64 and 128-bit wide unsigned integers.

Here is a before/after table of number of generated SASS instructions on sm120:

Type Before After Notes
uint8_t 32 4 Repeats lowest 8-bits in 32-bit word and performs funnel shift.
uint16_t 33 4 Repeats lowest 16-bits in 32-bit word and performs funnel shift.
uint64_t 26 5 Performs 2 funnel shifts and shuffles the 32-bit words if needed.
__uint128_t 40 13 Performs 4 funnel shifts and shuffles the 32-bit words if needed. Most of the instructions are SEL.

@davebayer
davebayer requested a review from a team as a code owner July 18, 2026 10:17
@davebayer
davebayer requested a review from wmaxey July 18, 2026 10:17
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 18, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: acfb931d-921c-469c-8e79-d94655282723

📥 Commits

Reviewing files that changed from the base of the PR and between a262443 and a883b8b.

📒 Files selected for processing (1)
  • libcudacxx/include/cuda/std/__bit/rotate.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • libcudacxx/include/cuda/std/__bit/rotate.h

📝 Walkthrough

Summary by CodeRabbit

  • Performance Improvements
    • Improved device-side bit-rotation performance for unsigned 8-bit, 16-bit, 32-bit, and 64-bit values.
    • Added specialized optimized paths for 8/16 using byte-based operations and for 64-bit by rotating low/high 32-bit halves and recombining, while keeping existing behavior consistent across supported types.

Walkthrough

Changes

Device rotate paths

Layer / File(s) Summary
Specialized device rotate implementations
libcudacxx/include/cuda/std/__bit/rotate.h
Device rotr and rotl paths add uint8_t and uint16_t handling through __byte_perm and 32-bit funnelshifts, plus uint64_t handling through split-half funnelshifts and conditional recombination.

Possibly related PRs

  • NVIDIA/cccl#9874: Updates 64-bit rotate builtin macro definitions in the same header.

Suggested reviewers: wmaxey


Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 1h 23m: Pass: 99%/120 | Total: 2d 02h | Max: 1h 23m | Hits: 72%/537335

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

1 participant