Determine word size of my processor

后端 未结 8 1247
长发绾君心
长发绾君心 2020-11-28 08:26

How do I determine the word size of my CPU? If I understand correct an int should be one word right? I\'m not sure if I am correct.

So should just prin

8条回答
  •  一整个雨季
    2020-11-28 09:12

    sizeof(int) is not always the "word" size of your CPU. The most important question here is why you want to know the word size.... are you trying to do some kind of run-time and CPU specific optimization?

    That being said, on Windows with Intel processors, the nominal word size will be either 32 or 64 bits and you can easily figure this out:

    • if your program is compiled for 32-bits, then the nominal word size is 32-bits
    • if you have compiled a 64-bit program then then the nominal word size is 64-bits.

    This answer sounds trite, but its true to the first order. But there are some important subtleties. Even though the x86 registers on a modern Intel or AMD processor are 64-bits wide; you can only (easily) use their 32-bit widths in 32-bit programs - even though you may be running a 64-bit operating system. This will be true on Linux and OSX as well.

    Moreover, on most modern CPU's the data bus width is wider than the standard ALU registers (EAX, EBX, ECX, etc). This bus width can vary, some systems have 128 bit, or even 192 bit wide busses.

    If you are concerned about performance, then you also need to understand how the L1 and L2 data caches work. Note that some modern CPU's have an L3 cache. Caches including a unit called the Write Buffer

提交回复
热议问题