Git Product home page Git Product logo

Comments (11)

simonbyrne avatar simonbyrne commented on September 15, 2024

This seems to work as desired on 0.5 (with -O3), but not on 0.4

function rotr(x,y)
    s = sizeof(x) << 3
    (x >> (y % s)) | (x << (-y % s))
end

from randomnumbers.jl.

sunoru avatar sunoru commented on September 15, 2024

Thanks, Simon. The former one seems very nice, I'll use this.

BTW there's a typo in the codes that it should be %4 = sub i64 63, %1

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

Why would it be 63, not 64?

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

I would suggest the latter one: the generality is well worth it, and hopefully 0.5 should be released by the time we're performance tuning. llvmcall is usually the last resort sort of thing.

from randomnumbers.jl.

sunoru avatar sunoru commented on September 15, 2024

Oh I just found myself wrong.

Okay, it's reasonable to take the second function.

from randomnumbers.jl.

sunoru avatar sunoru commented on September 15, 2024

Yesterday did you mean that I should just write

@inline function pcg_rotr(x::UIntTypes, y::UIntTypes)
    s = sizeof(x) << 3
    (x >> (y % s)) | (x << (-y % s))
end

instead of the current @eval form?

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

Yes, exactly: @eval gets you nothing in this case (each combination of concrete UInt types will still be JIT-ed).

You could even do this for a lot of the other functions, as it seems like the constants can mostly be computed (and so will be evaluated at compile time).

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

e.g. for XSH RR, you could include in the function

    s = sizeof(state) << 3
    t = trailing_zeros(s)-1 # log2(s)-1
    p1 = (s>>1 + t)>>1
    p2 = s>>1 - t
    p3 = s-t

which the JIT is smart enough to evaluate as constants.

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

Though for 128 bits, this gives a p1 as 35, not 29 as in your code: where did you get the constants from?

from randomnumbers.jl.

sunoru avatar sunoru commented on September 15, 2024

I copied the constants in the PCG sources. http://www.pcg-random.org/download.html

from randomnumbers.jl.

simonbyrne avatar simonbyrne commented on September 15, 2024

Ah, I see. I opened an issue here:
imneme/pcg-c-basic#7

I guess we see what the author says.

from randomnumbers.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.