<div dir="ltr"><br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Mon, May 15, 2017 at 9:35 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, May 10, 2017 at 1:14 PM Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ctopper<br>
Date: Wed May 10 15:01:38 2017<br>
New Revision: 302716<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302716&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=302716&view=rev</a><br>
Log:<br>
[APInt] Add negate helper method to implement twos complement. Use it to shorten code.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/<wbr>APInt.h<br>
    llvm/trunk/lib/Support/APInt.<wbr>cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/<wbr>APInt.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=302716&r1=302715&r2=302716&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/ADT/APInt.h?rev=302716&<wbr>r1=302715&r2=302716&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/ADT/<wbr>APInt.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/<wbr>APInt.h Wed May 10 15:01:38 2017<br>
@@ -1437,6 +1437,12 @@ public:<br>
   /// as "bitPosition".<br>
   void flipBit(unsigned bitPosition);<br>
<br>
+  /// Negate this APInt in place.<br>
+  void negate() {<br>
+    flipAllBits();<br>
+    ++(*this);<br></blockquote><div><br>If you like, you can drop the () here ^ and write: ++*this<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  }<br>
+<br>
   /// Insert the bits from a smaller APInt starting at bitPosition.<br>
   void insertBits(const APInt &SubBits, unsigned bitPosition);<br>
<br>
@@ -1996,8 +2002,7 @@ inline raw_ostream &operator<<(raw_ostre<br>
 }<br>
<br>
 inline APInt operator-(APInt v) {<br>
-  v.flipAllBits();<br>
-  ++v;<br>
+  v.negate();<br>
   return v;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/lib/Support/APInt.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302716&r1=302715&r2=302716&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Support/APInt.cpp?rev=302716&<wbr>r1=302715&r2=302716&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Support/APInt.<wbr>cpp (original)<br>
+++ llvm/trunk/lib/Support/APInt.<wbr>cpp Wed May 10 15:01:38 2017<br>
@@ -1846,10 +1846,8 @@ void APInt::fromString(unsigned numbits,<br>
     *this += digit;<br>
   }<br>
   // If its negative, put it in two's complement form<br>
-  if (isNeg) {<br>
-    --(*this);<br>
-    this->flipAllBits();<br>
-  }<br>
+  if (isNeg)<br>
+    this->negate();<br></blockquote><div><br>Any particular reason for the "this->" qualification? <br></div></div></div></blockquote><div><br></div><div>Nope, I suspect I just pasted "negate" over the original "flipAllBits" without much thought.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 }<br>
<br>
 void APInt::toString(<wbr>SmallVectorImpl<char> &Str, unsigned Radix,<br>
@@ -1927,8 +1925,7 @@ void APInt::toString(<wbr>SmallVectorImpl<cha<br>
     // They want to print the signed version and it is a negative value<br>
     // Flip the bits and add one to turn it into the equivalent positive<br>
     // value and put a '-' in the result.<br>
-    Tmp.flipAllBits();<br>
-    ++Tmp;<br>
+    Tmp.negate();<br>
     Str.push_back('-');<br>
   }<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>
</blockquote></div><br></div></div>