Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine word size of my processor

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 printing sizeof(int) would be enough to determine the word size of my processor?

like image 394
user69514 Avatar asked Feb 20 '10 04:02

user69514


People also ask

How do I find out the size of my word processor?

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.

What is the word size of Intel CPU?

In the x86 PC (Intel, AMD, etc.), although the architecture has long supported 32-bit and 64-bit registers, its native word size stems back to its 16-bit origins, and a "single" word is 16 bits.

What is the word size of a 64 bit computer?

DWORD (32 bits/4 bytes) QWORD (64 bits/8 bytes)

What is the word size of Pentium processor?

Answer: The Pentium/Pentium Pro provide four data types: a byte (8 bits), a word (16 bits), a doubleword (32 bits), and a quadword (64 bits).


1 Answers

Your assumption about sizeof(int) is untrue; see this.

Since you must know the processor, OS and compiler at compilation time, the word size can be inferred using predefined architecture/OS/compiler macros provided by the compiler.

However while on simpler and most RISC processors, word size, bus width, register size and memory organisation are often consistently one value, this may not be true to more complex CISC and DSP architectures with various sizes for floating point registers, accumulators, bus width, cache width, general purpose registers etc.

Of course it begs the question why you might need to know this? Generally you would use the type appropriate to the application, and trust the compiler to provide any optimisation. If optimisation is what you think you need this information for, then you would probably be better off using the C99 'fast' types. If you need to optimise a specific algorithm, implement it for a number of types and profile it.

like image 143
Clifford Avatar answered Sep 22 '22 04:09

Clifford