mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01: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:
parent
4734d0f8ad
commit
be0cfd848d
1 changed files with 7 additions and 0 deletions
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue