This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, i386]: Implement atomic_fetch_sub
On Fri, Aug 3, 2012 at 10:02 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Fri, Aug 3, 2012 at 9:24 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Fri, Aug 3, 2012 at 8:40 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>
>>> We can implement atomic_fetch_sub with atomic_fetch_add and inverted
>>> operand 2. However, we have to prevent overflows with negation, so
>>> only const_int operand 2 is allowed in the expander.
>
> Why do you need to prevent overflows?
Because we change (x)sub to (x)add, so for SImode operation - without
overflow check -
sub 0x80000000, %eax
gets changed to
add 0x80000000, %eax.
The same reasoning goes for dynamic negation: for neg %eax,%eax value
0x80000000 stays the same, but we have changed (x)sub to an (x)add in
the code stream.
Uros.