Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Optimizing C code for speed

Author: Matt Taylor

Date: 19:11:18 01/01/03

Go up one level in this thread


On January 01, 2003 at 21:55:10, Russell Reagan wrote:

>On January 01, 2003 at 19:13:20, Uri Blass wrote:
>
>>1)why it should not matter even with no optimization?
>>
>>Correct me if I am wrong but it seems that with the fastest way you need more
>>memory because you need to remember also x so theoretically it is possible that
>>the computer will crush because of memory problem in the first case when it does
>>not crash in the second case.
>
>It will be in a register if it's a double word sized value. If not it will be in
>the cache. Memory has nothing to do with this problem.
>
>>2)Suppose that you try optimization for minimize size and not maximal speed
>>Am I correct to assume that the compiler will not define the varaible x?
>
>If the data is used often, then it will be in the cache and there will be no
>memory accessed at all. If it is not used often, then it is not a critical part
>of the program most likely (in terms of speed). Besides, the cpu doesn't think
>in terms of "variables". The compiler won't have anything to do with whether or
>not this value is in the cache. That's a hardware thing, not a software thing.

Assumption being that the cache is free -- no. It is cheap, but it isn't free.
Registers are free, though. This is my reasoning and why I prefer using the temp
variable x.

Uri is also right if you think about the stack frame. With optimization, most
compilers will discard x in this code from the stack frame and keep its contents
in a register. This doesn't necessarily tie up an extra register -- after you
finish with the variable, the compiler will reuse the register.

-Matt



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.