Signed overflow optimization hazards in the kernel
Posted Aug 17, 2012 5:05 UTC (Fri) by
jimparis (subscriber, #38647)
In reply to:
Signed overflow optimization hazards in the kernel by PaulMcKenney
Parent article:
Signed overflow optimization hazards in the kernel
Hmmm... If I compile the following with gcc 4.6.1 with -O2:
unsigned long long signed_cast(unsigned long long a, unsigned long long b)
{
return (signed)((unsigned)a - (unsigned)b);
}
...
This is a 32-bit subtraction on 64-bit quantities.
Well, yeah, that's because "(signed)" is casting 32-bit when compiled with -m32. I might be misunderstanding your issue here but it seems you wanted:
unsigned long long signed_cast(unsigned long long a, unsigned long long b)
{
return (signed long long)((unsigned long long)a - (unsigned long long)b);
}
(
Log in to post comments)