[libcxx-commits] [PATCH] D125329: Replace modulus operations in std::seed_seq::generate with conditional checks.

Laramie Leavitt via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 16 10:01:51 PDT 2022


laramiel updated this revision to Diff 429755.
laramiel added a comment.

Adjust comments & rename km1modn to k1modn.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125329/new/

https://reviews.llvm.org/D125329

Files:
  libcxx/include/__random/seed_seq.h


Index: libcxx/include/__random/seed_seq.h
===================================================================
--- libcxx/include/__random/seed_seq.h
+++ libcxx/include/__random/seed_seq.h
@@ -109,23 +109,24 @@
             __first[__q] += __r;
             __first[0] = __r;
         }
+        // initialize {(__k + x) % __n} indexing terms
         size_t __kmodn = 0;          // __k % __n
+        size_t __k1modn = __n - 1;   // (__k - 1) % __n
         size_t __kpmodn = __p % __n; // (__k + __p) % __n
         size_t __kqmodn = __q % __n; // (__k + __q) % __n
-        size_t __km1modn = __n - 1;  // (__k-1) % __n
 
         for (size_t __k = 1; __k <= __s; ++__k)
         {
           if (++__kmodn == __n)
             __kmodn = 0;
-          if (++__km1modn == __n)
-            __km1modn = 0;
+          if (++__k1modn == __n)
+            __k1modn = 0;
           if (++__kpmodn == __n)
             __kpmodn = 0;
           if (++__kqmodn == __n)
             __kqmodn = 0;
 
-          result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__km1modn]);
+          result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__k1modn]);
           __first[__kpmodn] += __r;
           __r += __kmodn + __v_[__k - 1];
           __first[__kqmodn] += __r;
@@ -135,14 +136,14 @@
         {
           if (++__kmodn == __n)
             __kmodn = 0;
-          if (++__km1modn == __n)
-            __km1modn = 0;
+          if (++__k1modn == __n)
+            __k1modn = 0;
           if (++__kpmodn == __n)
             __kpmodn = 0;
           if (++__kqmodn == __n)
             __kqmodn = 0;
 
-          result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__km1modn]);
+          result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[__k1modn]);
           __first[__kpmodn] += __r;
           __r += __kmodn;
           __first[__kqmodn] += __r;
@@ -152,14 +153,14 @@
         {
           if (++__kmodn == __n)
             __kmodn = 0;
-          if (++__km1modn == __n)
-            __km1modn = 0;
+          if (++__k1modn == __n)
+            __k1modn = 0;
           if (++__kpmodn == __n)
             __kpmodn = 0;
           if (++__kqmodn == __n)
             __kqmodn = 0;
 
-          result_type __r = 1566083941 * _Tp(__first[__kmodn] + __first[__kpmodn] + __first[__km1modn]);
+          result_type __r = 1566083941 * _Tp(__first[__kmodn] + __first[__kpmodn] + __first[__k1modn]);
           __first[__kpmodn] ^= __r;
           __r -= __kmodn;
           __first[__kqmodn] ^= __r;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125329.429755.patch
Type: text/x-patch
Size: 2612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220516/f317f54f/attachment-0001.bin>


More information about the libcxx-commits mailing list