XorSAR++/+* PRNG, 16-bit State Example and Working Code, 4 to 28-Bit State Constants, 64-Bit State Example ASM Dump

133 views
Skip to first unread message

Cerian Knight

unread,
Dec 29, 2018, 7:30:37 PM12/29/18
to xorsar...@googlegroups.com
Normal approaches to creating pseudo-randomness often fall victim to artifacts from the structure of traditional math
operations, excessive complexity, trivial or accidental invertibility, unusable portions of state, escape-from-zero issues,
and/or run slowly due to the use of conventional non-linear functions.

The XorSAR (for Signed Arithmetic Rotation) class of PRNGs attempts to escape those pitfalls by using two simple rotation
operations, but one is a custom signed rotation on a single state variable, and the other is a standard rotation on the state
sum added or multiplied by a constant (A) and then xor masked with another constant (B). In that way randomness in the bits is
propagated simultaneously from both ends, as well as toward the middle by twisting (C) the stream to normalize the endpoint
randomness throughout. The result is that nearly all remnants of order are disseminated across all bits fairly evenly (when
the best constants are used) to ensure that common failings in statistical tests do not occur prematurely.

As a consequence of the design focus on the extremes of statistical randomness, speed, and code simplicity, while retaining
desirable equidistribution properties, some other desirable properties of a general purpose PRNG must have necessarily
been lost in the process? The short answer may be 'yes', as the equations describing the generator as a whole, or its individual
bits, are difficult to express comprehensibly in any form (linear, modular, etc., by me anyway). This makes it difficult to expand
the state/period to a more useful size, create independent steams, or implement seek-ability. On the plus-side, invertibility
is more of a challenge, but likely a meaningless consideration for this generator class in its current non-cryptographic form.

The simplest possible useful example that demonstrates the power of this method (and signed arithmetic rotation, in particular)
is the following 16-bit state / 8-bit output XorSAR8+* 1D and 2D code with a period of 65535 (full ++ and +* code farther down):
// Introductory example C++ XorSAR+* code (c) Chris Rutz

#include <stdint.h>

const uint8_t A = 0x73; // A must = 115/73H for this single constant example
 
// Seed state not everywhere 0
uint8_t s
[2] = {0,1};

inline uint8_t rar8(int8_t x) {
   
return (uint8_t)(x / 2 ^ (x << 7)) >> (int)(x==-1); }

inline uint8_t xorSAR16ps1D() {
    uint8_t result1D
= (s[0] - s[1]); // this 1D code line has been revised to use subtraction, as xor is sub-optimal
    uint8_t tmp
= (s[0] + s[1]) * A;
    s
[0] = rar8(s[1]);
    s
[1] = tmp;  // Normal bit xor and rotation here is not possible in this example, due to the chosen A constant
   
return result1D; } // Optional bit xor to map the single missing output to zero is not needed, due to the chosen A constant

inline uint8_t xorSAR16ps2D() {
    uint8_t result2D
= (s[0] + s[1]) * A;
    s
[0] = rar8(s[1]);
    s
[1] = result2D;
   
return result2D; }

In the above case the rest of the normal XorSAR constants associated with A = 115 cancel to
zero (B/C/D/X/Y all = 0), which makes this code the fastest, though not the most
statistically random (as it is running with 'one hand tied behind its back'), of the plus star
class. However, do not be fooled by the simplicity... even this example case exceeds the statistical
randomness of many comparable PRNGs of the same state size (for both 1D and 2D).

XorSAR is very fast in a 128-bit state form... ready for full testing if/when full-period 64-bit constants become
available (which will determine the efficacy of this algorithmic methodology). If the A/B constants are changed
to dynamic variables and the D constant = 0, the speed of the 128-bit ++ 2D variant is comparable to xoroshiro128**
and Lehmer128 (when it is similarly optimized with dynamic variables for constants, as the default implementation for
many PRNGs does not take into account the pipeline burden of in-lining normal constants with code under modern CPU architectures).

Full period 4-bit to 28-bit state constants, with arbitrary bit width rotation code, added as the first reply to this post: Constants

Example 128-bit state assembly language code added as second reply (using fictitious ABC constants), thus demonstrating
the underlying simplicity of the C++ code, which (hopefully at 32-bit state and above) belies its power: xorSAR128pp ASM

Let me know if you find this useful, have comments... or if you have some magical way to find constants required to extend
this logic to a 32-bit state, or beyond. I believe that mathematical study of the properties of and solutions to systems
of equations involving signed arithmetic right rotations could be very useful, with possible applications beyond PRNGs
(e.g., fast-hash, cryptographic, holographic data storage/compression, astrophysics, etc.) becoming somewhat more plausible
as one studies the obfuscated order resulting from the algorithmic implementation. For example, as a speculative thought-
experiment, try extending the logic of the rar function (modified to invert the lsb before shifting zero bits left on to
itself) down to a single set bit of input and you will reach a logical impasse reminiscent of either cooper-pairs in
superconductors or quantum-entangled qubits, where the math might be better expressed as a wave-function, which collapses
when additional bits are added.

16-bit state / 8-bit output / 1 and 2-Dimensional Equidistribution - Working Code:
// Original work (c) Chris Rutz, free for all uses in this 16-bit state form.
// Example C++ code of my XorSAR++ class generator with a period of 65535.
// Fast 8-bit output, 16-bit state.
// 1 or 2-dimensional equidistribution (short by a single 0 output, when D is used).
// PRNG combines output scrambler with calculation, while maintaining 2-dimensional equidistribution,
// reducible to 1D by returning xor of state.
// Inspired by G. Marsaglia, S. Vigna/D. Blackman, M. O'Neill, and my work with pre-selection masks
// for use with Echelle gratings used in some AES/OES (atomic/optical emission spectrometer) variants.

#include <stdint.h>

// Best known constants for 16-bit state 1D/2D ++ variant (for all ++/+* constants see list below code):
const uint8_t  A = 0xeb; // Constant A ADD
const uint8_t  B = 0x73; // Constant B XOR
const int      C = 3;    // Constant C ROL (0 is fastest, but much less random)
const uint8_t D2 = 0x04; // Remap short 2D output to zero (only if required, 0 is fastest)
const uint8_t D1 = 0xe5; // Remap short 1D output to zero (only if required, 0 is fastest)
const uint8_t  X = 0x5e; // Seed state 0 XOR mask
const uint8_t  Y = 0xbb; // Seed state 1 XOR mask
const uint8_t  W = 8;    // Output word size

// 16-bit state must not be directly seeded with above X and Y values simultaneously
uint8_t s
[2];

// Call this function to seed properly with 16 random bits, not everywhere zero
void xorSAR16_seed(uint16_t seed) {
  s
[0] = seed ^ X;
  s
[1] = (seed >> W) ^ Y; }

// 8-bit signed arithmetic right rotation
inline uint8_t rar8(int8_t x) {
 
return (uint8_t)(x / 2 ^ (x << (W - 1)) >> (int)(x==-1); }

// Old rar8, may be faster with some compilers
// inline uint8_t rar8o(int8_t x) {
//   uint8_t tmp = (x / 2) ^ (x << (W - 1));
//   if (x!=-1) { return tmp; } else { return 1 << (W - 2); } }

// 8-bit unsigned left rotation
inline uint8_t rol8(uint8_t x, int k) {
 
return (x << k) | (x >> (W - k)); }

// 2-Dimensional output ++ variant (fastest overall)
inline uint8_t xorSAR16pp2D() {
  uint8_t result
= s[0] + s[1] + A;
  s
[0] = rar8(s[1]);
  s
[1] = rol8(result ^ B, C);
 
return result ^ D2; } // Use D2 constant, only if required

// 2-Dimensional output +* variant (most random 2D)
inline uint8_t xorSAR16ps2D() {
  uint8_t result
= (s[0] + s[1]) * A;
  s
[0] = rar8(s[1]);
  s
[1] = rol8(result ^ B, C);
 
return result ^ D2; } // Use D2 constant, only if required

// 1-Dimensional output ++ variant (fastest 1D)
inline uint8_t xorSAR16pp1D() {
  uint8_t result
= s[0] ^ s[1]; // this 1D code line currently under review, as xor is sub-optimal
  uint8_t tmp = s[0] + s[1] + A;
  s
[0] = rar8(s[1]);
  s
[1] = rol8(tmp ^ B, C);
 
return result ^ D1; } // Use D1 constant, only if required

// 1-Dimensional output +* variant (most statistically random overall)
inline uint8_t xorSAR16ps1D() {
  uint8_t result
= s[0] ^ s[1]; // this 1D code line currently under review, as xor is sub-optimal
  uint8_t tmp = (s[0] + s[1]) * A;
  s
[0] = rar8(s[1]);
  s
[1] = rol8(tmp ^ B, C);
 
return result ^ D1; } // Use D1 constant, only if required

// Constants (hex) for 8-bit output / 16-bit state / 65535 period XorSAR16plusplus:
// A  B  C D2 D1 X  Y
// D9 6  0 54 7B 29 52
// 41 2C 0 EA 25 E3 C6
// D2 2D 0 B  35 13 26
// B5 5B 0 72 BD 94 29
// 59 86 0 D4 7B 29 52
// C1 AC 0 6A 25 E3 C6
// 52 AD 0 8B 35 13 26
// 35 DB 0 F2 BD 94 29
// 5C 23 2 79 DD B4 69
// DC A3 2 F9 DD B4 69
// 81 1F 3 9  68 D8 B0
// EB 73 3 4  E5 5E BB //recommended for fast 2D
// 1  9F 3 89 68 D8 B0
// 6B F3 3 84 E5 5E BB
// 8C 3  4 2F 23 E1 C2
// C1 50 4 3A 75 D3 A6
// E7 68 4 C6 1F F5 EA
// C  83 4 AF 23 E1 C2
// 41 D0 4 BA 75 D3 A6
// 67 E8 4 46 1F F5 EA
// EC 6B 5 44 96 73 E5
// 6C EB 5 C4 96 73 E5
// 1  2F 6 50 AF 70 DF
// 81 AF 6 D0 AF 70 DF
// 7F 52 7 90 D1 B0 61
// 52 76 7 FB 25 E3 C6
// FF D2 7 10 D1 B0 61
// D2 F6 7 7B 25 E3 C6

// Constants (hex) for 8-bit output / 16-bit state / 65535 period XorSAR16plusstar:
// A  B  C D2 D1 X  Y
// 73 0  0 0  0  0  0  // Constants for Preliminary Example 
// D1 69 0 6  D8 B7 6F
// D9 40 1 60 60 20 40
// D1 58 2 70 70 D0 A0
// 27 20 4 78 C6 43 85
// D7 91 4 A4 FA A9 53 // Excellent statistics, both 1D and 2D
// 93 F8 4 6F C5 BC 79
// BD 64 5 8F C3 BE 7D
// FF 2D 7 EF D1 B0 61
// 9B C7 7 2B 4D 3B 76
// 27 DF 7 83 39 17 2E

Cerian Knight

unread,
Dec 29, 2018, 8:40:44 PM12/29/18
to xorsar...@googlegroups.com
Below is a list of the full period constants for 2-bit to 14-bit output / 4-bit to 28-bit state xorSARpp and XorSARps, for reference.
However, code modification is required to support output word bit sizes other than 8/16/32/64. Example arbitrary bit rotation code at bottom of this post.

XorSARpp:
     Word(b) State(b) Period      A        B        C       D2       D1        X       Y
       2        4       15        0        2        0        3        3        2       1
       2        4       15        1        0        0        2        1        3       2
       2        4       15        2        0        0        1        3        2       1
       2        4       15        3        2        0        0        1        3       2
       2        4       15        0        1        1        3        3        2       1
       2        4       15        0        3        1        0        2        1       3
       2        4       15        1        1        1        1        0        0       0
       2        4       15        1        3        1        2        1        3       2
       2        4       15        2        1        1        2        2        1       3
       2        4       15        2        3        1        1        3        2       1
       2        4       15        3        1        1        0        1        3       2
       2        4       15        3        3        1        3        0        0       0
       3        6       63        1        4        0        1        6        3       5
       3        6       63        5        0        0        5        6        3       5
       3        6       63        2        2        1        2        0        0       0
       3        6       63        6        6        1        6        0        0       0
       4        8      255        4        4        0        4        0        0       0
       4        8      255       12       12        0       12        0        0       0
       4        8      255        4       12        1        8        4       12       8
       4        8      255       12        4        1        0        4       12       8
       4        8      255        1        0        3        4        3        1       2
       4        8      255        1       10        3        0       15       10       5
       4        8      255        4        4        3        4        0        0       0
       4        8      255        9        2        3        8       15       10       5
       4        8      255        9        8        3       12        3        1       2
       4        8      255       12       12        3       12        0        0       0
       5       10     1023        0       27        0       21        9        7      14
       5       10     1023        1        5        0       13       12        4       8
       5       10     1023       10        6        0       30        4       28      24
       5       10     1023       16       11        0        5        9        7      14
       5       10     1023       17       21        0       29       12        4       8
       5       10     1023       26       22        0       14        4       28      24
       5       10     1023        3        8        2        9        6        2       4
       5       10     1023       19       24        2       25        6        2       4
       5       10     1023        1       11        3        9        8       24      16
       5       10     1023        5       15        3       13        8       24      16
       5       10     1023       17       27        3       25        8       24      16
       5       10     1023       21       31        3       29        8       24      16
       5       10     1023        6        7        4       27        9        7      14
       5       10     1023       11       13        4       18       23        8      31
       5       10     1023       13       14        4        4       23       18       5
       5       10     1023       22       23        4       11        9        7      14
       5       10     1023       27       29        4        2       23        8      31
       5       10     1023       29       30        4       20       23       18       5
       6       12     4095        3       55        0       31       28       52      40
       6       12     4095       11       60        0       30       19       49      34
       6       12     4095       17       47        0       35       10        6      12
       6       12     4095       35       23        0       63       28       52      40
       6       12     4095       43       28        0       62       19       49      34
       6       12     4095       49       15        0        3       10        6      12
       6       12     4095       25       21        2       62       25       55      46
       6       12     4095       28       35        2       34        6        2       4
       6       12     4095       57       53        2       30       25       55      46
       6       12     4095       60        3        2        2        6        2       4
       6       12     4095       14       23        4        9       51       20      39
       6       12     4095       46       55        4       41       51       20      39
       6       12     4095        4       42        5       29       37       30      59
       6       12     4095       36       10        5       61       37       30      59
       7       14    16383       11       81        0       88       77       68       9
       7       14    16383       18      116        0        0       14      122     116
       7       14    16383       75       17        0       24       77       68       9
       7       14    16383       82       52        0       64       14      122     116
       7       14    16383       25       43        2      114       21      115     102
       7       14    16383       89      107        2       50       21      115     102
       7       14    16383       46       20        4       52        6        2       4
       7       14    16383      110       84        4      116        6        2       4
       7       14    16383        6       93        6       54       78       59     117
       7       14    16383       28       51        6        1       85       76      25
       7       14    16383       43       61        6       34      103       40      79
       7       14    16383       55       82        6       70       15        5      10
       7       14    16383       70       29        6      118       78       59     117
       7       14    16383       92      115        6       65       85       76      25
       7       14    16383      107      125        6       98      103       40      79
       7       14    16383      119       18        6        6       15        5      10
       8       16    65535       53      219        0      242      189      148      41
       8       16    65535       65       44        0      234       37      227     198
       8       16    65535       82      173        0      139       53       19      38
       8       16    65535       89      134        0      212      123       41      82
       8       16    65535      181       91        0      114      189      148      41
       8       16    65535      193      172        0      106       37      227     198
       8       16    65535      210       45        0       11       53       19      38
       8       16    65535      217        6        0       84      123       41      82
       8       16    65535       92       35        2      121      221      180     105
       8       16    65535      220      163        2      249      221      180     105
       8       16    65535        1      159        3      137      104      216     176
       8       16    65535      107      243        3      132      229       94     187
       8       16    65535      129       31        3        9      104      216     176
       8       16    65535      235      115        3        4      229       94     187
       8       16    65535       12      131        4      175       35      225     194
       8       16    65535       65      208        4      186      117      211     166
       8       16    65535      103      232        4       70       31      245     234
       8       16    65535      140        3        4       47       35      225     194
       8       16    65535      193       80        4       58      117      211     166
       8       16    65535      231      104        4      198       31      245     234
       8       16    65535      108      235        5      196      150      115     229
       8       16    65535      236      107        5       68      150      115     229
       8       16    65535        1       47        6       80      175      112     223
       8       16    65535      129      175        6      208      175      112     223
       8       16    65535       82      118        7      251       37      227     198
       8       16    65535      127       82        7      144      209      176      97
       8       16    65535      210      246        7      123       37      227     198
       8       16    65535      255      210        7       16      209      176      97
       9       18   262143        0       85        0      255      255       85     170
       9       18   262143        9      501        0      102      345      202     403
       9       18   262143       12       36        0      404      104      472     432
       9       18   262143      135      297        0       54      399      144     287
       9       18   262143      256      341        0      511      255       85     170
       9       18   262143      265      245        0      358      345      202     403
       9       18   262143      268      292        0      148      104      472     432
       9       18   262143      391       41        0      310      399      144     287
       9       18   262143       42      197        2      216       78       58     116
       9       18   262143       59      172        2      185      126       42      84
       9       18   262143      298      453        2      472       78       58     116
       9       18   262143      315      428        2      441      126       42      84
       9       18   262143        7      380        3      312      305      272      33
       9       18   262143      104      322        3      197       33       31      62
       9       18   262143      263      124        3       56      305      272      33
       9       18   262143      360       66        3      453       33       31      62
       9       18   262143      103      305        4      244      113       47      94
       9       18   262143      240      132        4      219       11      505     498
       9       18   262143      359       49        4      500      113       47      94
       9       18   262143      496      388        4      475       11      505     498
       9       18   262143       21       63        5      371       94      458     404
       9       18   262143      122      416        5       89      415      160     319
       9       18   262143      166       33        5       79       37      483     454
       9       18   262143      198      337        5      443      233      423     334
       9       18   262143      277      319        5      115       94      458     404
       9       18   262143      378      160        5      345      415      160     319
       9       18   262143      422      289        5      335       37      483     454
       9       18   262143      454       81        5      187      233      423     334
       9       18   262143       66      437        6      120      452      189     377
       9       18   262143      322      181        6      376      452      189     377
       9       18   262143       71      314        7      242       75       57     114
       9       18   262143      226      277        7      322      350      203     405
       9       18   262143      327       58        7      498       75       57     114
       9       18   262143      482       21        7       66      350      203     405
       9       18   262143        5      139        8      166      157      395     278
       9       18   262143      261      395        8      422      157      395     278
      10       20  1048575      104      791        0      593      485      163     326
      10       20  1048575      355      232        0      387      990      693     363
      10       20  1048575      405      705        0      921      500      172     344
      10       20  1048575      419      799        0      468      941      358     715
      10       20  1048575      492      979        0      789      165       99     198
      10       20  1048575      616      279        0       81      485      163     326
      10       20  1048575      867      744        0      899      990      693     363
      10       20  1048575      917      193        0      409      500      172     344
      10       20  1048575      931      287        0      980      941      358     715
      10       20  1048575     1004      467        0      277      165       99     198
      10       20  1048575       49       86        2     1014      961      322     643
      10       20  1048575      379      809        2      895      500      172     344
      10       20  1048575      561      598        2      502      961      322     643
      10       20  1048575      891      297        2      383      500      172     344
      10       20  1048575      159      741        3      529      624      465     929
      10       20  1048575      295     1005        3      718      407      141     282
      10       20  1048575      351      474        3      277      836      317     633
      10       20  1048575      473      238        3      404       59     1001     978
      10       20  1048575      671      229        3       17      624      465     929
      10       20  1048575      807      493        3      206      407      141     282
      10       20  1048575      863      986        3      789      836      317     633
      10       20  1048575      985      750        3      916       59     1001     978
      10       20  1048575      142      272        4      778      380      212     424
      10       20  1048575      654      784        4      266      380      212     424
      10       20  1048575      346      923        5      713      367      805     586
      10       20  1048575      858      411        5      201      367      805     586
      10       20  1048575      376       71        7      949      449      191     382
      10       20  1048575      888      583        7      437      449      191     382
      10       20  1048575      186       44        8      718      484      860     696
      10       20  1048575      698      556        8      206      484      860     696
      10       20  1048575        8       80        9      176       72       56     112
      10       20  1048575      295      542        9      575      280      776     528
      10       20  1048575      393     1012        9      805      348      820     616
      10       20  1048575      520      592        9      688       72       56     112
      10       20  1048575      807       30        9       63      280      776     528
      10       20  1048575      905      500        9      293      348      820     616
      11       22  4194303      242     1502        0     1447     1093     1084     121
      11       22  4194303      502      101        0      958     1590     1517     987
      11       22  4194303      597     1352        0      429     1686      627    1253
      11       22  4194303      787      448        0     1434      631     1581    1114
      11       22  4194303      860      583        0     2041      865     1759    1470
      11       22  4194303      865     1328        0      622      241     1967    1886
      11       22  4194303      910      349        0     1636     1188      925    1849
      11       22  4194303     1004      806        0      707     1303     1266     485
      11       22  4194303     1266      478        0      423     1093     1084     121
      11       22  4194303     1526     1125        0     1982     1590     1517     987
      11       22  4194303     1621      328        0     1453     1686      627    1253
      11       22  4194303     1811     1472        0      410      631     1581    1114
      11       22  4194303     1884     1607        0     1017      865     1759    1470
      11       22  4194303     1889      304        0     1646      241     1967    1886
      11       22  4194303     1934     1373        0      612     1188      925    1849
      11       22  4194303     2028     1830        0     1731     1303     1266     485
      11       22  4194303      194      185        3     1060      666     1654    1260
      11       22  4194303     1218     1209        3       36      666     1654    1260
      11       22  4194303      608      684        5      206     1644      549    1097
      11       22  4194303      707      447        5     1435      728     1608    1168
      11       22  4194303      922      866        5       76      810     1766    1484
      11       22  4194303     1632     1708        5     1230     1644      549    1097
      11       22  4194303     1731     1471        5      411      728     1608    1168
      11       22  4194303     1946     1890        5     1100      810     1766    1484
      11       22  4194303      472      491        7     1237     1273      938    1875
      11       22  4194303      651     1757        7     1278      371      209     418
      11       22  4194303     1496     1515        7      213     1273      938    1875
      11       22  4194303     1675      733        7      254      371      209     418
      11       22  4194303      280     1354        8     1096      816      272     544
      11       22  4194303     1304      330        8       72      816      272     544
      11       22  4194303      110     1187        9      731      337      207     414
      11       22  4194303      393      829        9      360     2015     1354     661
      11       22  4194303     1134      163        9     1755      337      207     414
      11       22  4194303     1417     1853        9     1384     2015     1354     661
      11       22  4194303       43     1668       10     1053     1002     1702    1356
      11       22  4194303      524      217       10     1493      965      323     646
      11       22  4194303      525     1255       10     1370      689     1647    1246
      11       22  4194303     1067      644       10       29     1002     1702    1356
      11       22  4194303     1548     1241       10      469      965      323     646
      11       22  4194303     1549      231       10      346      689     1647    1246
      12       24 16777215       36     1659        0     2653      565     3603    3110
      12       24 16777215      718     1879        0     4074     3298     1119    2237
      12       24 16777215     1006     1272        0     2603     2489     1898    3795
      12       24 16777215     1077      644        0       11     3016     2375     655
      12       24 16777215     1348     1283        0     3701     1741     3515    2934
      12       24 16777215     1504     1330        0     2921     2421     1838    3675
      12       24 16777215     1644      291        0     1472     3730     2673    1251
      12       24 16777215     1996     2982        0      130     1718     3474    2852
      12       24 16777215     2084     3707        0      605      565     3603    3110
      12       24 16777215     2766     3927        0     2026     3298     1119    2237
      12       24 16777215     3054     3320        0      555     2489     1898    3795
      12       24 16777215     3125     2692        0     2059     3016     2375     655
      12       24 16777215     3396     3331        0     1653     1741     3515    2934
      12       24 16777215     3552     3378        0      873     2421     1838    3675
      12       24 16777215     3692     2339        0     3520     3730     2673    1251
      12       24 16777215     4044      934        0     2178     1718     3474    2852
      12       24 16777215       88     3974        2     1469     1177     3191    2286
      12       24 16777215      219     2582        2      558      147      113     226
      12       24 16777215      894      606        2     2167     1269     3155    2214
      12       24 16777215      923     1351        2     3672      577     3647    3198
      12       24 16777215      976     3020        2     3931     2931     2350     605
      12       24 16777215     1643     2804        2     1909     3332     2819    1543
      12       24 16777215     2136     1926        2     3517     1177     3191    2286
      12       24 16777215     2267      534        2     2606      147      113     226
      12       24 16777215     2942     2654        2      119     1269     3155    2214
      12       24 16777215     2971     3399        2     1624      577     3647    3198
      12       24 16777215     3024      972        2     1883     2931     2350     605
      12       24 16777215     3691      756        2     3957     3332     2819    1543
      12       24 16777215      524     2595        3     1661      909      379     758
      12       24 16777215      741     3117        3     2029     2310     1795    3589
      12       24 16777215     2572      547        3     3709      909      379     758
      12       24 16777215     2789     1069        3     4077     2310     1795    3589
      12       24 16777215      186     3363        4     2604     2188     2171     247
      12       24 16777215     2234     1315        4      556     2188     2171     247
      12       24 16777215       98     1417        5     1078     3090     3057    2019
      12       24 16777215     2146     3465        5     3126     3090     3057    2019
      12       24 16777215     1185     3313        6     2559      606      458     916
      12       24 16777215     3233     1265        6      511      606      458     916
      12       24 16777215      415     1571        8     1249      826      278     556
      12       24 16777215      621     1388        8     1732     1063     3101    2106
      12       24 16777215      961     1803        8     3610     2393     2248     401
      12       24 16777215     2463     3619        8     3297      826      278     556
      12       24 16777215     2669     3436        8     3780     1063     3101    2106
      12       24 16777215     3009     3851        8     1562     2393     2248     401
      12       24 16777215     1683     3784       10      908     2809     2472     849
      12       24 16777215     3731     1736       10     2956     2809     2472     849
      12       24 16777215      236     1515       11     2543     1283      769    1538
      12       24 16777215     1761     1368       11      890     2713     2440     785
      12       24 16777215     2010     3663       11     1589     3619     2590    1085
      12       24 16777215     2284     3563       11      495     1283      769    1538
      12       24 16777215     3809     3416       11     2938     2713     2440     785
      12       24 16777215     4058     1615       11     3637     3619     2590    1085
Incomplete 13 and 14:
      13       26 67108863     1136     2420        0      893     7949     5380    2569
      13       26 67108863     6803     5330        0     4325     5676     4635    1079
      13       26 67108863     7110      241        0     2791     3869     1291    2582
      13       26 67108863     1138     1263        8      433      319     7957    7722
      13       26 67108863     6564     6480        8     6330     7944     5383    2575
      13       26 67108863      523     1117       10     1651     5222     3107    6213
      13       26 67108863     1949     6961       11      413     5630     4949    1707
      13       26 67108863      702     7737       12     7394     6618     2231    4461
      14       28   2^28-1    12651    13193        2     5516     5149     3083    6166
      14       28   2^28-1    13143     7060        2    12041    15180    10555    4727

XorSARps:
    Word       State     Period        A          B          C         D2         D1          X          Y
     
2          4         15          1          2          0          3          3          2          1
     
2          4         15          3          1          0          3          1          3          2
     
2          4         15          1          1          1          3          3          2          1
     
2          4         15          1          3          1          0          2          1          3
     
2          4         15          3          0          1          0          0          0          0
     
2          4         15          3          2          1          3          1          3          2
     
3          6         63          3          2          0          6          2          6          4
     
3          6         63          5          3          0          0          6          5          3
     
3          6         63          3          6          1          0          6          3          5
     
3          6         63          3          0          2          0          0          0          0
     
3          6         63          3          6          2          0          6          5          3
     
4          8        255          3          3          0         10         12          5          9
     
4          8        255         13          3          0          5          5          3          6
     
4          8        255          9         12          1         10          2         14         12
     
4          8        255          5         10          2          1          1         15         14
     
4          8        255          7          8          2          4         10          9          3
     
4          8        255          7         13          2          5          3          1          2
     
4          8        255         13          2          2          9          1         15         14
     
5         10       1023          1         27          0         21          9          7         14
     
5         10       1023          7         29          3         21          3          1          2
     
5         10       1023         19         11          4          0         30         11         21
     
6         12       4095         21         38          0         10         26         54         44
     
6         12       4095         43         17          0         15         17         15         30
     
6         12       4095         49         37          0         16         46         27         53
     
6         12       4095         49         48          0         16         16         48         32
     
6         12       4095         59         49          0         15          1         63         62
     
6         12       4095         13         56          2         12         58         41         19
     
6         12       4095         19         51          2         50          6          2          4
     
6         12       4095         31         40          4          7         37         30         59
     
6         12       4095          7         60          5         27         41         26         51
     
6         12       4095         25         18          5          7         31         53         42
     
6         12       4095         37          3          5         39         27          9         18
     
6         12       4095         43         39          5         11         29         11         22
     
7         14      16383        101         66          2         84         52        108         88
     
7         14      16383        123         41          4         68        114         47         93
     
7         14      16383         43         71          5         16         78         59        117
     
7         14      16383         85         52          5         75         95         32        127
     
7         14      16383        121         62          5         40        102         35         69
     
7         14      16383         15        121          6         24          8        120        112
     
7         14      16383         65         37          6         79        111         90         53
     
7         14      16383         75        126          6          8        102         93         59
     
8         16      65535        115          0          0          0          0          0          0
     
8         16      65535        209        105          0          6        216        183        111
     
8         16      65535        217         64          1         96         96         32         64
     
8         16      65535        209         88          2        112        112        208        160
     
8         16      65535         39         32          4        120        198         67        133
     
8         16      65535        147        248          4        111        197        188        121
     
8         16      65535        215        145          4        164        250        169         83
     
8         16      65535        189        100          5        143        195        190        125
     
8         16      65535         39        223          7        131         57         23         46
     
8         16      65535        155        199          7         43         77         59        118
     
8         16      65535        255         45          7        239        209        176         97
     
9         18     262143          1         85          0        255        255         85        170
     
9         18     262143         77        223          0         12        442        361        211
     
9         18     262143        133        261          0        290        308        275         39
     
9         18     262143        271        286          0        410        198         66        132
     
9         18     262143        425        272          0         48        176        400        288
     
9         18     262143        451        461          0        450        264        263         15
     
9         18     262143         15          9          3        208        430        357        203
     
9         18     262143        455         69          3         15        377        296         81
     
9         18     262143        421        399          4        102        464        335        159
     
9         18     262143        473        246          6        496        112        464        416
     
9         18     262143        453        162          7        215        467        334        157
     
9         18     262143         95          9          8        461        147        113        226
     
10         20    1048575        643         41          0        334        980        691        359
     
10         20    1048575        691       1013          4        127        249         87        174
     
10         20    1048575         65        492          5        526        624        559         95
     
10         20    1048575        365        928          5        609         57         23         46
     
10         20    1048575        399        747          5        719        705        576        129
     
10         20    1048575          5        361          7        850        804        739        455
     
10         20    1048575        117        862          7        291        935        360        719
     
10         20    1048575        513        169          7        451        955        662        301
     
10         20    1048575        581        586          7        366        342        818        612
     
10         20    1048575        671        596          8        605        387        129        258
     
11         22    4194303         15       1618          0        702        666       1654       1260
     
11         22    4194303       1035       1516          0        932        364       1828       1608
     
11         22    4194303        675        122          3       1011       1645        550       1099
     
11         22    4194303        439        749          5       1064       1254       1117        187
     
11         22    4194303        947        880          5       1028       1490        847       1693
     
11         22    4194303        617        128          6        853       1009       1711       1374
     
11         22    4194303        655       1659          7        403        577       1599       1150
     
11         22    4194303       1001        299          9       1087       1511       1186        325
     
11         22    4194303        333       1493         10       1798       2012        693       1385
     
11         22    4194303       1327       1765         10       1524        844       1732       1416
     
11         22    4194303       1507       1504         10         96        928        352        704
     
12         24   16777215       3629       2690          0       2230        814        282        564
     
12         24   16777215       3925        913          2       1176       2614       1555       3109
     
12         24   16777215       1287       2693          3       3925        451       3905       3714
     
12         24   16777215       1409       1566          3       1426       2640       1585       3169
     
12         24   16777215       1453       2925          3       2222       2324       1805       3609
     
12         24   16777215        339       1062          4        595       1277        939       1878
     
12         24   16777215       3895        769          4       3958       1218        958       1916
     
12         24   16777215       3925        253          4        972       2714       2441        787
     
12         24   16777215       3583        867          5       1131        393        135        270
     
12         24   16777215       2213       3566          8       1690       3820       2651       1207
     
12         24   16777215       3427       2225          8       1879       1409        895       1790
     
12         24   16777215        105       1363         10       3792        400       3952       3808
     
12         24   16777215       3301       1540         10       3485       1429        883       1766

// Rotation functions for non-intrinsic bit widths (2-bit to 31-bit, unoptimized code, since these functions may be looped to fill a fast look-up array)
static inline uint32_t rarx(int32_t x, int w) {
   
return ((uint32_t)((-(x & (1 << (w - 1))) | x) / 2 ^ (x << (w - 1))) & ((1 << w) - 1)) >> (int)(x == ((1 << w) - 1)); }

static inline uint32_t rolx(uint32_t x, int k, int w) {
   
return ((x << k) | (x >> (w - k))) & ((1 << w) - 1); }

Cerian Knight

unread,
Dec 30, 2018, 12:32:35 AM12/30/18
to xorsar...@googlegroups.com
Original 8-bit output / 16-bit state C++ code post: Click Here

Tiny GCC -O3 assembly language dump of 128-bit state, 64-bit word/output C++ code with fictitious ABC constants and D=0.
Using updated rar64 function to remove use of cmove asm instruction, for better support of MSVC, etc., and now using dynamic constants for speed/smaller code.
To reach its greatest potential, the rar8/16/32/64 functions would need to be implemented in hardware and/or as an ASM primitive.
xorSAR128pp2D():
 mov rcx
, QWORD PTR s[rip+8]
 mov rax
, QWORD PTR s[rip]
 mov rdx
, rcx
 mov rsi
, rcx
 add rax
, rcx
 add rax
, QWORD PTR A[rip]     //A constant (dynamic for speed)
 shr rdx
, 63
 sal rsi
, 63
 add rdx
, rcx
 sar rdx
 xor rdx
, rsi
 cmp rcx
, -1
 sete cl
 shr rdx
, cl
 mov QWORD PTR s
[rip], rdx
 mov rdx
, QWORD PTR B[rip]     //B constant (dynamic for speed)
 xor rdx
, rax
 rol rdx
, 13                   //C constant
 mov QWORD PTR s
[rip+8], rdx
 ret
s
:
 
.zero 16
B
:
 
.quad 5949946252051827096
A
:
 
.quad 4067921595744811285
Reply all
Reply to author
Forward
0 new messages