From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: Bill Schmidt <wschmidt@linux.ibm.com>,
Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH] libstdc++: Add support for POWER9 DARN instruction to std::random_device
Date: Wed, 20 Oct 2021 10:12:50 +0100 [thread overview]
Message-ID: <YW/dktwz20HOdTHw@redhat.com> (raw)
In-Reply-To: <YW72mu89f24vKPrl@redhat.com>
On 19/10/21 17:47 +0100, Jonathan Wakely wrote:
>The ISA-3.0 instruction set includes DARN ("deliver a random number")
>which can be used similar to the existing support for RDRAND and RDSEED.
>
>libstdc++-v3/ChangeLog:
>
> * src/c++11/random.cc (USE_DARN): Define.
> (__ppc_darn): New function to use POWER9 DARN instruction.
> (Which): Add 'darn' enumerator.
> (which_source): Check for __ppc_darn.
> (random_device::_M_init): Support "darn" and "hw" tokens.
> (random_device::_M_getentropy): Add darn to switch.
> * testsuite/26_numerics/random/random_device/cons/token.cc:
> Check "darn" token.
> * testsuite/26_numerics/random/random_device/entropy.cc:
> Likewise.
>
>Tested powerpc64le-linux (power8 and power9) and x86_64-linux.
>
>The new "darn" (power-specific) and "hw" (x86 and power)
>strings should be documented, but I'll do that if this gets committed.
>
>Most of this patch is just "more of the same", similar to the existing
>code for RDRAND and RDSEED on x86, but the parts of the patch I'd like
>more eyes on are:
>
>
>+#elif defined __powerpc__ && defined __BUILTIN_CPU_SUPPORTS__
>+# define USE_DARN 1
> #endif
This means DARN can only be used when __builtin_cpu_supports is
available, which means glibc 2.23 ... is that acceptable? It means
RHEL 7 wouldn't be able to use DARN, but RHEL 8 would.
There certainly are POWER9 machines running RHEL 7 and similar
vintages (the GCC compile farm has one) so if there's another way to
check for ISA 3.0 then I could use that.
If __POWER9_VECTOR__ is defined when building libstdc++, presumably
that means the whole library can only be run on POWER9 hardware. So
would that mean we don't need to check __builtin_cpu_supports("darn")
when __POWER9_VECTOR__ is defined? Or is it possible to build with
-mcpu=power8 -mpower9-vector and run it on h/w without the DARN
instruction?
Also, I forgot to add a configure check that the assembler supports
darn, which is another prerequisite for using it here.
>@@ -135,6 +137,15 @@ namespace std _GLIBCXX_VISIBILITY(default)
> #endif
> #endif
>
>+#ifdef USE_DARN
>+ unsigned int
>+ __attribute__((target("power9")))
Oops, that should be "cpu=power9".
With that change it works on a POWER9 machine (9009-42A) with glibc
2.34 and binutils 2.35.
>+ __ppc_darn(void*)
>+ {
>+ return __builtin_darn_32();
>+ }
>+#endif
next prev parent reply other threads:[~2021-10-20 9:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 16:47 Jonathan Wakely
2021-10-20 9:12 ` Jonathan Wakely [this message]
2021-10-20 13:00 ` [PATCH v2] " Jonathan Wakely
2021-11-03 15:01 ` Jonathan Wakely
2021-11-03 15:02 ` Jonathan Wakely
2021-11-04 20:44 ` Bill Schmidt
2021-11-05 12:44 ` Jonathan Wakely
2021-11-05 13:20 ` Bill Schmidt
2021-11-05 18:16 ` Jonathan Wakely
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=YW/dktwz20HOdTHw@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=segher@kernel.crashing.org \
--cc=wschmidt@linux.ibm.com \
/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).