From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Simplify metaprogramming in <random>
Date: Sat, 10 Oct 2020 11:44:31 +0100 [thread overview]
Message-ID: <20201010104431.GR7004@redhat.com> (raw)
In-Reply-To: <20201009170903.GA763924@redhat.com>
On 09/10/20 18:09 +0100, Jonathan Wakely wrote:
>This removes the __detail::_Shift class template, replacing it with a
>constexpr function template __pow2m1. Instead of using the _Mod class
>template to calculate a modulus just perform a bitwise AND with the
>result of __pow2m1. This works because the places that change all
>perform a modulus operation with a power of two, x mod 2^w, which can be
>replaced with x & (2^w - 1).
Actually that's not quite true, there are two kinds of usage of
_Shift. The first is used with _Mod to do x mod 2^w as mentioned
above.
The second is to calculate the factor to multiply a 32-bit value by
when shifting it into the higher bits of a 64-bit or 128-bit value:
>- _UIntType __factor = 1u;
> _UIntType __sum = 0u;
> for (size_t __j = 0; __j < __k; ++__j)
> {
>- __sum += __arr[__j + 3] * __factor;
>- __factor *= __detail::_Shift<_UIntType, 32>::__value;
>+ __sum += __arr[__j + 3] << (32 * __j);
> }
But we don't need the _Shift template here either. Instead of
multiplying by (j+1) * 2^32 we can just shift by j * 32 instead.
I'll update the commit msg to mention that usage too.
prev parent reply other threads:[~2020-10-10 10:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-09 17:09 Jonathan Wakely
2020-10-10 10:44 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201010104431.GR7004@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).