Skip to content

Variable assignments in System.Random's xorshiro256ss' NextUInt64() can be removed #95116

Answered by huoyaoyuan
Xyncgas asked this question in General
Discussion options

You must be logged in to vote

Simple benchmark does not support this:

using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Program
{
    static void Main()
    {
        BenchmarkRunner.Run<Program>();
    }

    private ulong _s0 = 123, _s1 = 456, _s2 = 789, _s3 = 1000;

    [Benchmark(Baseline = true)]
    public ulong NextUInt64()
    {
        ulong s0 = _s0, s1 = _s1, s2 = _s2, s3 = _s3;

        ulong result = BitOperations.RotateLeft(s1 * 5, 7) * 9;
        ulong t = s1 << 17;

        s2 ^= s0;
        s3 ^= s1;
        s1 ^= s2;
        s0 ^= s3;

        s2 ^= t;
        s3 = BitOperations.RotateLeft(s3, 45);

        _s0 = s0;
        _s1 = s1;
        _s2 = s2;

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Xyncgas
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@hez2010
Comment options

@Xyncgas
Comment options

@Xyncgas
Comment options

@huoyaoyuan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants