Boost logo

Boost Users :

Subject: Re: [Boost-users] min and max preferring NaN
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2011-03-10 13:18:35


2011/3/10 Rhys Ulerich <rhys.ulerich_at_[hidden]>

> > inline const T& minnan( const T& a, const T& b )
> > {
> > template < class T >
> > return a < b || is_nan(a) ? a : b;
> > }
>
> That's much cleaner. Thank you Kris. I've tossed my goofy UNLIKELY
> macro around the is_nan check just because.
>
> It's interesting that when using this minnan() implementation on a
> sequence of values that short circuiting suggests using the
> "incumbent" minimum value as the first parameter and the "challenger"
> candidate value as the second parameter.
>
>
I'm no expert in this, but I'd expect a modern compiler to generate for a
modern procesor such code, that would check both conditions parallel
somehow, i.e. in different instruction pipelines. So I wouldn't expect
UNLIKELY or short circuiting to make a defference.. I'd expect UNLIKELY to
kick-in well in situations, the conditional branches are larger. And I'd
expect short circuiting to make a defference in situations, where the
calculations of the condithis are large (or have sideeffects). But only
measurements can tell for sure ;-)

Regards,
Kris



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net