Landing: 2aab5af1738b

Project / Subsystem

gcc / libstdc++

Date

2026-07-28

Author

Tomasz Kamiński

Commit

2aab5af1738b3adc2e673977b4cd0d5c393b4252

Source

github

Perf win

Yes

Breaking

No

All attributes

project
gcc
subsystem
libstdc++
patch_id
—
commit_hash
2aab5af1738b3adc2e673977b4cd0d5c393b4252
source_type
github
headline
libstdc++: Extend Lemire's algorithm to all power-of-two ranges.
tldr
Libstdc++ now uses Lemire's algorithm for all power-of-two sized random number generation ranges.
author
Tomasz Kamiński
outcome
committed
performance_win
true
breaking_change
false
series_id
—
series_parts
[]
tags
  • • libstdc++
  • • random
  • • optimization
discussion_id_link
—
bugzilla_pr
—
date
2026-07-28T00:00:00.000Z

This change expands the application of Lemire’s algorithm in libstdc++ to cover all random number generators producing values in ranges that are powers of two. Previously, this optimization was limited to 2^32 and 2^64 ranges. By masking the conversion of __product to the lowest _Bits width, the algorithm is now more universally applicable. This improves the efficiency of random number generation for a wider set of configurations, with the masking operation being optimized away by compilers when the bit width matches the target type.