Author: Bruce Moreland
Date: 14:53:14 09/15/01
Go up one level in this thread
On September 15, 2001 at 16:17:52, Vincent Diepeveen wrote:
>Like if i check for 2 non-array/pointer entities for being zero:
>
>if( a & b )
> then do this and that;
I don't know what you mean here, but is you probably don't mean to say "&".
>to produce some crap assembly:
> CMP EAX,0
> JNZ LOOP
> CMP EDX,0
> JNZ LOOP1
This seems to indicate that you meant "&&".
>Now already people will complain: "you don't need special CMP for
>2 different statements". Well they're right.
>
>In fact you don't need 2 compares even. All you need is something
>primitive like:
>
> ADD EAX,EDX
> CMP EAX,0
> JNZ LOOP1
Or perhaps:
add eax, edx
jnz loop1
But this isn't the same thing. If "a" is 1, and "b" is -1, you get a failure
here. Okay, so let's assume they are unsigned values. You can still get a zero
value when adding two things if together they add up to exactly 2^32.
The compiler has to care about this, so I don't see how this is the fault of the
compiler.
Perhaps your problem is with the language. If the language allowed you to
specify a range of values for each data-type, the compiler could catch this.
>However i would need to learn assembly for this or i must rewrite
>my C code. The compiler isn't smart Bruce. The compiler is very stupid
>when talking about source connections. So i have to write:
> if( a+b )
> then do this and that;
This is not the same as "a && b", as stated above, but if you can produce the
same code as you can write in assembly, exactly what is the problem?
>>Using pointers will usually help the compiler out, because it can just indirect
>>through a value, rather than having to deal with scaling the value and adding it
>>to a constant. But in some circumstances, scaling it and adding it to a
>>constant is free.
>
>In general the above construction makes no sense. Optimizing it with a
>pointer is always safer!
Sometimes it doesn't matter.
bruce
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.