|
From: | Christian Franke |
Subject: | Re: Endianness macros capitalization |
Date: | Mon, 07 Jul 2008 21:25:39 +0200 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 |
Javier Martín wrote:
El dom, 06-07-2008 a las 20:30 +0200, Robert Millan escribió:On Sun, Jul 06, 2008 at 12:54:58AM +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); }I know I get to be annoying about this, but which of these two (plus the non-inline version) would result in _smaller_ code? Function calls on i386-pc are cheap (because we use the regparm hack), so maybe it'd work better using normal functions.
Assembly code for grub_swap_bytes16 from Debian gcc 4.1.2-7:Macro or Inline: 4 bytes (minus possible additional benefit from register level optimizations)
66 c1 c0 08 rol $0x8,%ax Function call: 11 bytes 0f b7 c0 movzwl %ax,%eax e8 xx xx xx xx call grub_swap_bytes16 0f b7 c0 movzwl %ax,%eax The break even is possibly at grub_swap_bytes64() :-)
If we are to take the space-saving route, the best we can do is turn them to functions, maybe even _without_ the "inline" keyword, and GCC will do what's best.
How can this be accomplished for functions in include files?If non-inline functions are declared non-static in an include file, duplicate symbols will result (Even with 'inline' you have to be careful due to different inline modes).
If declared static and GCC decides to emit a function instead of inline, the code will be duplicated in all modules which use this function.
AFAIK, GCC supports 'vague linkage' code (each put in an extra section with '.linkonce' attribute) only for C++, but not for C. Or is there a GCC specific function attribute to accomplish this?
Christian
[Prev in Thread] | Current Thread | [Next in Thread] |