This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] fold-const trick for gzip





Andrew Pinski writes:
>In gzip, there is a place where the code could be using unconditional code
>instead of conditional code for speed and size (at least on PPC).
>
>It turns (A > (2^n)-1) ? (A - 2^n) : 0 into (-(A >> n))&(A-2^n) where n+1
>is the size of the conditional type in bits.

Roger Sayle writes:
>The second is that any conditional of the form "((signed) A < 0) ? B : 0"
>can be transformed into "B & X" where X is "(signed) A >> n" or in your
>example above, "-((unsigned) A >> n)" which requires an additional
>negation.

So the original  ((A > (2^n)-1) ? (A - 2^n) : 0)  can be if-converted
into  ((unsigned) A >> n) & (A - 2^n).

I'd just like to point out that this is a special case of
unsigned-subtract-and-saturate:  (A >= C ? A - C : 0), or in other words
the form "((signed) A-C < 0) ? 0 : A-C",  which can be if-converted into
(A - C) & !((unsigned) (A-C) >> (wordlength-1)).

This works for any C, not necessarily constant, but is slightly less
efficient than the special case of C == 2^{wordlength-1}, where
((unsigned) (A-C) >> (wordlength-1)) can indeed be simplified into
!((unsigned) A >> (wordlength-1)).

Note that a target may directly support unsigned-subtract-and-saturate,
which is most efficient.

MTCW, Ayal.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]