Efficient bit rotate functions: ror, rol...what is the official way for Julia v1?

Hi,
I found this https://github.com/JuliaLang/julia/issues/11592 but I can not understand what should I do for a UInt64 or any other arbitrary 0b....
Am I missing something in the doc?

Thanks you

Define these:

ror(x::UInt64, k::Int) = (x >>> (0x3f & k)) | (x << (0x3f & -k))
rol(x::UInt64, k::Int) = (x >>> (0x3f & -k)) | (x << (0x3f & k))

Verification:

julia> code_native(ror, (UInt64, Int); syntax = :intel)
        ...
        ror     rax, cl
        ...

julia> code_native(rol, (UInt64, Int); syntax = :intel)
        ...
        rol     rax, cl
        ...
4 Likes

I rather think we should have these in Base for the fixed size integer types. The definitions are non-obvious enough that people shouldn’t have to define them for themselves. If someone wants to make a PR this is a good intro one!

6 Likes