GCC Hacks in the Linux Kernel

The Linux kernel uses several special capabilities of the GNU Compiler Collection (GCC) suite. These capabilities range from giving you shortcuts and simplifications to providing the compiler with hints for optimization. Discover some of these special GCC features and learn how to use them in the Linux kernel.

The article introduces some obscure yet useful GCC extensions with sample code from the linux kernel. The extensions are categorized into functionality and optimization. Some of my favorite extensions from the list are:

  • Type Discovery. This is a simplified version of templates found in C++. But its pretty cool to write a generic min() or max() function using this extension.
  • Range Extension. Now this is an awesome extension that can save some typing (or copy/pasting). It lets you use a range in Switch … Case statements. You can also initialize an array range with a value.
  • Branch Prediction and Pre-fetching. These extensions are optimization hints that help the compiler to produce efficient machine code. Branch Prediction is used in if-else conditions to notify which condition is more likely to be true. Pre-fetching is manually populating the L1 and L2 cache with appropriate data which results in reduced latency, thus improving the performance.


  1. 2008-11-21 4:58 am
    • 2008-11-21 5:34 am
      • 2008-11-21 1:34 pm
        • 2008-11-21 1:45 pm
          • 2008-11-21 1:54 pm
  2. 2008-11-21 2:05 pm
  3. 2008-11-22 2:09 am
    • 2008-11-22 7:32 pm
      • 2008-11-22 7:50 pm
    • 2008-11-22 7:33 pm