Skip to content

Instantly share code, notes, and snippets.

@jfalcou

jfalcou/rol.cpp Secret

Created May 17, 2016 10:12
Show Gist options
  • Save jfalcou/20a51bf62f0cef11deae0e471fe7902a to your computer and use it in GitHub Desktop.
Save jfalcou/20a51bf62f0cef11deae0e471fe7902a to your computer and use it in GitHub Desktop.
rol implementation that trigger use of x86 ROL intrinsic
#include <cstdint>
std::uint64_t rotl32c (std::uint64_t x, std::uint64_t n)
{
return (x<<n) | (x>>(-n&63));
}
std::uint32_t rotl32c (std::uint32_t x, std::uint32_t n)
{
return (x<<n) | (x>>(-n&31));
}
std::uint16_t rotl32c (std::uint16_t x, std::uint16_t n)
{
return (x<<n) | (x>>(-n&15));
}
std::uint8_t rotl32c (std::uint8_t x, std::uint8_t n)
{
return (x<<n) | (x>>(-n&7));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment