From patchwork Fri Oct 14 18:09:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 16516 Received: (qmail 87580 invoked by alias); 14 Oct 2016 18:09:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 87568 invoked by uid 89); 14 Oct 2016 18:09:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=carlosredhatcom, carlos@redhat.com, our X-HELO: mail-qk0-f181.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:organization:message-id:date :user-agent:mime-version:content-transfer-encoding; bh=AQEi1QytyMUvsjs4RMePOE5VC6rRTPOHntJfO9VSH3w=; b=CfIbEoMH3m6t/a3m6FVmAqI8YwEJCBUHnSi0JIOof8n1+UMqBbJklaA0U1OUmkW/ns mR6/U7rDmQpOVxZGBH0roXSMqCBozWj1D49XGvXjIbmDRxkcacGW+MmNwDJhlTSiV3vB lMVHVdPKOcPu9bBq+T9N4q3slVIprhejYZaw9VdtHTivMAF9lG2ilakpPVelnathl2GS Xztj6ve47wIiYdiXuOOSHUPJlYFwT7qkdQlCYVfHPNehwk6uv0ESS2hgpTK9Qw/gzooL XYjBUBHUuM+cxQPW4SjGSqpj7tDFnkreC6Y1R69nWwBqqiOoKTGmyXWBm2PUH0/E6qMF IkZA== X-Gm-Message-State: AA6/9RmPviP1IhF6ZGXb7PhCMSPPNXOwRNc1cAr87vxeppUa2Nd+itQV8ufPRCF58jiR5vO5 X-Received: by 10.55.73.23 with SMTP id w23mr12529591qka.13.1476468567744; Fri, 14 Oct 2016 11:09:27 -0700 (PDT) To: GNU C Library , "H.J. Lu" From: Carlos O'Donell Subject: [PATCH] Bug 201689: Belt-and-suspenders detection of FMA. Message-ID: <90af3efa-aaca-2dce-e433-1df7e5dbcfbd@redhat.com> Date: Fri, 14 Oct 2016 14:09:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In the Intel Architecture Instruction Set Extensions Programming reference the recommended way to test for FMA in section '2.2.1 Detection of FMA' is: "Application Software must identify that hardware supports AVX as explained in ... after that it must also detect support for FMA..." We don't do that in glibc. We use osxsave to detect the use of xgetbv, and after that we check for AVX and FMA orthogonally. It is conceivable that you could have the AVX bit clear and the FMA bit in an undefined state. I have never seen a machine with the AVX bit clear and the FMA bit set, but we should follow the intel specifications and adjust our check as the following patch works. OK to checkin? 2016-10-14 Carlos O'Donell [BZ #20689] * sysdeps/x86/cpu-features.c: Only enable FMA is AVX is present. diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 11b9af2..1d52f22 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -83,8 +83,10 @@ get_common_indeces (struct cpu_features *cpu_features, |= bit_arch_AVX512DQ_Usable; } } - /* Determine if FMA is usable. */ - if (CPU_FEATURES_CPU_P (cpu_features, FMA)) + /* Determine if FMA is usable. The recommended Intel procedure + is to check for AVX && FMA to decide if FMA is available. */ + if (CPU_FEATURES_CPU_P (cpu_features, AVX) + && CPU_FEATURES_CPU_P (cpu_features, FMA)) cpu_features->feature[index_arch_FMA_Usable] |= bit_arch_FMA_Usable; }