[PATCH 2/2] Add single-threaded fast path to rand()
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Mar 20 14:28:43 GMT 2024
Hi Cristian,
> Yeah, it should be no surprise this interfaces are bad,
> I thought this was common knowledge.
It's bad but we also made it thread-safe via locks rather than add its state to TLS.
> we need something like https://github.com/C2SP/C2SP/blob/main/chacha8rand.md
> which prety much outperforms even non-CS algorithms in at least 64 bit x86.
> but the question of the state remains.global? TLS? how to discard it
> in all the appropriate occasions?
I believe the current implementation is already way overkill. All you need is a simple
LFSR random generator with 64 bits of state and a decently large cycle. It's not
meant to be a serious random number generator - it's invariably used to generate
randomized inputs for testing and benchmarking. That's all. The complaints are
due to it being too slow due to all the locking.
Cheers,
Wilco
More information about the Libc-alpha
mailing list