<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"></p>
<div>I'm having trouble understanding how APInts should be used.</div>
<div><br>
</div>
<div>The APInt documentation states that it 'is a functional replacement for common</div>
<div>case unsigned integer type', but I'm not seeing this because the internal logic</div>
<div>is that the value is always treated as negative if the most significant bit is</div>
<div>set.</div>
<div><br>
</div>
<div>I'm interested in an add or sub that could be using a negative value. I have the</div>
<div>following snippet of code to demostrate the issue:</div>
<div><br>
</div>
<div>APInt Positive(8, 128, false);</div>
<div>APInt Negative(8, -128, true);</div>
<div>LLVM_DEBUG(dbgs() << "Positive: " << Positive << "\n");</div>
<div>LLVM_DEBUG(dbgs() << "Negative: " << Negative << "\n");</div>
<div>LLVM_DEBUG(dbgs() << "0 + Positive = " << 0 + Positive << "\n");</div>
<div>LLVM_DEBUG(dbgs() << "0 - Positive = " << 0 - Positive << "\n");</div>
<div>LLVM_DEBUG(dbgs() << "0 + Negative = " << 0 + Negative << "\n");</div>
<div>LLVM_DEBUG(dbgs() << "0 - Negative = " << 0 - Negative << "\n");</div>
<div><br>
</div>
<div>The output is:</div>
<div><br>
</div>
<div>Positive: -128</div>
<div>Negative: -128</div>
<div>0 + Positive = -128</div>
<div>0 - Positive = -128</div>
<div>0 + Negative = -128</div>
<div>0 - Negative = -128</div>
<div><br>
</div>
<div>I know there are operators for when the sign matters, but from my example,</div>
<div>either my understanding or the functionality is broken. If an abstract</div>
<div>structure exists, why does the MSB still represent the sign? Especially</div>
<div>when it's supposed to be an unsigned type!</div>
<br>
<p></p>
<p style="margin-top:0;margin-bottom:0">Thanks,</p>
<p style="margin-top:0;margin-bottom:0">Sam</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p></p>
<p style="font-family:"Times New Roman""><span style="font-family:Calibri,Helvetica,sans-serif">Sam Parker</span></p>
<span style="font-family:Calibri,Helvetica,sans-serif"></span>
<p style="font-family:"Times New Roman""><span style="font-family:Calibri,Helvetica,sans-serif">Compilation Tools Engineer | Arm</span></p>
<span style="font-family:Calibri,Helvetica,sans-serif"></span>
<p style="font-family:"Times New Roman""><span style="font-family:Calibri,Helvetica,sans-serif">. . . . . . . . . . . . . . . . . . . . . . . . . . .</span></p>
<span style="font-family:Calibri,Helvetica,sans-serif"></span>
<p style="font-family:"Times New Roman""><span style="font-family:Calibri,Helvetica,sans-serif">Arm.com</span></p>
<p></p>
</div>
</div>
</div>
</body>
</html>