[PATCH] D33720: [PowerPC] Eliminate compares - add i64 sext/zext handling for SETNE
Guozhi Wei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 17:53:49 PDT 2017
Carrot added a comment.
In https://reviews.llvm.org/D33720#789251, @Carrot wrote:
> In https://reviews.llvm.org/D33720#788925, @nemanjai wrote:
>
> > That's actually not what the SUBFE instruction does. As per the ISA:
> >
> > subfe RT,RA,RB
> > computes
> > RT = ~(RA) + (RB) + CA
> >
> >
> > So in your example, it will be:
> >
> > ~AC + XOR + CARRY
> > ~(~0) + 0 + 0
> >
> >
> > Which of course will just be a zero.
>
>
> Then the document is wrong.
>
> Mathematically, subtraction is
> RB - RA = RB + ~RA + 1
> just like the description in instruction subf.
>
> A subtraction when considering borrowing from lower bit is
> RB - RA - CA = RB + ~RA + 1 - CA = RB + ~RA + !CA
I wrote a small program to test it, you are right, the instruction subfe does
RT = ~(RA) + (RB) + CA
so
RT = (RB) + ~(RA) + CA = (RB) + ~(RA) + 1 - 1 + CA = RB - RA + CA - 1
I can't understand the mathematical meaning of the right side. And how can it be used to implement high precision integer substraction.
Repository:
rL LLVM
https://reviews.llvm.org/D33720
More information about the llvm-commits
mailing list