From owner-svn-src-stable-9@FreeBSD.ORG Mon Apr 15 18:30:01 2013 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id DD08D426; Mon, 15 Apr 2013 18:30:01 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id C12A71270; Mon, 15 Apr 2013 18:30:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3FIU18E023206; Mon, 15 Apr 2013 18:30:01 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3FIU1Hd023205; Mon, 15 Apr 2013 18:30:01 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201304151830.r3FIU1Hd023205@svn.freebsd.org> From: Dimitry Andric Date: Mon, 15 Apr 2013 18:30:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r249518 - stable/9/contrib/llvm/lib/Support X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Apr 2013 18:30:01 -0000 Author: dim Date: Mon Apr 15 18:30:00 2013 New Revision: 249518 URL: http://svnweb.freebsd.org/changeset/base/249518 Log: Pull in r178636 from upstream llvm trunk: Second pass at addressing PR15351 by explicitly checking for AVX support when getting the host processor information. It emits a .byte sequence on GNUC compilers to work around lack of xgetbv support with older assemblers, and resolves a comment typo found in the previous patch. This should fix crashes due to emitting of AVX instructions on certain processors, which do not support then, when using -march=native. This is a direct commit to stable/9, since head has a complete import of llvm/clang trunk, and there is no single commit to merge. Reported by: Kubilay Kocak Modified: stable/9/contrib/llvm/lib/Support/Host.cpp Modified: stable/9/contrib/llvm/lib/Support/Host.cpp ============================================================================== --- stable/9/contrib/llvm/lib/Support/Host.cpp Mon Apr 15 17:59:06 2013 (r249517) +++ stable/9/contrib/llvm/lib/Support/Host.cpp Mon Apr 15 18:30:00 2013 (r249518) @@ -111,6 +111,21 @@ static bool GetX86CpuIDAndInfo(unsigned #endif } +static bool OSHasAVXSupport() { +#if defined( __GNUC__ ) + // Check xgetbv; this uses a .byte sequence instead of the instruction + // directly because older assemblers do not include support for xgetbv and + // there is no easy way to conditionally compile based on the assembler used. + int rEAX, rEDX; + __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a" (rEAX), "=d" (rEDX) : "c" (0)); +#elif defined(_MSC_VER) + unsigned long long rEAX = _xgetbv(_XCR_XFEATURE_ENABLED_MASK); +#else + int rEAX = 0; // Ensures we return false +#endif + return (rEAX & 6) == 6; +} + static void DetectX86FamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) { Family = (EAX >> 8) & 0xf; // Bits 8 - 11 @@ -133,6 +148,10 @@ std::string sys::getHostCPUName() { DetectX86FamilyModel(EAX, Family, Model); bool HasSSE3 = (ECX & 0x1); + // If CPUID indicates support for XSAVE, XRESTORE and AVX, and XGETBV + // indicates that the AVX registers will be saved and restored on context + // switch, then we have full AVX support. + bool HasAVX = (ECX & ((1 << 28) | (1 << 27))) != 0 && OSHasAVXSupport(); GetX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); bool Em64T = (EDX >> 29) & 0x1; @@ -242,11 +261,15 @@ std::string sys::getHostCPUName() { case 42: // Intel Core i7 processor. All processors are manufactured // using the 32 nm process. case 45: - return "corei7-avx"; + // Not all Sandy Bridge processors support AVX (such as the Pentium + // versions instead of the i7 versions). + return HasAVX ? "corei7-avx" : "corei7"; // Ivy Bridge: case 58: - return "core-avx-i"; + // Not all Ivy Bridge processors support AVX (such as the Pentium + // versions instead of the i7 versions). + return HasAVX ? "core-avx-i" : "corei7"; case 28: // Most 45 nm Intel Atom processors case 38: // 45 nm Atom Lincroft