From 7b4323e1e0ec90fe818df551ee6dd51db80e8de5 Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Tue, 8 Feb 2022 18:27:53 -0800 Subject: [PATCH] Add rotr --- include/fmt/format-inl.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index eba27f46..d2c68548 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -816,6 +816,16 @@ struct uint128_wrapper { } }; +// Compilers should be able to optimize this into the ror instruction. +inline std::uint32_t rotr(uint32_t n, uint32_t r) noexcept { + r &= 31; + return (n >> r) | (n << (32 - r)); +} +inline std::uint64_t rotr(uint64_t n, uint32_t r) noexcept { + r &= 63; + return (n >> r) | (n << (64 - r)); +} + // Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox. namespace dragonbox { // Computes 128-bit result of multiplication of two 64-bit unsigned integers.