int's, int's, everywhere!

Started by
7 comments, last by Thrump 22 years, 3 months ago
I started a project in C a while ago, and any time I need an integer, I used int, regardless of the size needed. Now looking back, I want to start changing them to a more logical size. My question is, does the size of arguments affect speed of a function call? I know generally yes, but is void Function(Int32); slower than void Function(Int8); How does this depend on the processor''s word size?
Advertisement
most likely the compiler will pass "int8" as a 32-bit integer (assuming Intel x86 architecture), it will just sign/zero extend it.

this all really depends on a CPU''s ability to manipulate data not equal to the processor word size.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Mordern computers are optimized for 32bit dwords.

So int32 will be faster.
Kill mages first!
No, I think it wouldn''t.
But I can''t really know that because I don''t know your target hardware.

If you''re using an 8-bit integer, it wouldn''t be faster but your program would be smaller.

Of course there is some dependence of size and speed and if programs are smaller they sometimes execute faster ( if you''re using more memory ( RAM ) then available and others ... ).
But usually the first choice ( 32-bit ) would be faster.

One thing you have to know is your goal and that there''s nearly always a possibility to trade size for speed.

And if you really want to know why this is like it is,
you''ll have to study your target processor ( to look up the size of the data bus, the execution unit and stuff like that ) and your algo
( for checking if it wouldn''t be faster when you use precalculated / preprocessed data ).
Askadar: "Mordern computers are optimized for 32bit dwords."

are you sure?

i would remove the word "computers" and replace it with "Windows based PC''s".

because the Itanium, various Alpha chips, various MIPS RISC chips (including the PS2), etc. are NOT 32-bit.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Well, I was assuming the average gaming pc.

Your definition isn''t correct either. There are WinNT versions for the Alpha processor.
Kill mages first!
AP: actually what VC++ 6.0 (enterprise) does is if the value is a constant (i.e. 10), it uses "push 0ah". if the value is a variable (i.e. __int8 j) it uses "mov al, [j]" & "push eax".

also if i define a function "__cdecl void func(__int8 i)".
when the compiler cleans up the stack is uses "add esp, 4".

this is because Windows wants to keep the stack 32-bit aligned.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
yeah, as well as MIPS, PowerPC, Motorola 68xxx, etc.

my point is Visual Studio optimizes for 32-bit because majority of Windows users are using Intel Pentium base processors.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Actually, VIsual Studios optimizes to the word length of the target machine. Visual Studio for RISC ALPHA is 64bit word length aligned, IIRC.

This topic is closed to new replies.

Advertisement