LWN.net Logo

How likely should likely() be?

How likely should likely() be?

Posted Feb 14, 2004 20:48 UTC (Sat) by giraffedata (subscriber, #1954)
In reply to: How likely should likely() be? by zooko
Parent article: How likely should likely() be?

Except that programmer-specified hints are a lot easier. Also, the hint to the code reader can be valuable too.

Where the code reader is concerned, the likely() notation is awful. I read this as "if some_condition is likely, then ..." A more appropriate notation would be

  assert(likely(some_condition));
  if (some_condition) ...

Furthermore, just minimizing the average time spent doing the branch isn't the only reason to do branch prediction hints. Consider

  if (fast_response_required) ...

Even if fast_response_required is rarely true, I may want the code optimized for the case that it is. That gets me to

  optimize_for(fast_response_required)
or maybe
  if (fast_response_required) {
    optimize_for_this_case();
  }


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds