]>
git.ipfire.org Git - thirdparty/gcc.git/commit
i386: Implement .SAT_SUB for unsigned scalar integers [PR112600]
The following testcase:
unsigned
sub_sat (unsigned x, unsigned y)
{
unsigned res;
res = x - y;
res &= -(x >= y);
return res;
}
currently compiles (-O2) to:
sub_sat:
movl %edi, %edx
xorl %eax, %eax
subl %esi, %edx
cmpl %esi, %edi
setnb %al
negl %eax
andl %edx, %eax
ret
We can expand through ussub{m}3 optab to use carry flag from the subtraction
and generate code using SBB instruction implementing:
unsigned res = x - y;
res &= ~(-(x < y));
sub_sat:
subl %esi, %edi
sbbl %eax, %eax
notl %eax
andl %edi, %eax
ret
PR target/112600
gcc/ChangeLog:
* config/i386/i386.md (ussub<mode>3): New expander.
(sub<mode>_3): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr112600-b.c: New test.