From owner-freebsd-current@freebsd.org Tue Dec 8 07:57:05 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F287E9D3B10 for ; Tue, 8 Dec 2015 07:57:04 +0000 (UTC) (envelope-from 214748mv@gmail.com) Received: from mail-ig0-x232.google.com (mail-ig0-x232.google.com [IPv6:2607:f8b0:4001:c05::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C4A601AB0; Tue, 8 Dec 2015 07:57:04 +0000 (UTC) (envelope-from 214748mv@gmail.com) Received: by igvg19 with SMTP id g19so96446601igv.1; Mon, 07 Dec 2015 23:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0xOVny4SfRdS0Y/3gAuBVFGcrVi13A/1fWoMvOKXyrQ=; b=TvK+Zw7zY+mDOiRSJm9uk9u0vNUtnuDYd29XMMGVs+6X6VcewdXQUs7hVfbUTE+QjL BgZ1WLOC7jP+maZd7DLSRK/MDc3aCjpJcYyLwbIzblmQpcyWwHhu/HybwrVY7j+fosl4 UnzmOpODg2hzz8YHb5ngili+uLD0ZdAt6arriur5KXZDPBaOQy4bHk9TzUNK6T3FMMrF jM6+I7J9hgQJxP0+Nn/vYYiUMjErkKuZkLV9RbAtmRsecHKAtkXhN7XnrQr4s9NQy0BB rQ17+I6ajla1R5WmAs38VcOrgBCN/6fazy3ke+Iq/A+7EMEHb3B1titB5VzzN4pcmnb6 c0ig== MIME-Version: 1.0 X-Received: by 10.50.27.38 with SMTP id q6mr19421290igg.70.1449561424134; Mon, 07 Dec 2015 23:57:04 -0800 (PST) Received: by 10.79.111.199 with HTTP; Mon, 7 Dec 2015 23:57:04 -0800 (PST) In-Reply-To: References: <20151208031327.GA17554@thinkpad.swarthmore.edu> Date: Tue, 8 Dec 2015 08:57:04 +0100 Message-ID: Subject: Re: [PATCH] XOR uses From: "Ranjan1018 ." <214748mv@gmail.com> To: araujo@freebsd.org Cc: Michael McConville , freebsd-current Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2015 07:57:05 -0000 2015-12-08 5:40 GMT+01:00 Marcelo Araujo : > Hi Michael, > > What would be the advantage of it? > I still prefer explicit than implicit. The current code is much more > readable. > > Best, > > 2015-12-08 11:13 GMT+08:00 Michael McConville : > > > A minor simplification patch: > > > > > > Index: sys/arm/allwinner/a10_gpio.c > > =================================================================== > > --- sys/arm/allwinner/a10_gpio.c (revision 291978) > > +++ sys/arm/allwinner/a10_gpio.c (working copy) > > @@ -356,10 +356,7 @@ > > sc = device_get_softc(dev); > > A10_GPIO_LOCK(sc); > > data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); > > - if (data & (1 << pin)) > > - data &= ~(1 << pin); > > - else > > - data |= (1 << pin); > > + data ^= (1 << pin); > > A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), data); > > A10_GPIO_UNLOCK(sc); > > > > Index: sys/arm/altera/socfpga/socfpga_gpio.c > > =================================================================== > > --- sys/arm/altera/socfpga/socfpga_gpio.c (revision 291978) > > +++ sys/arm/altera/socfpga/socfpga_gpio.c (working copy) > > @@ -336,10 +336,7 @@ > > > > GPIO_LOCK(sc); > > reg = READ4(sc, GPIO_SWPORTA_DR); > > - if (reg & (1 << i)) > > - reg &= ~(1 << i); > > - else > > - reg |= (1 << i); > > + reg ^= (1 << i); > > WRITE4(sc, GPIO_SWPORTA_DR, reg); > > GPIO_UNLOCK(sc); > > > > Index: sys/arm/rockchip/rk30xx_gpio.c > > =================================================================== > > --- sys/arm/rockchip/rk30xx_gpio.c (revision 291978) > > +++ sys/arm/rockchip/rk30xx_gpio.c (working copy) > > @@ -375,10 +375,7 @@ > > return (EINVAL); > > RK30_GPIO_LOCK(sc); > > data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DR); > > - if (data & (1U << pin)) > > - data &= ~(1U << pin); > > - else > > - data |= (1U << pin); > > + data ^= (1U << pin); > > RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DR, data); > > RK30_GPIO_UNLOCK(sc); > > > > Index: sys/arm/samsung/exynos/exynos5_pad.c > > =================================================================== > > --- sys/arm/samsung/exynos/exynos5_pad.c (revision 291978) > > +++ sys/arm/samsung/exynos/exynos5_pad.c (working copy) > > @@ -722,10 +722,7 @@ > > > > GPIO_LOCK(sc); > > reg = READ4(sc, bank.port, bank.con + 0x4); > > - if (reg & (1 << pin_shift)) > > - reg &= ~(1 << pin_shift); > > - else > > - reg |= (1 << pin_shift); > > + reg ^= (1 << pin_shift); > > WRITE4(sc, bank.port, bank.con + 0x4, reg); > > GPIO_UNLOCK(sc); > > > > Index: sys/dev/nand/nandsim_ctrl.c > > =================================================================== > > --- sys/dev/nand/nandsim_ctrl.c (revision 291978) > > +++ sys/dev/nand/nandsim_ctrl.c (working copy) > > @@ -388,9 +388,6 @@ > > rand = random(); > > if ((rand % 1000000) < chip->error_ratio) { > > bit = rand % 8; > > - if (*byte & (1 << bit)) > > - *byte &= ~(1 << bit); > > - else > > - *byte |= (1 << bit); > > + *byte ^= (1 << bit); > > } > > } > > > Hi, I prefer the syntax in the patch: - the semantic is more clear for me: if you want to flip a bit you should use xor - it saves, probably, some bytes of assembly code Regards Maurizio