Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/xorwow-mix-20261109/README.md # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / evidence / xorwow-mix-20261109 / README.md` 115 lines · 8572 bytes Raw Blame History Rendered 1 # XORWOW: what the page-5 listing tunes, and an output mix (L441) 2 3 Host only, 2026-11-09, Spark `spark-b87b` (aarch64). No GPU, no libcurand call. 4 5 ## The listing 6 7 Marsaglia, "Xorshift RNGs", Journal of Statistical Software 8(14), 2003, page 5. CUDA 13.0.3 8 `curand()` is the same step (earlier check on CUDApp branch `feat/fft-rng` at ``f564d78b``, 9 `docs/LIBRARIES.md` line 18). State words x, y, z, w, v and the Weyl counter d, 32 bits each: 10 11 t = x ^ (x >> 2); x = y; y = z; z = w; w = v; 12 v = (v ^ (v << 4)) ^ (t ^ (t << 1)); 13 return (d += 362437) + v; 14 15 ## What it tunes (Wolfram receipts) 16 17 1. The shift triple (a, b, c) = (2, 1, 4). The 160 by 160 GF(2) matrix of the xorshift part has a 18 primitive characteristic polynomial, so the five words run through all 2^160 - 1 nonzero states. 19 Neighbouring triples do not: (2, 1, 5), (1, 1, 1) and (1, 3, 10) are not primitive. 20 2. The Weyl increment 362437 is odd, so d runs through all 2^32 values. 21 3. 2^160 - 1 is odd, so gcd(2^160 - 1, 2^32) = 1 and the combined period is 22 (2^160 - 1) * 2^32 = 2^192 - 2^32. 23 24 Query 1 (WolframLanguageEvaluator, 2026-11-09): 25 26 ``` 27 n=32; id=IdentityMatrix[n]; z0=ConstantArray[0,{n,n}]; L[k_]:=Table[If[j==i-k,1,0],{i,0,n-1},{j,0,n-1}]; R[k_]:=Table[If[j==i+k,1,0],{i,0,n-1},{j,0,n-1}]; T[a_,b_,c_]:=Mod[ArrayFlatten[{{z0,id,z0,z0,z0},{z0,z0,id,z0,z0},{z0,z0,z0,id,z0},{z0,z0,z0,z0,id},{Mod[(id+L[b]).(id+R[a]),2],z0,z0,z0,Mod[id+L[c],2]}}],2]; cp[a_,b_,c_]:=PolynomialMod[CharacteristicPolynomial[T[a,b,c],xx],2]; N0=2^160-1; qs=FactorInteger[N0][[All,1]]; pw[e_,p_]:=Fold[PolynomialMod[If[#2==1,xx*#1^2,#1^2],{p,2}]&,1,IntegerDigits[e,2]]; prim[p_]:=Exponent[p,xx]==160&&IrreduciblePolynomialQ[p,Modulus->2]&&pw[N0,p]===1&&AllTrue[qs,pw[N0/#,p]=!=1&];res=Table[{abc,prim[cp@@abc]},{abc,{{2,1,4},{2,1,5},{1,1,1},{1,3,10}}}];{FactorInteger[N0],res,Mod[362437,2],(2^160-1)*2^32==2^192-2^32,GCD[2^160-1,2^32]} 28 ``` 29 30 Result: 31 32 ``` 33 {{{3,1},{5,2},{11,1},{17,1},{31,1},{41,1},{257,1},{61681,1},{65537,1},{414721,1},{`4278255361`,1},{`44479210368001`,1}}, 34 {{{2,1,4},True},{{2,1,5},False},{{1,1,1},False},{{1,3,10},False}}, 1, True, 1} 35 ``` 36 37 (The kernel printed a lint warning that the single-letter names L, R, T were "undefined"; the 38 values are computed. Query 3 below rebuilds the same matrix with longer names and no warning.) 39 40 ## The named metric 41 42 Linear complexity of each output bit, by Berlekamp-Massey over GF(2), over the first N = 1000 43 outputs from the published state `123456789`, `362436069`, `521288629`, `88675123`, `5783321`, `6615241`. 44 An unpredictable bit scores about N/2 = 500. A bit fails when it scores below 480. The score for 45 the whole generator is the number of failing bits out of 32; lower is better, 0 is ideal. 46 47 The low bits are weak by construction. Bit 0 of `d + v` is bit 0 of d XOR bit 0 of v: no carry 48 reaches it. Bit 0 of v is a 160-stage linear recurrence and bit 0 of d alternates, so bit 0 is a 49 linear recurrence of length 162. Bit 1 gets one carry, v0 AND d0, and has length 323. The carries 50 reach every higher bit through d, which is why bits 2 to 31 already score about 500. 51 52 Query 2 (the scores, N = 1000), result: 53 54 | Output | bit 0 | bit 1 | bits 2..31 | failing bits | 55 |---|---|---|---|---| 56 | raw XORWOW `d + v` | 162 | 323 | 499..502 | 2 | 57 | fold `o ^ (o >> 16)` | 500 | 501 | 499..502 | 0 | 58 | murmur3 fmix32 of `o` | 500 | 500 | 497..503 | 0 | 59 | Wolfram `RandomInteger` words | 500 | 501 | 497..501 | 0 | 60 61 ``` 62 msk=2^32-1; stp[{xa_,ya_,za_,wa_,va_,da_}]:=Module[{t=BitXor[xa,BitShiftRight[xa,2]],nv,nd},nv=BitAnd[BitXor[BitXor[va,BitShiftLeft[va,4]],BitXor[t,BitShiftLeft[t,1]]],msk];nd=Mod[da+362437,2^32];{ya,za,wa,va,nv,nd}]; num=1000; sts=Rest[NestList[stp,{`123456789`,`362436069`,`521288629`,`88675123`,`5783321`,`6615241`},num]]; raw=Mod[#[[5]]+#[[6]],2^32]&/@sts; fold[o_]:=BitXor[o,BitShiftRight[o,16]]; fmix[h0_]:=Module[{h=h0},h=BitXor[h,BitShiftRight[h,16]];h=Mod[h*16^^`85ebca6b`,2^32];h=BitXor[h,BitShiftRight[h,13]];h=Mod[h*16^^`c2b2ae35`,2^32];BitXor[h,BitShiftRight[h,16]]]; bm[s_]:=Module[{nn=Length[s],c,b,lc=0,m=-1,dd,tt,sh},c=ConstantArray[0,nn+1];c[[1]]=1;b=c;Do[dd=Mod[c[[1;;lc+1]].Reverse[s[[i-lc+1;;i+1]]],2];If[dd==1,tt=c;sh=i-m;c=Mod[c+Join[ConstantArray[0,sh],b[[1;;nn+1-sh]]],2];If[2 lc<=i,lc=i+1-lc;m=i;b=tt]],{i,0,nn-1}];lc]; lcs[out_]:=Table[bm[BitAnd[BitShiftRight[out,k],1]],{k,0,31}]; lr=lcs[raw]; lf=lcs[fold/@raw]; lm=lcs[fmix/@raw]; rnd=lcs[RandomInteger[msk,num]]; {Take[raw,8], lr, lf, lm, rnd, Count[#,v_/;v<480]&/@{lr,lf,lm,rnd}} 63 ``` 64 65 The first eight raw outputs it printed are `246875399` `3690007200` `1264581005` `3906711041` `1866187943` 66 `2481925219` `2464530826` `1604040631`, the same eight as the earlier C and Wolfram listing check. The 67 full 32-score rows for raw and fold are `expected.txt` in this folder. Failing-bit counts: 68 `{2, 0, 0, 0}`. 69 70 Query 3 proves the two low-bit scores exactly: the Berlekamp-Massey minimal polynomial of bit 0 71 equals p(x) (x + 1)^2 and that of bit 1 equals p(x)^2 (x + 1)^3, where p is the degree-160 72 characteristic polynomial of the (2, 1, 4) matrix. Result `{162, 323, True, True, 160}`. 73 74 ``` 75 n=32; id=IdentityMatrix[n]; z0=ConstantArray[0,{n,n}]; shl[k_]:=Table[If[j==i-k,1,0],{i,0,n-1},{j,0,n-1}]; shr[k_]:=Table[If[j==i+k,1,0],{i,0,n-1},{j,0,n-1}]; tm=Mod[ArrayFlatten[{{z0,id,z0,z0,z0},{z0,z0,id,z0,z0},{z0,z0,z0,id,z0},{z0,z0,z0,z0,id},{Mod[(id+shl[1]).(id+shr[2]),2],z0,z0,z0,Mod[id+shl[4],2]}}],2]; p=PolynomialMod[CharacteristicPolynomial[tm,xx],2]; msk=2^32-1; stp[{xa_,ya_,za_,wa_,va_,da_}]:=Module[{t=BitXor[xa,BitShiftRight[xa,2]],nv},nv=BitAnd[BitXor[BitXor[va,BitShiftLeft[va,4]],BitXor[t,BitShiftLeft[t,1]]],msk];{ya,za,wa,va,nv,Mod[da+362437,2^32]}]; sts=Rest[NestList[stp,{`123456789`,`362436069`,`521288629`,`88675123`,`5783321`,`6615241`},1000]]; raw=Mod[#[[5]]+#[[6]],2^32]&/@sts; bmc[s_]:=Module[{nn=Length[s],c,b,lc=0,m=-1,dd,tt,sh},c=ConstantArray[0,nn+1];c[[1]]=1;b=c;Do[dd=Mod[c[[1;;lc+1]].Reverse[s[[i-lc+1;;i+1]]],2];If[dd==1,tt=c;sh=i-m;c=Mod[c+Join[ConstantArray[0,sh],b[[1;;nn+1-sh]]],2];If[2 lc<=i,lc=i+1-lc;m=i;b=tt]],{i,0,nn-1}];{lc,c[[1;;lc+1]]}]; minp[{lc_,c_}]:=Sum[c[[k+1]] xx^(lc-k),{k,0,lc}]; r0=bmc[BitAnd[raw,1]]; r1=bmc[BitAnd[BitShiftRight[raw,1],1]]; {r0[[1]],r1[[1]],PolynomialMod[minp[r0]-p*(xx+1)^2,2]===0,PolynomialMod[minp[r1]-p^2*(xx+1)^3,2]===0, Exponent[p,xx]} 76 ``` 77 78 Query 4 (N = 3000, bits 0..7): raw `{162, 323, 1500, 1501, 1499, 1500, 1501, 1501}`, fold 79 `{1501, 1501, 1501, 1499, 1501, 1500, 1501, 1500}`. Bits 0 and 1 do not grow with N: 162 and 323 80 are their full linear complexity. The fold's 32 by 32 GF(2) matrix has determinant 1 mod 2 81 (`Det[foldM, Modulus->2]` -> 1), so the fold is a bijection on 32-bit words: it keeps the period 82 and the uniform distribution of each output word. 83 84 Query 4 is query 2 with `num=3000`, `lcs` over bits `{k,0,7}`, only `raw` and `fold`, and 85 `foldM=Table[If[j==i||j==i+16,1,0],{i,0,31},{j,0,31}]`; it returned `{lr, lf, Det[foldM,Modulus->2]}`. 86 87 ## Answer 88 89 The fold `o ^ (o >> 16)` wins on the named metric: 0 failing bits against 2 for raw XORWOW, at the 90 cost of one shift and one XOR per output. murmur3 fmix32 also scores 0 but costs two more 91 shift-XOR pairs and two multiplies, so the fold is the cheaper winner. Scope of the claim: this 92 one metric, this seed, N = 1000 and 3000. It is not a TestU01 BigCrush result. The folded 93 generator no longer reproduces 94 `curand()`, so it can only be an opt-in variant; the curand-matching step stays unmixed. 95 96 ## Omega check 97 98 `omega/libraries/xorwow_mix.om` computes the same 64 scores in Omega and exits 0 only when raw 99 bit 0 is 162, raw bit 1 is 323, raw has exactly 2 failing bits and the fold has 0. 100 `run.sh` builds it with the pinned compiler, compares stdout byte for byte with `expected.txt` 101 (the Wolfram scores) and builds three mutants that must fail: 102 103 | Mutant | Change | Required exit | 104 |---|---|---| 105 | weyl | increment 362438 | 10 (first eight outputs) | 106 | nofold | fold returns `o` | 30 (fold has failing bits) | 107 | bmlen | Berlekamp-Massey never grows its length | 20 (raw bit 0 not 162) | 108 109 Receipt `run.log` (source commit ``7863601676150a18241e39d75e364f9805270f1c``): omc 110 ``2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f``, omega-mv ``e5b32567`` rebuilt 111 from seed by `sh seed/omega-from-seed.sh` (RC=0), the pin in `AGENTS.md`. Binary sha256 112 ``57a7667907f491e1d576a672b205f7937734b035b717a0550f468c11bf4cc2cc``. All rows PASS, exit 0. 113 With a different compiler (omc ``3ad9f10f`…`) `run.sh` prints NOT_RUN and exits 3. Compiled 114 directly by that omc (omega-mv ``f4df8239``) the program is byte-identical (same binary sha256) 115 and its stdout equals `expected.txt`.