DeveMazeGeneratorCore/Generators/Helpers/XorShiftRandom.cs
/// <summary>
/// A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation
/// thus providing a nice speedup. The loop is also partially unrolled to allow out-of-order-execution,
/// this results in about a x3 speedup on an Intel Core i7 920 (Bloomfield). Thus performance may vary 
/// wildly on different CPUs depending on the number of execution units available.
/// 
/// Another significant speedup is obtained by setting the 4 bytes by indexing pDWord (e.g. pDWord[i++]=_w)
/// instead of dereferencing it (e.g. *pDWord++=_w).
/// 
/// Note that this routine requires the unsafe compilation flag to be specified and so is commented out by default.
/// </summary>
/// <remarks>The byte array length must be divisible by 8.</remarks>
/// <param name="buffer"></param>
A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation
thus providing a nice speedup. The loop is also partially unrolled to allow out-of-order-execution,
this results in about a x3 speedup on an Intel Core i7 920 (Bloomfield). Thus performance may vary
wildly on different CPUs depending on the number of execution units available.

Another significant speedup is obtained by setting the 4 bytes by indexing pDWord
instead of dereferencing it .

Note that this routine requires the unsafe compilation flag to be specified and so is commented out by default.
A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation thus providing a nice speedup . The loop is also partially unrolled to allow out - of - order - execution this results in about a x3 speedup on an Intel Core i7 920 ( Bloomfield ) . Thus performance may vary wildly on different CPUs depending on the number of execution units available . Another significant speedup is obtained by setting the 4 bytes by indexing pDWord instead of dereferencing it . Note that this routine requires the unsafe compilation flag to be specified and so is commented out by default .
public unsafe void NextBytes8(byte[] buffer)
        {
            if(buffer.Length % 8 != 0) {
                throw new ArgumentException("Buffer length must be divisible by 8", "buffer");
            }
            uint x=_x, y=_y, z=_z, w=_w;
            fixed(byte* pByte0 = buffer)
            {
                uint* pDWord = (uint*)pByte0;
                for(int i=0, len = buffer.Length>>2; i<len; i+=2)
                {
                    uint t = (x^(x<<11));
                    x=y; y=z; z=w;
                    pDWord[i] = w = (w^(w>>19))^(t^(t>>8));
                    t = (x^(x<<11));
                    x=y; y=z; z=w;
                    pDWord[i+1] = w = (w^(w>>19))^(t^(t>>8));
                }
            }
            _x=x; _y=y; _z=z; _w=w;
        }
public unsafe void NextBytes8 ( byte [ ] buffer ) { if ( buffer . Length % 8 != 0 ) { throw new ArgumentException ( " " , " " ) ; } uint x = _x , y = _y , z = _z , w = _w ; fixed ( byte * pByte0 = buffer ) { uint * pDWord = ( uint * ) pByte0 ; for ( int i = 0 , len = buffer . Length >> 2 ; i < len ; i += 2 ) { uint t = ( x ^ ( x << 11 ) ) ; x = y ; y = z ; z = w ; pDWord [ i ] = w = ( w ^ ( w >> 19 ) ) ^ ( t ^ ( t >> 8 ) ) ; t = ( x ^ ( x << 11 ) ) ; x = y ; y = z ; z = w ; pDWord [ i + 1 ] = w = ( w ^ ( w >> 19 ) ) ^ ( t ^ ( t >> 8 ) ) ; } } _x = x ; _y = y ; _z = z ; _w = w ; }
A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation
thus providing a nice speedup.
A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation thus providing a nice speedup .
buffer
byte[]
None
remarks
The byte array length must be divisible by 8.
The byte array length must be divisible by 8 .