Linux-kernel of likely and unlikely

Source: Internet
Author: User

When reading the Linux source code, we often find likely and unlikely, which are defined under Compiler.h.

#define LIKELY (x)__builtin_expect (!! (x), 1)

#define UNLIKELY (x)__builtin_expect (!! (x), 0)

Here we need to first understand __builtin_expect:# define __builtin_expect (x, Expected_value) (x)

So it can be found that likely (x) and x are a meaning, so why bother with such a strength to complicate it?

This is to improve the speed of the system, when the likely instead of direct judgment, the GCC compiler will know that the likely branch is more likely to occur, then we put it in front, so that the cache hit probability will increase, and if it is unlikely, Then this thing may not happen, we should put it in the back, through such a mechanism, is to let the upper layer will be more likely to occur in the awareness of the system to improve the overall speed of operation, from the whole system will have a certain optimization


Linux-kernel of likely and unlikely

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.