/* Given X an unsigned of 32 bits, and Y a bool. Try to translate optimizing * * Y = X > 2147483647; to Y = ((signed)X) < 0; * Y = X >= 2147483648; to Y = ((signed)X) < 0; * * [ Another optimization is to Y = (X >> 31) ] * * The opposite (ELSE): * * Y = X <= 2147483647; to Y = ((signed)X) >= 0; * Y = X < 2147483648; to Y = ((signed)X) >= 0; * * [ Another optimization is to Y = ((~X) >> 31) ] * * 2147483647=0x7FFFFFFF 2147483648=0x80000000 * * The unsigned comparison is become to signed comparison. * * by J.C. Pizarro */
# gcc version 4.1.3 20070326 (prerelease) Full test of isnegative is PASSED. notl %eax shrl $31, %eax xorl $1, %eax IS WORSE THAN shrl $31, %eax --------------------- xorl %eax, %eax cmpl $0, 4(%esp) sets %al IS WORSE THAN movl 4(%esp), %eax shrl $31, %eax ------------------------------------------------------------------------------ Full info with src code and tarball is in http://gcc.gnu.org/ml/gcc/2007-04/msg00317.html I'm sorry, i did want to say 2 billions, not 2 millions. J.C. Pizarro -- Summary: A microoptimization of isnegative or greaterthan2millions. Product: gcc Version: 4.1.3 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: JCPiza at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531