From owner-freebsd-arch@FreeBSD.ORG Fri May 16 05:19:05 2008 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C8372106564A; Fri, 16 May 2008 05:19:05 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.delphij.net (delphij-pt.tunnel.tserv2.fmt.ipv6.he.net [IPv6:2001:470:1f03:2c9::2]) by mx1.freebsd.org (Postfix) with ESMTP id E66738FC17; Fri, 16 May 2008 05:19:04 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [202.108.54.204]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.delphij.net (Postfix) with ESMTPS id 8FFEC28449; Fri, 16 May 2008 13:19:03 +0800 (CST) Received: from localhost (tarsier.geekcn.org [202.108.54.204]) by tarsier.geekcn.org (Postfix) with ESMTP id 197F1EB2507; Fri, 16 May 2008 13:19:03 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([202.108.54.204]) by localhost (mail.geekcn.org [202.108.54.204]) (amavisd-new, port 10024) with ESMTP id 91MfQ63LV5eB; Fri, 16 May 2008 13:18:57 +0800 (CST) Received: from charlie.delphij.net (c-69-181-135-56.hsd1.ca.comcast.net [69.181.135.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id E8FB3EB24FA; Fri, 16 May 2008 13:18:55 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:cc:subject:x-enigmail-version:openpgp:content-type; b=M1kMpISOdcgj33maNgbexpDTjhxHChG2RhW4Pp8Do+TeWo28RZBCRCKl9xhTp7hFY Sn/F3ESBhTmdmdhPuGt9Q== Message-ID: <482D193D.2010802@delphij.net> Date: Thu, 15 May 2008 22:18:53 -0700 From: Xin LI Organization: The FreeBSD Project User-Agent: Thunderbird 2.0.0.14 (X11/20080505) MIME-Version: 1.0 To: freebsd-arch@FreeBSD.org X-Enigmail-Version: 0.95.6 OpenPGP: id=18EDEBA0; url=http://www.delphij.net/delphij.asc Content-Type: multipart/mixed; boundary="------------070905020208020405010806" Cc: sephe@FreeBSD.org Subject: A couple of bitwise operations X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2008 05:19:06 -0000 This is a multi-part message in MIME format. --------------070905020208020405010806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I find the DragonFly macros, __BIT, __BITS, __LOWEST_SET_BIT, __SHIFTOUT, __SHIFTIN and __SHIFTOUT_MASK useful. Any objection adding this as sys/sys/bitops.h? (These macros are found in NetBSD in sys/sys/cdefs.h and DragonFly as sys/sys/bitops.h) Cheers, - -- ** Help China's quake relief at http://www.redcross.org.cn/ |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Xin LI http://www.delphij.net/ FreeBSD - The Power to Serve! -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkgtGTwACgkQi+vbBBjt66DYYACePxDc5HaOpQXoJVSfttjukSvp bsAAnR61/+vOEaHqVNZjiynQzksLmTix =X14I -----END PGP SIGNATURE----- --------------070905020208020405010806 Content-Type: text/plain; name="bitops.h" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="bitops.h" /* * Copyright (c) 2004, 2005 David Young. All rights reserved. * * Programmed for NetBSD by David Young. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of David Young may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * $DragonFly: src/sys/sys/bitops.h,v 1.1 2007/10/14 04:15:17 sephe Exp $ * $FreeBSD$ */ #ifndef _SYS_BITOPS_H_ #define _SYS_BITOPS_H_ /* * __BIT(n): Return a bitmask with bit n set, where the least * significant bit is bit 0. * * __BITS(m, n): Return a bitmask with bits m through n, inclusive, * set. It does not matter whether m>n or m<=n. The * least significant bit is bit 0. * * A "bitfield" is a span of consecutive bits defined by a bitmask, * where 1s select the bits in the bitfield. __SHIFTIN, __SHIFTOUT, * and __SHIFTOUT_MASK help read and write bitfields from device * registers. * * __SHIFTIN(v, mask): Left-shift bits `v' into the bitfield * defined by `mask', and return them. No * side-effects. * * __SHIFTOUT(v, mask): Extract and return the bitfield selected * by `mask' from `v', right-shifting the * bits so that the rightmost selected bit * is at bit 0. No side-effects. * * __SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that * the rightmost non-zero bit is at bit * 0. This is useful for finding the * greatest unsigned value that a bitfield * can hold. No side-effects. Note that * __SHIFTOUT_MASK(m) = __SHIFTOUT(m, m). */ /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ #define __BIT(__n) (((__n) == 32) ? 0 : ((uint32_t)1 << (__n))) /* __BITS(m, n): bits m through n, m < n. */ #define __BITS(__m, __n) \ ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) /* Find least significant bit that is set */ #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) #endif /* !_SYS_BITOPS_H_ */ --------------070905020208020405010806--