Received: from eggs.gnu.org ([2001:4830:134:3::10]:57224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzd8r-0005uO-BT for qemu-devel@nongnu.org; Thu, 27 Oct 2016 01:22:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzd8o-0007Go-6w for qemu-devel@nongnu.org; Thu, 27 Oct 2016 01:22:17 -0400 Sender: Richard Henderson References: <1477463189-26971-1-git-send-email-nikunj@linux.vnet.ibm.com> <1477463189-26971-6-git-send-email-nikunj@linux.vnet.ibm.com> <20161027034734.GN19918@umbus.fritz.box> From: Richard Henderson Message-ID: Date: Wed, 26 Oct 2016 22:22:10 -0700 MIME-Version: 1.0 In-Reply-To: <20161027034734.GN19918@umbus.fritz.box> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 5/6] target-ppc: add vprtyb[w/d/q] instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson , Nikunj A Dadhania Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, bharata@linux.vnet.ibm.com, sandipandas1990@gmail.com, ego@linux.vnet.ibm.com, Ankit Kumar On 10/26/2016 08:47 PM, David Gibson wrote: >> > +void helper_vprtybq(ppc_avr_t *r, ppc_avr_t *b) >> > +{ >> > + int i; >> > + uint8_t s = 0; >> > + for (i = 0; i < 16; i++) { >> > + s ^= (b->u8[i] & 1); >> > + } >> > + r->u64[LO_IDX] = (!s) ? 0 : 1; >> > + r->u64[HI_IDX] = 0; >> > +} >> > + > I think you can implement these better. First mask with 0x01010101 > (of the appropriate length) to extract the LSB bits of each byte. > Then XOR the two halves together, then quarters and so forth, > ln2(size) times to arrive at the parity. This is similar to the usual > Hamming weight implementation. > You don't even have to mask with 0x01010101 to start. Just fold halves til you get to the byte level and then mask with 1. r~