x86: Optimize SSE2 memchr overflow calculation
commit402bf0695218bbe290418b9486b1dd5fe284d903
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 19 May 2017 17:46:29 +0000 (19 10:46 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 19 May 2017 17:48:45 +0000 (19 10:48 -0700)
tree0107d383f8a38c75076dae69996b15b46e13b04a
parent1d71a6315396f6e1cc79a1d7ecca0a559929230a
x86: Optimize SSE2 memchr overflow calculation

SSE2 memchr computes "edx + ecx - 16" where ecx is less than 16.  Use
"edx - (16 - ecx)", instead of satured math, to avoid possible addition
overflow.  This replaces

add %ecx, %edx
sbb %eax, %eax
or %eax, %edx
sub $16, %edx

with

neg %ecx
add $16, %ecx
sub %ecx, %edx

It is the same for x86_64, except for rcx/rdx, instead of ecx/edx.

* sysdeps/i386/i686/multiarch/memchr-sse2.S (MEMCHR): Use
"edx + ecx - 16" to avoid possible addition overflow.
* sysdeps/x86_64/memchr.S (memchr): Likewise.
ChangeLog
sysdeps/i386/i686/multiarch/memchr-sse2.S
sysdeps/x86_64/memchr.S