Word size
Re:Word size
i think that the only way is to detect the processor type then to get word size from docs or CPU specifications
Re:Word size
or maybe u can try to put the maximum value on a register then calculate how many bits it holds.
Code: Select all
xor reg, reg ;put 0 in reg
dec reg ;put 1111111.....b in reg
;then calculate how many bits there is
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Word size
@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.
The opcode you give to the processor *tells* the word size to be used. However, i'd expect CPUID to tell you how that through extension flags.
from /usr/src/linux/include/asm/cpufeature.h
32 bits processors have a sticky bit somewhere in flags that ppl can check to know if it's 386+ or 286-only processor around.
The opcode you give to the processor *tells* the word size to be used. However, i'd expect CPUID to tell you how that through extension flags.
from /usr/src/linux/include/asm/cpufeature.h
Code: Select all
#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
Re:Word size
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)
If you are wondering how to determine the size of the registers then, for x86 types, using a method of determining the processor like CPUID can help you to determine the register size used. On Motorola type processors I am unfamiliar. Certain embedded processors don't have a way to determine them,so you would devlope directly for that platform (using documentation).
Of course, since I'm uncertain for sure what you're asking then perhaps I am off base. Please specify what you are requestiing.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Word size
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.
"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
Re:Word size
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.
int i = 0;
--i;
// count the bits
int should be word-size (note: non intel specific usage of the word "word") on every type of processors, ensured by the compiler.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Word size
bit counting might be easier done with the "bsr" or "bsl" instructions - at least on i386 processors.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:Word size
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
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Word size
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);
The same program (bitwise.c, collecting code above), either compiled on a 32bits system (./bitwise) or on a 64bits system (./bitwise64) give the following results on a x86-64 AMD system
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.
Re:Word size
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
if this can be used we should declare a null pointer then decrease it and count bits
but i m not sure if its a memory word or a CPU word
if this can be used we should declare a null pointer then decrease it and count bits
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Word size
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
Re:Word size
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?
Maybe That CPUID method is the best bet so far?
Only Human
Re:Word size
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 ...