[libcxx-commits] [libcxx] [libc++] Add an ABI flag to optimize mersenne_twister_engine (PR #206423)
Kyungtak Woo via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 15 11:54:52 PDT 2026
kevinwkt wrote:
Hey @philnik777, I believe I'm getting some breakages due to this change when std::mt19937 is seeded using std::seed_seq under the vectorized ABI configuration (_LIBCPP_ABI_VERSION >= 2).
When initialized with a seed sequence, the engine bypasses the initial twist (__update_all_states()) due to an early return in the all-zero state check inside seed(_Sseq& __q). This causes the engine to return the raw, untwisted seed values (tempered) instead of the correct twisted values.
Here is a minimal reproducer:
```
#include <iostream>
#include <random>
int main() {
std::seed_seq sseq{15, 22, 288, 37};
std::mt19937 engine(sseq);
uint32_t val = engine();
std::cout << "Expected (Standard): 192527404\n";
std::cout << "Actual: " << val << "\n";
if (val == 360235457) {
std::cout << "RESULT: FAIL (returned untwisted state)\n";
return 1;
} else if (val == 192527404) {
std::cout << "RESULT: PASS\n";
return 0;
}
return 1;
}
```
I've been using using libc++ with the unstable ABI enabled and running into failure with
```
clang++ -stdlib=libc++ -D_LIBCPP_ABI_VERSION=2 repro.cc -o repro && ./repro
```
I created https://github.com/llvm/llvm-project/pull/209860 to try to address this but just wanted to make sure my assumptions are correct first.
https://github.com/llvm/llvm-project/pull/206423
More information about the libcxx-commits
mailing list