Word size
Posted: Sat Dec 18, 2004 6:54 am
Is there any way we can find the word size of a Processor and/or the OS? (without referring to the docs that is)
Code: Select all
xor reg, reg ;put 0 in reg
dec reg ;put 1111111.....b in reg
;then calculate how many bits there is
Code: Select all
#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
I'm unsure what you're asking. A word is described as two-bytes on every processor I've encountered. A byte is eight bits and a nibble is four bits. A double word is four-bytes and a quatenary-word is eight-bytes.Neo wrote: Is there any way we can find the word size of a Processor and/or the OS? (without referring to the docs that is)
Then you may not have encountered SPARC processor yet, nor those ancient exotic 36-bits word machines. And the "dword" and "quadword" you're refering are much intel-specific, afaik.smiddy wrote: A word is described as two-bytes on every processor I've encountered.
Hmm that's right :). But what about this:Pype.Clicker wrote: @aladin, that'd make no sense: if you issue opcode for "dec AX", you will not alter bits 16-31 of a 32bits machine ... And if you use "dec eax", you will not alter bits 32-63 of a 64bits machine.
This is true, however most course today will use what I said as gospel.Pype.Clicker wrote:Then you may not have encountered SPARC processor yet, nor those ancient exotic 36-bits word machines. And the "dword" and "quadword" you're refering are much intel-specific, afaik.smiddy wrote: A word is described as two-bytes on every processor I've encountered.
Yeah, I agree, it is very vague depending on your platform and especially the layer of thinking we're talking. I expect that the original question was compiler specific. As you point out below, that being why I was confused and asking for specifics ;D"Word" is a vague term wich usually refers to the "native integer that the ALU can process at once" ... Since natively-speaking, x86 is a 16bits (then extended) family, "word" has initially referred to a 16bits quantity, but on machines like SunSparc (see mindhack.cebuano.org), 'word' is 32 or 64 bits ...
The most "portable" way to tell is to ask your compiler how large is an "int" (and assume you're using a correctly-configured compiler
Code: Select all
unsigned int i=0;
unsigned bits=0;
for (--i;i;bits++,i=i>>1);
kprint("running on a %i-bits system",bits);
Code: Select all
kprint("compiled on a %i-bits system",sizeof(int)*8);
goliath /home/martin> ./bitwise64
running on a 64-bits system (runtime)
compiled on a 64-bits system
goliath /home/martin> ./bitwise
running on a 32-bits system (runtime)
compiled on a 32-bits system
Which confirms most course today are biased ...This is true, however most course today will use what I said as gospel.
This will, once again, tell you what the *compiler* assumes from the CPU you're running on, not what the CPU itself is capable of.aladdin wrote: what about counting a pointer size in bits, I think pointer size is equal to word size.
but i m not sure if its a memory word or a CPU word
That would be my assessment. You would have to hard code for the specific platform you're on based on determination of the processor you find by CPUID or whatever the function is on the processor you're coding for, then use optimaized code accordingly.Yeah determining the compilers would not be too difficult but the CPU's word size......... :-\
Maybe That CPUID method is the best bet so far?
Yeah, the philosophy of the propaganda pushed due to information dominance... ;D I get the hint that this is annoying you. Sorry, I don't intend to. Given the exigence will determine the definition used. If all encompassing is the presribed agenda then it is necessary to open up full disclosure about the permutation of possibility. However, given the scope of what has been presented up to this point then a rudimentary explanation would suffice, no? We could also delve into paragraphs too, but then there are so many possibilities. Which would perhaps waste type face on these pages, I expect.Quote:
This is true, however most course today will use what I said as gospel.
Which confirms most course today are biased ...