Author: Robert Hyatt
Date: 15:01:14 02/10/00
Go up one level in this thread
On February 10, 2000 at 17:50:54, Robert Hyatt wrote:
Thought a sample bit of code would be even better for the TYPE issue
in Tom's question. Here is a simple piece of C code to compute the
absolute value of an integer and return it:
abs(int i) {
int j;
j=(i > 0) ? i : -i;
return(j);
}
Here is what gcc produces to accomplish that:
abs:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl %eax,%edx
negl %edx
cmpl $-1,%eax
cmovle %edx,%eax
movl %ebp,%esp
popl %ebp
ret
Which nicely avoids any branch penalties (except for the ret, but
this doesn't have to be a function of course, it could be inlined
easily.)
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.