From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 865B23858439; Thu, 4 Nov 2021 20:44:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 865B23858439 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A4KGWNX013596; Thu, 4 Nov 2021 20:44:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c4pdqgenc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Nov 2021 20:44:47 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1A4KLJIb002674; Thu, 4 Nov 2021 20:44:46 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c4pdqgen3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Nov 2021 20:44:46 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1A4KT0I6009221; Thu, 4 Nov 2021 20:44:45 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma02dal.us.ibm.com with ESMTP id 3c22tu4m5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Nov 2021 20:44:45 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1A4KiiAY26607956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 4 Nov 2021 20:44:44 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA5506E053; Thu, 4 Nov 2021 20:44:44 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 785636E050; Thu, 4 Nov 2021 20:44:44 +0000 (GMT) Received: from Bills-MacBook-Pro.local (unknown [9.211.111.110]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 4 Nov 2021 20:44:44 +0000 (GMT) Reply-To: wschmidt@linux.ibm.com Subject: Re: [PATCH v2] libstdc++: Add support for POWER9 DARN instruction to std::random_device To: Jonathan Wakely Cc: libstdc++ , gcc Patches , Segher Boessenkool References: From: Bill Schmidt Message-ID: <00a3f87e-77d4-39d4-8385-4207ab271bb1@linux.ibm.com> Date: Thu, 4 Nov 2021 15:44:43 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: Content-Language: en-GB X-TM-AS-GCONF: 00 X-Proofpoint-GUID: iwcRNKIcUCDS2XpvNXyG2AmOuHE653Bf X-Proofpoint-ORIG-GUID: F59nhx0YbsQGbqXYkAPXECKFQCehdALd Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-04_06,2021-11-03_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1011 spamscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111040080 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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: Thu, 04 Nov 2021 20:44:50 -0000 For posterity:  This was discussed briefly on IRC, and Segher approved with some simplifications and a request to implement a fail/retry check. Thanks, Bill On 11/3/21 10:02 AM, Jonathan Wakely wrote: > On Wed, 3 Nov 2021 at 15:01, Jonathan Wakely wrote: Any feedback from POWER maintainers about this? I'd like to push it soon if there's nothing wrong with it. With the updated patch attached again this time ... ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ZjQcmQRYFpfptBannerStart > This Message Is From an External Sender > This message came from outside your organization. > ZjQcmQRYFpfptBannerEnd > On Wed, 3 Nov 2021 at 15:01, Jonathan Wakely wrote: > > Any feedback from POWER maintainers about this? I'd like to push it soon if there's nothing wrong with it. > > > With the updated patch attached again this time ... > > > > On Wed, 20 Oct 2021 at 14:00, Jonathan Wakely via Libstdc++ > wrote: > > On 20/10/21 10:12 +0100, Jonathan Wakely wrote: > >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. > > > > Here's the updated patch with a configure check for assembler support, > and the target attribute fixed. > > This still requires Glibc 2.23 for __builtin_cpu_supports, which I'm > assuming is acceptable. > > > >