Linux source code Analysis of the bit length definition--bitsperlong.h

Source: Internet
Author: User

We know that in the Linux kernel, different CPUs have different byte-order definitions for different CPUs.
This section of the year is mainly about: different CPUs, the definition of the individual bits is also different.

The Linux kernel version used for this analysis is: linux--3.0.0-12.


Arch/xxx/include/asm/bitsperlong.h: Bit length definition for different CPUs (XXX)

1) ARM (xxx=arm):

#include <asm-generic/bitsperlong.h>


(2) PowerPC (XXX=POWERPC)

#ifndef __asm_powerpc_bitsperlong_h
#define __asm_powerpc_bitsperlong_h

#if defined (__powerpc64__)
# define __bits_per_long 64
#else
# define __bits_per_long 32
#endif

#include <asm-generic/bitsperlong.h>

#endif/* __asm_powerpc_bitsperlong_h */


(3) X86 (xxx=x86)

#ifndef __asm_x86_bitsperlong_h
#define __asm_x86_bitsperlong_h

#ifdef __x86_64__
# define __bits_per_long 64
#else
# define __bits_per_long 32
#endif

#include <asm-generic/bitsperlong.h>

#endif/* __asm_x86_bitsperlong_h */


From the 3 examples above, it can be seen that three different CPUs differ in their respective bit length definitions.

Next we look at Asm-generic/bitsperlong.h, the source code is as follows

#ifndef __asm_generic_bits_per_long
#define __asm_generic_bits_per_long

/*
* There seems to be no on the detecting this automatically from user
* Space, so a bit architectures should override this in their
* Bitsperlong.h. In particular, a architecture that supports
* Both and a bit user space must not rely on Config_64bit
* To decide it, but rather check a compiler provided macro.
*/
#ifndef __bits_per_long
#define __bits_per_long 32
#endif

#endif/* __asm_generic_bits_per_long */

The header file describes a schema that supports 32 and 64-bit user space, and does not depend on config_64bit to determine the bit length, but rather examines the macros provided by the compiler.


Summary: That is, the first check arch/xxx/include/asm/bitsperlong.h, see whether the CPU defines a bit length, if not defined, according to Asm-generic/bitsperlong.h to decide.
(This example is defined as long as the arch/xxx/include/asm/bitsperlong.h is not defined, the asm-generic/bitsperlong.h defines a bit length of 32)

Linux source code Analysis of the bit length definition--bitsperlong.h

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.