diff --git a/0001-Optimizing-the-rand-function-on-arm64-platforms.patch b/0001-Optimizing-the-rand-function-on-arm64-platforms.patch new file mode 100644 index 0000000000000000000000000000000000000000..7f0599424870eb00ad023809ae4ea11763ea7a29 --- /dev/null +++ b/0001-Optimizing-the-rand-function-on-arm64-platforms.patch @@ -0,0 +1,64 @@ +From a71c4a25086acf6f36b18607dfc9d19b3d62bc86 Mon Sep 17 00:00:00 2001 +From: Tian Tao +Date: Thu, 20 Jul 2023 16:25:44 +0800 +Subject: [PATCH] Optimizing the rand function on arm64 platforms + +Armv8.5 adds the FEAT_RNG feature so that true random numbers can be +obtained from the cpu. This optimization is therefore proposed for the +arm64 platform. + +Signed-off-by: Tian Tao +--- + stdlib/rand.c | 32 ++++++++++++++++++++++++++++++++ + 1 file changed, 32 insertions(+) + +diff --git a/stdlib/rand.c b/stdlib/rand.c +index c250c065e4..f199dbd65f 100644 +--- a/stdlib/rand.c ++++ b/stdlib/rand.c +@@ -19,10 +19,42 @@ + + #undef rand + ++#ifdef __aarch64__ ++// A global variable to indicate whether rndr instruction is supported ++static int rndr_supported = 0; ++// A function prototype to check rndr support ++static void check_rndr_support (void) __attribute__ ((constructor)); ++#endif + + /* Return a random integer between 0 and RAND_MAX. */ + int + rand (void) + { ++ // Use armv8.5 rndr instruction if supported ++#ifdef __aarch64__ ++ if (rndr_supported) { ++ unsigned int r; ++ asm volatile("mrs %0, s3_3_c2_c4_0" : "=r" (r)); ++ // Discard the least random bit ++ r >>=1; ++ return (int) r; ++ } ++#endif + return (int) __random (); + } ++ ++#ifdef __aarch64__ ++// A function to check rndr support and set the global variable accordingly ++static void ++check_rndr_support (void) ++{ ++ unsigned long isar0; ++ // Read the ID_AA64ISAR0_EL1 register to check the rndr feature ++ asm volatile("mrs %0, s3_0_c0_c6_0" : "=r" (isar0)); ++ // Check the bits [63:60] for the rndr feature ++ if ((isar0 >> 60) & 0xf) { ++ // Set the global variable to indicate rndr support ++ rndr_supported = 1; ++ } ++} ++#endif +-- +2.33.0 + diff --git a/glibc.spec b/glibc.spec index f3aee523298d9c87a7e8582ef805afd3d9d64423..f6184964ee76b66df803a4c9a1d87f1154c76d81 100644 --- a/glibc.spec +++ b/glibc.spec @@ -65,7 +65,7 @@ ############################################################################## Name: glibc Version: 2.36 -Release: 18 +Release: 19 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -115,6 +115,7 @@ Patch9014: strcmp-delete-align-for-loop_aligned.patch Patch9015: add-pthread_cond_clockwait-GLIBC_2_28.patch Patch9016: add-GB18030-2022-charmap-BZ-30243.patch Patch9017: 0001-Optimizing-__random-for-single-threaded-scenarios.patch +Patch9018: 0001-Optimizing-the-rand-function-on-arm64-platforms.patch Provides: ldconfig rtld(GNU_HASH) bundled(gnulib) @@ -1274,6 +1275,9 @@ fi %endif %changelog +* Thu Jul 20 2023 jiangyingxin - 2.36-19 +- Optimizing the rand function on arm64 platforms + * Tue Jul 11 2023 jiangyingxin - 2.36-18 - Optimizing __random for single-threaded scenarios