From owner-svn-src-head@FreeBSD.ORG Fri Mar 2 02:23:56 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EC0E7106564A; Fri, 2 Mar 2012 02:23:56 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail06.syd.optusnet.com.au (mail06.syd.optusnet.com.au [211.29.132.187]) by mx1.freebsd.org (Postfix) with ESMTP id 83ED38FC13; Fri, 2 Mar 2012 02:23:56 +0000 (UTC) Received: from c211-30-171-136.carlnfd1.nsw.optusnet.com.au (c211-30-171-136.carlnfd1.nsw.optusnet.com.au [211.30.171.136]) by mail06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q222NmPS006269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Mar 2012 13:23:54 +1100 Date: Fri, 2 Mar 2012 13:23:48 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Tijl Coosemans In-Reply-To: <201203012346.20648.tijl@freebsd.org> Message-ID: <20120302130435.J929@besplex.bde.org> References: <201202281939.q1SJdtYr084858@svn.freebsd.org> <20120229160522.W2514@besplex.bde.org> <20120229181608.S2887@besplex.bde.org> <201203012346.20648.tijl@freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Dimitry Andric , Bruce Evans Subject: Re: svn commit: r232266 - in head/sys: amd64/include i386/include pc98/include x86/include X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Mar 2012 02:23:57 -0000 On Thu, 1 Mar 2012, Tijl Coosemans wrote: > On Wednesday 29 February 2012 08:44:54 Bruce Evans wrote: >> ... >> So any macro version must use gcc features to be safe. The following >> seems to work: >> >> #define __bswap16(x) __extension__ ({ __uint16_t __x = x; >> (__uint16_t)(__x << 8 | __x >> 8); }) >> >> clang now produces "rolw $8,x" when x is volatile. This seems to >> violate volatile semantics. gcc produces load-rolw-store then. Both >> produce "rolw $8,x" when x is not volatile. > > I'll have a closer look at the patch tomorrow, but the Intel > documentation for the bswap instruction recommends to use xchg for > bswap16. That's what i386 used to do, using an asm (see for example the RELENG_4 version), but the asm was replaced by C code and the compiler apparently knows better. This might depend on -mtune. I tested with the default, which is poorly documented and hard to remember, but what I remember is that it is for a really old Intel CPU. Checking the documentation shows that the default might be the same as -mtune=generic which is the same as -mtune=i686, where i686 seems to be undocumented but seems to be similar to pentiumpro. I would have to run old tests to verify this. There must also be magic to break i386 support, so that bswap gets used. The current default is certainly not -march=i386 like it used to be, but the details of what it now is seem to be undocumented. It doesn't include SSE support, since it is only for a really old Intel CPU; just one that is not quite as old as plain i386. Bruce