Wednesday, July 05, 2006

Bug in Intel Core Duo CPU?

Check it out. The following test case prints "The result is 2" on a MacBook Pro (Intel Core Duo) but "The result is 1" on a Pentium 4:
#include 

int main(char **argv, int argc)
{
int result;

__asm__("movl $0x10000000,%%eax; shl $3,%%eax; jno x; movl $1,%0; jmp end; x: movl $2,%0; end:"
:"=c"(result)::"%eax");

printf("The result is %d\n",result);
}

The SHL instruction is not setting the overflow flag on the Core Duo.

Update: Andy Hefner in #lisp says "overflow flag is undefined if the shift count is not equal to 1". So its not a bug after all.

1 comment:

Andy Hefner said...

To be accurate, I should amend that statement. The overflow flag is undefined if the shift count is >1. It is defined for 0 or 1.