[A86] Re: SDCC v2.3.0


[Prev][Next][Index][Thread]

[A86] Re: SDCC v2.3.0




> Van: rabidcow@juno.com
> 
> The problems with using macros instead of real inline functions are in
> places like this:
> 
> inline int min(a,b) { return (a<b)?a:b; }   /* or #define min(a,b) ... */
> a = min(i++, j);
> 
> which becomes:  a = (i++<j)?i++:j;
> and i may get incremented twice, whereas with real inline functions it
> doesn't.  I think it's likely there're always fancy tricks to get around
> this tho.

Have you tested this? I mean, could it be that the compiler/preprocessor
(or wherever they normaly do the inlineing) translates the inline function
to:

-------
inl_0 = i;
inl_1 = j;
inl_ret_0 = (inl_0++ < inl_1) ? inl_0 : inl_1);
a = inl_ret_0;
-------

as since variables passed to a function are local (for the function only).

SDCC (..if it had inlineing..) would then optimize it a little:

[inl_1 equals j]
[inl_ret_0 equals a]
inl_0 = i;
a = (inl_0++ < j) ? inl_0++ : j);

And maybe even to:

a = ((i+1) < j) ? (i+1) : j);

I think the first optimization (I thought of) would be the best, since the
register allocator could then (possibly) use one register for holding
'inl_0', instead of calculating 'i+1' twice.

	Henk Poley <><