From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 4C45F3858419 for ; Wed, 20 Oct 2021 09:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C45F3858419 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-aMIZKUo2PTGXBSriadeAMw-1; Wed, 20 Oct 2021 05:12:52 -0400 X-MC-Unique: aMIZKUo2PTGXBSriadeAMw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 950651800D41; Wed, 20 Oct 2021 09:12:51 +0000 (UTC) Received: from localhost (unknown [10.33.36.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4574CADCD; Wed, 20 Oct 2021 09:12:51 +0000 (UTC) Date: Wed, 20 Oct 2021 10:12:50 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Bill Schmidt , Segher Boessenkool Subject: Re: [PATCH] libstdc++: Add support for POWER9 DARN instruction to std::random_device Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Oct 2021 09:12:55 -0000 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