mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-12 19:04:54 +03:00
stdlib: Add single-threaded fast path to rand()
Improve performance of rand() and __random() by adding a single-threaded fast path. Bench-random-lock shows about 5x speedup on Neoverse V1. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
@@ -51,6 +51,7 @@
|
|||||||
SUCH DAMAGE.*/
|
SUCH DAMAGE.*/
|
||||||
|
|
||||||
#include <libc-lock.h>
|
#include <libc-lock.h>
|
||||||
|
#include <sys/single_threaded.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -288,6 +289,12 @@ __random (void)
|
|||||||
{
|
{
|
||||||
int32_t retval;
|
int32_t retval;
|
||||||
|
|
||||||
|
if (SINGLE_THREAD_P)
|
||||||
|
{
|
||||||
|
(void) __random_r (&unsafe_state, &retval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
__libc_lock_lock (lock);
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
(void) __random_r (&unsafe_state, &retval);
|
(void) __random_r (&unsafe_state, &retval);
|
||||||
|
Reference in New Issue
Block a user