From owner-svn-src-all@FreeBSD.ORG Fri Jun 10 01:13:15 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A71A8106566C; Fri, 10 Jun 2011 01:13:15 +0000 (UTC) (envelope-from rodrigc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 971588FC18; Fri, 10 Jun 2011 01:13:15 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p5A1DFqo003203; Fri, 10 Jun 2011 01:13:15 GMT (envelope-from rodrigc@svn.freebsd.org) Received: (from rodrigc@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p5A1DFUx003201; Fri, 10 Jun 2011 01:13:15 GMT (envelope-from rodrigc@svn.freebsd.org) Message-Id: <201106100113.p5A1DFUx003201@svn.freebsd.org> From: Craig Rodrigues Date: Fri, 10 Jun 2011 01:13:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222908 - head/lib/libstand X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2011 01:13:15 -0000 Author: rodrigc Date: Fri Jun 10 01:13:15 2011 New Revision: 222908 URL: http://svn.freebsd.org/changeset/base/222908 Log: Obtain bswap64() function implementation from version 1.3 of src/common/lib/libc/gen/bswap64.c in NetBSD. Obtained from: NetBSD Modified: head/lib/libstand/bswap.c Modified: head/lib/libstand/bswap.c ============================================================================== --- head/lib/libstand/bswap.c Thu Jun 9 23:12:23 2011 (r222907) +++ head/lib/libstand/bswap.c Fri Jun 10 01:13:15 2011 (r222908) @@ -8,7 +8,7 @@ __FBSDID("$FreeBSD$"); #if defined(LIBC_SCCS) && !defined(lint) static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $"; -static char *rcsid = "$NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $"; +static char *rcsid = "$NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $"; #endif #include @@ -30,12 +30,28 @@ bswap32(u_int32_t x) u_int64_t bswap64(u_int64_t x) -{ - u_int32_t *p = (u_int32_t*)&x; - u_int32_t t; - t = bswap32(p[0]); - p[0] = bswap32(p[1]); - p[1] = t; - return x; -} - +{ +#ifdef _LP64 + /* + * Assume we have wide enough registers to do it without touching + * memory. + */ + return ( (x << 56) & 0xff00000000000000UL ) | + ( (x << 40) & 0x00ff000000000000UL ) | + ( (x << 24) & 0x0000ff0000000000UL ) | + ( (x << 8) & 0x000000ff00000000UL ) | + ( (x >> 8) & 0x00000000ff000000UL ) | + ( (x >> 24) & 0x0000000000ff0000UL ) | + ( (x >> 40) & 0x000000000000ff00UL ) | + ( (x >> 56) & 0x00000000000000ffUL ); +#else + /* + * Split the operation in two 32bit steps. + */ + u_int32_t tl, th; + + th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL)); + tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL)); + return ((u_int64_t)th << 32) | tl; +#endif +}