Learning from Kernel Compiler.h

Source: Internet
Author: User

Directly on the code can be, so the study is in the comments!

#ifndef __linux_compiler_h#define __LINUX_COMPILER_H#ifndef __assembly__//If the macro defines the __checker__//Learn more about a sparse#ifdef __checker__/** * This is used to modify a variable, the variable must be non-de-referenced, no * dereference, that is, the variable must be valid, and the variable is located in the * address space must be 1, which is used by the user program. * Program space is divided into 3 parts, 0 means normal space, that is, the normal address space, * for the kernel code, is the kernel space, 1 means the user address space * 2 represents the device address mapping space, such as the hardware device's register in the kernel * map of the address space * */# define __user __attribute__ (Noderef, Address_space (1)))//default is the kernel address space# define __kernel/* Default address space * ///variable can be empty# define __safe __attribute__ (SAFE)//variables can be cast# define __force __attribute__ (force)//parameter type must match the actual parameter type# define __nocast __attribute__ ((nocast))//Pointer address in device address space# define __iomem __attribute__ (Noderef, Address_space (2)))//Parameter x, the reference count must be 0 before execution, and the reference count must be 1 after execution# define __acquires (x) __attribute__ ((Context (0,1) )//Parameter x, the reference count must be 1 before execution, and must be 0 after execution# define __releases (x) __attribute__ ((Context (1,0) )//The reference count for parameter x is +1 after execution# define __acquire (x) __context__ (1)//Parameter x reference count after execution-1# define __RELEASE (x) __context__ ( -1)//Parameter x is 0, returns 0 if parameter x is not 0, the reference count is +1, and returns 1# define __cond_lock (x) (x)? ({__context__ (1); 1;}) : 0)//Check the user address space pointerexternvoid__chk_user_ptr (void__user *);//Check device address space pointerexternvoid__chk_io_ptr (void__iomem *);#else# define __user# define __kernel# define __safe# define __force# define __nocast# define __IOMEM# define __CHK_USER_PTR (x) (void) 0# define __CHK_IO_PTR (x) (void) 0# define __builtin_warning (x, y ...) (1)# define __acquires (x)# define __releases (x)# define __acquire (x) (void) 0# define __RELEASE (x) (void) 0# define __cond_lock (x) (x)#endif#ifdef __kernel__//__GNUC__ This macro represents the version of GCC//You can use this macro to conditionally compile for different versions of GCC#if __gnuc__ > 4//error, no corresponding version of compiler-gcc.h file#error No compiler-gcc.h file for this GCC version#elif __gnuc__ = = 4# include <linux/compiler-gcc4.h>#elif __gnuc__ = = 3# include <linux/compiler-gcc3.h>#else//Sorry, error. Your compiler version is too old or is not recognized. # error Sorry, your compiler is too old/not recognized.#endif/ * Intel compiler defines __gnuc__. So weabove headers files Here is overwrite implementations * coming from above headers files here * The Intel compiler defines __gnuc__. So The compiler-intel.h header file is also included here. */#ifdef __intel_compiler# include <linux/compiler-intel.h>#endif/ * * Generic compiler-dependent macros required for kernel * Build go below this comment. Actual Compiler/compiler version * Specific implementations come from the above header files * Define likely and unlikely macros * * in kernel compilation When translating, the macro definition you need is below the comment. The actual compiler or compiler version is implemented in the header file above. *//* * __builtin_expect () is an implementation provided by GCC or Intel compilers * to provide this implementation in order to optimize the code and avoid the degradation of performance * caused by excessive jumps. * __builtin (!! (x), 1) indicates that X is more likely to have a value of 1 * __builtin (!!) (x), 0) indicates that X is more likely to have a value of 0 * * For example: * int x; * IF (unlikely (x)) * {* x + = 1; *}else{* x = 1; *} * This code indicates that x is more likely to be 0, which means the program executes the code in the else is more likely, so at compile time else The contents follow the code above * *#define LIKELY (x) __builtin_expect (!! (x), 1)#define UNLIKELY (x) __builtin_expect (!! (x), 0)//Optimization barrier//For more information please see my blog [Kernel memory barrier Learning] (http://blog.csdn.net/hongbochen1223/article/details/44961487)/ * Optimization barrier * /#ifndef Barrier# define Barrier () __memory_barrier ()#endif#ifndef reloc_hide# define Reloc_hide (PTR, off) \({unsignedLong__ptr; __ptr = (unsignedLong) (PTR); (typeof (PTR)) (__ptr + (off)); })#endif#endif/* __kernel__ * /#endif/* __assembly__ * /#ifdef __kernel__/ * * allow us to mark functions as ' deprecated ' and has gcc emit a nice * warning for each use, in hopes of speeding The functions removal. * Usage is: * int __deprecated foo (void) * * * * allows us to flag a function as ' obsolete ' and will give GCC a reasonable warning of no use, * hopefully to expedite the removal of the function. * How to use: * int __deprecated foo (void) */#ifndef __deprecated# define __deprecated/* unimplemented *//Not implemented#endif#ifdef MODULE#define __deprecated_for_modules __deprecated#else#define __deprecated_for_modules#endif#ifndef __must_check#define __must_check#endif/* * allow us to avoid ' defined but not used ' warnings on functions and data, * as-well-as force them-be-emitted to The assembly file.  * * As of GCC 3.3, static functions that is not marked with attribute ((used)) * May is elided from the assembly file. As of GCC 3.3, static data not so * marked is not being elided, but this is the change in a future GCC version. * In prior versions of GCC, such functions and data would is emitted, but * would is warned about except with attribute ( (unused)). * * Allow us to avoid the ' define but not use ' warnings in functions and data and force them to send to the * assembly file. * For compiler GCC 3.3, static functions that are not marked with the used attribute will be ignored by the assembly file. However, for the compiler GCC 3.3, there is no such token that static data will not be ignored, but will change in subsequent GCC versions. * In the more advanced GCC version, such functions and data will be transmitted, but will be issued with an ' unused property ' * for exception warnings. */#ifndef __attribute_used__# define __ATTRIBUTE_USED__/* unimplemented *//Not implemented#endif/* * from the GCC manual: * from the GCC manual * * Many functions have no effects except the return value and their * return Valu  E depends only on the parameters and/or global * variables. Such a function can be subject to common subexpression * elimination and loops optimization just as an arithmetic operator * would be. * [...] * Many functions have no effect in addition to their return values, and their return values depend only on parameters * or global variables. Such a function will be governed by the common subexpression elimination and loop optimization as an arithmetic * operator. */#ifndef __attribute_pure__# define __ATTRIBUTE_PURE__/* unimplemented * /#endif#ifndef noinline#define Noinline#endif#ifndef __always_inline#define __always_inline Inline#endif#endif/* __kernel__ * //* * from the GCC manual: * Defines the const function * Many functions does not examine any values except their arguments, * and has no  Effects except the return value. Basically this was * just slightly more strict class than the ' pure ' attribute above, * Since function was not allowed to re AD Global memory.  * Note that a function as has pointer arguments and examines the * data pointed to must _not_ is declared ' const '.  Likewise, A * function that calls a non-' const ' function usually must isn't be * ' const '. It does not make sense for a ' const ' function to return * ' void '. */#ifndef __attribute_const__# define __ATTRIBUTE_CONST__/* unimplemented * /#endif#endif/* __linux_compiler_h * /

Learning from Kernel Compiler.h

Related Article

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.