diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2024-07-09 17:34:25 +0200 |
---|---|---|
committer | Uros Bizjak <ubizjak@gmail.com> | 2024-07-09 17:35:20 +0200 |
commit | d17889dbffd5dcdb2df22d42586ac0363704e1f1 (patch) | |
tree | c69cee19a91852ff486d176bbbd380ee094b628e /gcc/doc | |
parent | 2d6e6a77e840b7b93d1f18708aa08ced8b46282e (diff) | |
download | gcc-d17889dbffd5dcdb2df22d42586ac0363704e1f1.zip gcc-d17889dbffd5dcdb2df22d42586ac0363704e1f1.tar.gz gcc-d17889dbffd5dcdb2df22d42586ac0363704e1f1.tar.bz2 |
i386: Implement .SAT_TRUNC for unsigned integers
The following testcase:
unsigned short foo (unsigned int x)
{
_Bool overflow = x > (unsigned int)(unsigned short)(-1);
return ((unsigned short)x | (unsigned short)-overflow);
}
currently compiles (-O2) to:
foo:
xorl %eax, %eax
cmpl $65535, %edi
seta %al
negl %eax
orl %edi, %eax
ret
We can expand through ustrunc{m}{n}2 optab to use carry flag from the
comparison and generate code using SBB:
foo:
cmpl $65535, %edi
sbbl %eax, %eax
orl %edi, %eax
ret
or CMOV instruction:
foo:
movl $65535, %eax
cmpl %eax, %edi
cmovnc %edi, %eax
ret
gcc/ChangeLog:
* config/i386/i386.md (@cmp<mode>_1): Use SWI mode iterator.
(ustruncdi<mode>2): New expander.
(ustruncsi<mode>2): Ditto.
(ustrunchiqi2): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/i386/sattrunc-1.c: New test.
Diffstat (limited to 'gcc/doc')
0 files changed, 0 insertions, 0 deletions