This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR 10339: Remove unsafe memcmp optimizations
"Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu> writes:
> PS: Do we have a compare_by_pieces for small comparisons analogous
> to the move_by_pieces, clear_by_pieces and store_by_pieces? This
> would be a good optimization for platforms without cmpstr.
We don't, it seems. It would be a good idea though, IMHO. On big
endian, it's obvious, on Alpha for example, you can do something like
diff = x0 ^ x1;
if (diff == 0) return 0;
eq = cmpbge(0, diff);
x1_gt_x0 = cmpbge(x1, x0) & ~eq;
return (x1_gt_x0 & (eq + 1)) ? -1 : 1;
I guess other little endian platforms might have similar tricks.
Additionally, about 90% of all memcmps seem to occur in a boolean
context, where they could be simplified even more.
--
Falk