This is the mail archive of the
mailing list for the GCC project.
cmpstrnsi pattern should check for zero byte?
- From: Aaron Sawdey <acsawdey at linux dot vnet dot ibm dot com>
- To: GCC <gcc at gcc dot gnu dot org>
- Cc: olegendo at gcc dot gnu dot org, nickc at redhat dot com
- Date: Tue, 01 Nov 2016 17:28:55 -0500
- Subject: cmpstrnsi pattern should check for zero byte?
- Authentication-results: sourceware.org; auth=none
I am about to put up a patch to make a change to the way
builtins.c/expand_builtin_strncmp does things. At present it will only
expand if one of the strings is a constant, and the length it passes in
is MIN(len, strlen(constant string)+1). I want to change it so that it
will also attempt to expand strncmp where neither of the input strings
is a constant.
What I ran into is that the i386 target cmpstrnsi pattern uses repz
cmpsb which does not check for the zero byte and thus depends on
expand_builtin_strncmp to arrange things so the length is not past the
end of both strings.
SH and RX are the other two targets that have cmpstrnsi patterns.
My reading of sh_expand_cmpnstr() in sh-mem.cc is that the code that it
emits will both look for a zero byte and compare the strings so it will
not have trouble with this change to expand_builtin_strncmp.
It also looks to me like rx.md emits the "scmpu" instruction to do the
comparison. The RX manual I found showed pseudocode for scmpu that
shows it both checks for zero byte as well as comparing the strings.
If this isn't correct, please let me know here or on the patch itself.
Aaron Sawdey, Ph.D. firstname.lastname@example.org
050-2/C113 (507) 253-7520 home: 507/263-0782
IBM Linux Technology Center - PPC Toolchain