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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9E2A2385803B for ; Wed, 3 Nov 2021 15:01:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E2A2385803B Received: from mail-vk1-f200.google.com (mail-vk1-f200.google.com [209.85.221.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-4LkppP-jMIuNp9zAb9c0Uw-1; Wed, 03 Nov 2021 11:01:35 -0400 X-MC-Unique: 4LkppP-jMIuNp9zAb9c0Uw-1 Received: by mail-vk1-f200.google.com with SMTP id y135-20020a1f328d000000b002e25ebcc4a8so1015639vky.14 for ; Wed, 03 Nov 2021 08:01:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0bTDWocIdYJoQrXw6jRgfNpGJJJDQ+Esg2RETDHylVQ=; b=diLbMqbwSBTvYjzOsjhvfA3wFnhAfcUbYMuIIfG0PL8Z/pmWqeO3aqUXVVMpD6aZkT gCeQHA8a59R7PJtSO5P6QNXze8tPSgaAmxIjF1VOwVNO0FEpixzxrtF0mfI/2y3wcFQ7 udwcmvO8qIQBOtG2UMP/6RAs6h2xAQ/SSFmfKVxMPw0O2qC88n5cP5hvWPo7AImlj+FU 7pAaQzefwNkKZ7RuCTfYcKgiZ6I3Aw+DS8Io5sJFMKaKoqwoMcnIt8KH57d0NZP4q8/g J4VFOwebeLEzoMOxL8f2om5+tLstYB8wd1h27Ug/9hsSiaGLGqisSyrpRF4Y9Or22VMc EfPQ== X-Gm-Message-State: AOAM5338OKLWiBAPLv4VbQSReMezXyH5Do0qCG/B6EfPPMFyQ7NqaNaq zY8hnnwYDd3jR9cRqbyrsKS7upYGNmm6S0wPD9wrIyCjOMs5TbHk6WxrNB5YRy7A3Og2Pa0NPcr hXdBsGq23/61SJ1NsW3uNd7Y8FNVwLEw= X-Received: by 2002:a05:6102:c8a:: with SMTP id f10mr50030298vst.11.1635951694436; Wed, 03 Nov 2021 08:01:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx61uO+AY6V/6/YzbFrNPBl4BGoT/Nq0NKXo1ypiYUJhQIVPRRnibryAxbPYMJJgTV+WwU7o1CHjCg/4lZS1CY= X-Received: by 2002:a05:6102:c8a:: with SMTP id f10mr50030246vst.11.1635951694142; Wed, 03 Nov 2021 08:01:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 3 Nov 2021 15:01:22 +0000 Message-ID: Subject: Re: [PATCH v2] libstdc++: Add support for POWER9 DARN instruction to std::random_device To: Jonathan Wakely Cc: "libstdc++" , gcc Patches , Bill Schmidt , Segher Boessenkool X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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, 03 Nov 2021 15:01:44 -0000 Any feedback from POWER maintainers about this? I'd like to push it soon if there's nothing wrong with it. On Wed, 20 Oct 2021 at 14:00, Jonathan Wakely via Libstdc++ < libstdc++@gcc.gnu.org> 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. > > >