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: [patch] fold-const.c: Fold (A & ~3) - (A & 3) into (A ^ 3) - 3.


> Attached is a patch to fold (A & ~B) - (A & B) into (A ^ B) - B, where
> B is any power of 2 minus 1.

This actually works for any B:

(A & ~B) - (A & B) = (A & ~B) + ~(A & B) + 1
                   = (A & ~B) + (~A & B) + ~B + 1
                   = (A & ~B) + (~A & B) - B
                   = (A ^ B) - B.


Segher


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