From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KFGxJ-0001HI-Jf for mharc-grub-devel@gnu.org; Sat, 05 Jul 2008 19:14:13 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KFGxH-0001Gm-7c for grub-devel@gnu.org; Sat, 05 Jul 2008 19:14:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KFGxE-0001DV-Qo for grub-devel@gnu.org; Sat, 05 Jul 2008 19:14:09 -0400 Received: from [199.232.76.173] (port=40181 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KFGxE-0001DA-HZ for grub-devel@gnu.org; Sat, 05 Jul 2008 19:14:08 -0400 Received: from c60.cesmail.net ([216.154.195.49]:42994) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1KFGxE-0004ay-40 for grub-devel@gnu.org; Sat, 05 Jul 2008 19:14:08 -0400 Received: from unknown (HELO relay.cesmail.net) ([192.168.1.81]) by c60.cesmail.net with ESMTP; 05 Jul 2008 19:14:07 -0400 Received: from [192.168.0.21] (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by relay.cesmail.net (Postfix) with ESMTP id 0EFEE618F22 for ; Sat, 5 Jul 2008 19:14:07 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: <1215298499.26019.192.camel@localhost> References: <1215264476.26019.160.camel@localhost> <1215293427.17114.2.camel@dv> <1215298499.26019.192.camel@localhost> Content-Type: text/plain; charset=UTF-8 Date: Sat, 05 Jul 2008 19:14:05 -0400 Message-Id: <1215299645.17114.25.camel@dv> Mime-Version: 1.0 X-Mailer: Evolution 2.22.2 (2.22.2-2.fc9) Content-Transfer-Encoding: 8bit X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: Endianness macros capitalization X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Jul 2008 23:14:11 -0000 On Sun, 2008-07-06 at 00:54 +0200, Javier Martín wrote: > El sáb, 05-07-2008 a las 17:30 -0400, Pavel Roskin escribió: > > They probably should be functions. We may want to sparse annotate GRUB > > one day, and then inline functions in the only way to go. > Hmm... you mean changing this > > #define grub_swap_bytes16(x) \ > ({ \ > grub_uint16_t _x = (x); \ > (grub_uint16_t) ((_x << 8) | (_x >> 8)); \ > }) > > ...for this > > inline grub_uint16_t grub_swap_bytes16(uint16_t x) > { > return (x << 8) | (x >> 8); > } > > and such? Actually, grub_swap_bytes16 should be avoided in the general code. We need to convert macros like grub_cpu_to_le16() to functions. > The pro is that we get rid of the ugly hack in the macro > version that ensures single evaluation, but a con is that we cannot > _force_ any random compiler to inline anything, so we might end up with > gross numbers of function calls. We can force inlining in gcc with always_inline. But we don't need to force anything. Modern versions of gcc can decide for us, but we can influence the choice by using optimization flags, such as -O2 and -Os. In come cases, function calls would take less space than the actual code for byte swapping. > By the way, what is "sparse annotate"? There is a utility called sparse: git://git.kernel.org/pub/scm/linux/kernel/git/josh/sparse.git It acts like a compiler, but it only produces warnings. It can distinguish bitwise types that cannot be treated like normal integers for arithmetic operations like addition. If we mark little-endian and big-endian variables as bitwise, sparse will warn if such variables are used without byte swapping. Linux uses it a lot. Sparse is really a very good checker for that purpose. Sparse does other checks too. -- Regards, Pavel Roskin