From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marc Zyngier Subject: Re: [Android-virt] [PATCH v5 05/13] ARM: KVM: Inject IRQs and FIQs from userspace Date: Mon, 12 Dec 2011 11:06:45 +0000 Message-ID: <4EE5E045.7070904@arm.com> References: <20111211102403.21693.6887.stgit@localhost> <20111211102449.21693.12265.stgit@localhost> <4EE4C9D8.1010601@web.de> <-4744042178058961854@unknownmsgid> Mime-Version: 1.0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Cc: Peter Maydell , Christoffer Dall , "kvm@vger.kernel.org" , Jan Kiszka , "avi@redhat.com" , "android-virt@lists.cs.columbia.edu" , "tech@virtualopensystems.com" To: Christoffer Dall Return-path: Received: from service87.mimecast.com ([91.220.42.44]:58820 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751710Ab1LLLGv convert rfc822-to-8bit (ORCPT ); Mon, 12 Dec 2011 06:06:51 -0500 In-Reply-To: <-4744042178058961854@unknownmsgid> Sender: kvm-owner@vger.kernel.org List-ID: On 11/12/11 20:07, Christoffer Dall wrote: > On Dec 11, 2011, at 2:48 PM, Peter Maydell wrote: > >> On 11 December 2011 19:30, Christoffer Dall >> wrote: >>> On Sun, Dec 11, 2011 at 11:03 AM, Peter Maydell >>> wrote: >>>> Removing the mask would be wrong since the irq field here >>>> is encoding both cpu number and irq-vs-fiq. The default is >>>> just an unreachable condition. (Why are we using % here >>>> rather than the obvious bit operation, incidentally?) >>>> >>> right, I will remove the default case. >>> >>> I highly doubt that the difference in using a bitop will be measurably >>> more efficient, but if you feel strongly about it, I can change it to >>> a shift and bitwise and, which I assume is what you mean by the >>> obvious bit operation? I think my CS background speaks for using %, >>> but whatever. >> >> Certainly the compiler ought to be able to figure out the >> two are the same thing; I just think "irq & 1" is more readable >> than "irq % 2" (because it's being clear that it's treating the >> variable as a pile of bits rather than an integer). This is >> bikeshedding rather, though, and style issues in kernel code >> are a matter for the kernel folk. So you can ignore me :-) >> > Well, if it was just "irq & 1", then I hear you, but it would be "(irq >>> cpu_idx) & 1" which I don't think is more clear. > > But yes let's see what the kernel folks say. The general consensus is to use bit operations rather than arithmetic. The compiler will usually convert the "% 2" pattern into a shift, but I tend to agree with Peter on the readability of the thing. When encoding multiple information in a word, bit operations should be used, as they make it obvious which part of the word contains the bit you're interested in. But I've probably been corrupted by working with HW guys for a bit too long... ;-) M. -- Jazz is not dead. It just smells funny...