<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,
<div><br>
</div>
<div>I have tried to add the LEON CASArr instruction as part of a Sparc Subtarget to the Sparc instructions. Almost all the tests I've written have worked without problem, but when I try to encode the instruction, it doesn't work.
<div><br>
</div>
<div>I modelled it on the CASrr instruction which it basically mimics in every regard except the ASI.</div>
<div><br>
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div>
<div><font face="Courier New" size="2">// The CAS instruction, unlike other instructions, only comes in a </font></div>
</div>
<div>
<div><font face="Courier New" size="2">// form which requires an ASI be provided. The ASI value hardcoded </font></div>
</div>
<div>
<div><font face="Courier New" size="2">// here is ASI_PRIMARY, the default unprivileged ASI for SparcV9.</font></div>
</div>
<div>
<div><font face="Courier New" size="2">let Predicates = [HasV9], Constraints = "$swap = $rd", asi = 0b10000000 in</font></div>
</div>
<div>
<div><font face="Courier New" size="2">  def CASrr: F3_1_asi<3, 0b111100,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                                     IntRegs:$swap),</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 "cas [$rs1], $rs2, $rd",</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 [(set i32:$rd,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                     (atomic_cmp_swap iPTR:$rs1, i32:$rs2, i32:$swap))], </font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 NoItinerary>;</font></div>
</div>
<div>
<div><font face="Courier New" size="2"><br>
</font></div>
</div>
<div>
<div><font face="Courier New" size="2"><br>
</font></div>
</div>
<div>
<div><font face="Courier New" size="2">// CASA supported on some LEON3 and all LEON4 processors. Same pattern as</font></div>
</div>
<div>
<div><font face="Courier New" size="2">// CASrr, above, but with a different ASI.</font></div>
</div>
<div>
<div><font face="Courier New" size="2">// Requires the use of SparcV8's default ASI, 0xA ("User Data").</font></div>
</div>
<div>
<div><font face="Courier New" size="2">let Predicates = [CASASupported], Constraints = "$swap = $rd", asi = 0b00001010 in</font></div>
</div>
<div>
<div><font face="Courier New" size="2">  def CASArr: F3_1_asi<3, 0b111100,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                                     IntRegs:$swap),</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 "casa [$rs1], $rs2, $rd",</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 [(set i32:$rd,</font></div>
</div>
<div>
<div><font face="Courier New" size="2">                     (atomic_cmp_swap iPTR:$rs1, i32:$rs2, i32:$swap))], </font></div>
</div>
<div>
<div><font face="Courier New" size="2">                 NoItinerary>;</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>However, when I get the following trying to encode the instruction to binary:</div>
<div><br>
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div>
<div><font face="Courier New">$ llvm-mc leon-atomic-instructions.s -arch=sparc -mcpu=gr712rc -show-encoding</font></div>
</div>
<div>
<div><font face="Courier New"><span class="Apple-tab-span" style="white-space:pre"></span>.text</font></div>
</div>
<div>
<div><font face="Courier New">leon-atomic-instructions.s:4:15: error: invalid operand for instruction</font></div>
</div>
<div>
<div><font face="Courier New">        casa [%i0], %l6, %o2</font></div>
</div>
</blockquote>
<div><br>
</div>
<div>The only operative line in leon-atomic-instructions is the one that throws the error.
<font face="Courier New">gr712rc </font>is the name of the CPU I've added, which switches on the "<font face="Courier New">CASASupported</font>" feature that you can see in the instruction definition above. All this part of the system works, so it's almost
 certainly nothing there - plus I've performed many tests to verify this.</div>
<div><br>
</div>
<div>I've also run the pre-existing test in test/MC/Sparc: llvm-mc sparcv9-atomic-instructions -arch=sparc -show-encoding. This works fine and I don't get any such error ("<span style="font-size: 13.3333px;">invalid operand for instruction") </span><span style="font-size: 10pt;">on
 "</span><span style="font-size: 10pt;"><font face="Courier New">cas [%i0], %l6, %o2</font>".</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">Can anyone explain why I get a difference between the two and what I need to change?</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">Best Regards,</span></div>
<div><span style="font-size: 10pt;">Chris Dewhurst.</span></div>
<div><span style="font-size: 10pt;">University of Limerick.</span></div>
</div>
</div>
</body>
</html>