On Don, 2008-09-04 at 20:19 +0200, Henning Rogge wrote:
> On Thu, Sep 4, 2008 at 17:37, Bernd Petrovitsch <bernd@firmix.at> wrote:
> > On Thu, 2008-09-04 at 16:31 +0200, Hannes Gredler wrote:
> > [....]
> >> don't know - perhaps now now - at least we should fix the overflow
> >> detection. (your previous patch) when comparing timestamps to now.
> >
> > Apart from a superfluous '{' (or missing '}';-), the notorious
> > department of "minimized run-time code" uses usually more something
> > like:
> > ----  snip  ----
> > int time_cmp(const olsr_u32_t t1, const olsr_u32_t t2)
> > {
> >    const olsr_32_t diff = t1 - t2;
> >    return diff == 0 ? 0 : diff < 0 : -1 : 1;
> > }
> 
> This code is completely unreadable in my oppinion, sorry.
> 
> A ?: operator in C is just another way to define a conditional operation.
> 
> I see no reason why the code should be any faster than
> 
> int time_cmp(const olsr_u32_t t1, const olsr_u32_t t2)
> {
>    const olsr_32_t diff = t1 - t2;
>    if (diff > 0)
>       return 1;
>    if (diff < 0)
>       return -1;
>    return 0;
> }

That was not your original version (and - with a somewhat sane C
compiler - the ?: operator or the "const"s won't buy anything compared
to the above if() sequence of course).

Why it's different better?
At least gcc-4.1.2 produced other asm code for i386.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services



