From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXWap-0000pM-4c for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:38:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXWal-0006Rm-Tf for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:38:27 -0400 Received: from mail-qk0-x22a.google.com ([2607:f8b0:400d:c09::22a]:33260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXWal-0006RW-QT for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:38:23 -0400 Received: by qkdv1 with SMTP id v1so22848319qkd.0 for ; Thu, 03 Sep 2015 08:38:23 -0700 (PDT) Sender: Richard Henderson References: <1441243885-7495-1-git-send-email-rth@twiddle.net> <1441243885-7495-34-git-send-email-rth@twiddle.net> <55E86117.9070806@redhat.com> From: Richard Henderson Message-ID: <55E8696B.4030006@twiddle.net> Date: Thu, 3 Sep 2015 08:38:19 -0700 MIME-Version: 1.0 In-Reply-To: <55E86117.9070806@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v15 33/33] target-tilegx: Handle v1shl, v1shru, v1shrs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org On 09/03/2015 08:02 AM, Eric Blake wrote: > Is it any more efficient to use multiplies instead of looping, as in: > > uint64_t m; > > b &= 7; > m = 0x0101010101010101ULL * ((1 << (8 - b)) - 1); > return (a & m) << b; > > Or if multiplies are bad, what about straight-line expansion of the > mask, as in: > > uint64_t m; > > b &= 7; > m = (1 << (8 - b)) - 1; > m |= m << 32; > m |= m << 16; > m |= m << 8; > return (a & m) << b; The multiply will (likely) be expanded by the compiler to the shift, but yes, I should have played the mask game after Peter pointed out that this wasn't a per-element variable shift in v14. r~