From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Rini Date: Fri, 28 Feb 2020 12:35:24 -0500 Subject: [PATCH] common/board_f.c: use #ifdefs a little more consistently In-Reply-To: <1500fa23-9959-76cc-0b3e-148a22cd46da@prevas.dk> References: <20200227081825.11039-1-rasmus.villemoes@prevas.dk> <76d3bc74-0406-cd11-8793-b2192ffdb7ee@prevas.dk> <20200228154620.GJ18302@bill-the-cat> <1500fa23-9959-76cc-0b3e-148a22cd46da@prevas.dk> Message-ID: <20200228173524.GK18302@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Fri, Feb 28, 2020 at 05:24:58PM +0000, Rasmus Villemoes wrote: > On 28/02/2020 16.46, Tom Rini wrote: > > On Fri, Feb 28, 2020 at 08:42:21AM +0000, Rasmus Villemoes wrote: > >> On 28/02/2020 00.40, Simon Glass wrote: > > >>> Using if() is preferable to #if if there is no cost. > >> > >> Completely agree, and I also prefer to have the linker eliminate unused > >> functions rather than cluttering the C code with #ifdefs. But that can't > >> be used in this case. > >> > >> Anyway, this wasn't primarily to save 112 bytes or whatnot from the > >> U-Boot image, just to use one style a little more consistently. > > > > Perhaps we could come up with a little more macro-magic? In > > psuedo-code: > > #define RESERVE_INIT_SEQ_F_ENTRY(fn) \ > > #if CONFIG_IS_ENABLED(toupper(fn)) > > reserve_##fn > > #endif > > #endif > > I'm afraid that's rather far from something that can be implemented; > macros cannot expand to other preprocessor directives, and toupper is > also pretty hard to do. Darn. I would have been willing to move to reserve_FUNCTION if it would have otherwise worked. > What we could do if we want to reduce #ifdefs while still eliminating > the no-op functions is to replace > > #ifdef CONFIG_FOO > static int foo_init(void) { > blabla; > return 0; > } > #endif > ... > init_sequence_f[] = { ... > #ifdef CONFIG_FOO > foo_init, > #endif > ... > } > > by > > static int foo_init(void) { /* always defined */ > blabla; > return 0; > } > > init_sequence_f[] = { ... > IS_ENABLED(CONFIG_FOO) ? foo_init : NULL, > ... > } > > and teach the iterator to ignore NULL entries (I don't remember if we > use a NULL terminator or use ARRAY_SIZE; if the former one should switch > to the latter). It will still cost sizeof(void*) for the NULL entries, > but the function bodies (and on powerpc the .fixups) should be > eliminated, and there's not an #ifdef in sight. That sounds pretty nice actually. If you're so inclined I'd like to see it. -- Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: