<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<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;">I've been looking to see if there's a way to get the instruction below (SMAC) emitted from a higher-level construct, but I'm starting to think this is unrealistic.
<div><br>
</div>
<div>To do so, I'd have to tie-in two other instructions: Firstly, clearing the ASR18 and Y register somewhere near the start of the method, then copying out the value of these registers somewhere near the end of the method, or wherever the value needs to be
used.</div>
<div><br>
</div>
<div>In addition, it would only make sense to use the construct inside a loop of some form, otherwise, some variation on MUL would be better. That would either require detecting the loop, or optimising further down the line to convert the above construct *into*
a simple MUL.</div>
<div><br>
</div>
<div>This now feels to me to be unrealistic and likely to be prone to bugs.</div>
<div><br>
</div>
<div>On that basis, I'm going to go with the simple "assembler-only support" recommended below, unless anyone can recommend a simple way of achieving the above (and direct me to a suitable reference). I can't find anything sufficiently similar in any of the
other processors supported by LLVM. </div>
<div><br>
</div>
<div>Thanks for the feedback</div>
<div>Chris Dewhurst</div>
<div>University of Limerick.<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF44699" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> James Y Knight [jyknight@google.com]<br>
<b>Sent:</b> 18 September 2015 16:39<br>
<b>To:</b> Chris.Dewhurst<br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] multiply-accumulate instruction<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">Do you only want to define assembler syntax for this, or do you need to be able to be able to automatically emit it from some higher level construct? I'd expect the former would be entirely sufficient, in which case this should be sufficient:
<div>
<p class="MsoNormal" style="font-size:12.8000001907349px"><span style="font-size:10pt; font-family:monospace">let Predicates = [HasLeon3, HasLeon4], Defs = [Y, ASR18], Uses = [Y, ASR18] in<u></u><u></u></span></p>
<p class="MsoNormal" style="font-size:12.8000001907349px"><span style="font-size:10pt; font-family:monospace">def SMACrr : F3_1<3, 0b111110,<u></u><u></u></span></p>
<p class="MsoNormal" style="font-size:12.8000001907349px"><span style="font-size:10pt; font-family:monospace"> (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),<u></u><u></u></span></p>
<p class="MsoNormal" style="font-size:12.8000001907349px"><span style="font-size:10pt; font-family:monospace"> "smac $rs1, $rs2, $rd",<u></u><u></u></span></p>
<p class="MsoNormal" style="font-size:12.8000001907349px"><span style="font-size:10pt; font-family:monospace"> [</span><span style="font-family:monospace; font-size:10pt">]>;</span></p>
<p class="MsoNormal" style="font-size:12.8000001907349px"><br>
</p>
<p class="MsoNormal" style="font-size:12.8000001907349px">If you want the latter, I'm not sure how you'd go about being able to pattern-match it, because of the unusual 40 bit accumulate input and output, and the unusual for sparc 16-bit inputs. Hopefully you
don't really need that. :)</p>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Sep 18, 2015 at 10:19 AM, Chris.Dewhurst via llvm-dev
<span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div lang="EN-IE">
<div>
<p class="MsoNormal">I’m trying to define a multiply-accumulate instruction for the LEON processor, a Subtarget of the Sparc target.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The documentation for the processor is as follows:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">===<u></u><u></u></p>
<p class="MsoNormal">To accelerate DSP algorithms, two multiply&accumulate instructions are implemented: UMAC and SMAC. The UMAC performs an unsigned 16-bit multiply, producing a 32-bit result, and adds the result to a 40-bit accumulator made up by the 8 lsb
bits from the %y register and the %asr18 register. The least significant 32 bits are also written to the destination register. SMAC works similarly but performs signed multiply and accumulate. The MAC instructions execute in one clock but have two clocks latency,
meaning that one pipeline stall cycle will be inserted if the following instruction uses the destination register of the MAC as a source operand.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Assembler syntax:<u></u><u></u></p>
<p class="MsoNormal"> smac rs1, reg_imm, rd<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Operation:<u></u><u></u></p>
<p class="MsoNormal"> prod[31:0] = rs1[15:0] * reg_imm[15:0]<u></u><u></u></p>
<p class="MsoNormal"> result[39:0] = (Y[7:0] & %asr18[31:0]) + prod[31:0]<u></u><u></u></p>
<p class="MsoNormal"> (Y[7:0] & %asr18[31:0]) = result[39:0]<u></u><u></u></p>
<p class="MsoNormal"> rd = result[31:0]<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">%asr18 can be read and written using the rdasr and wrasr instructions.<u></u><u></u></p>
<p class="MsoNormal">===<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I have the following in SparcInstrInfo to define the lowering rules for this instruction, but I feel that this isn’t likely to work as I need to somehow tie together the fact that %Y, %ASR18 and %rd are all related to each other in the
output.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; font-family:Monospace">let Predicates = [HasLeon3, HasLeon4], Defs = [Y, ASR18], Uses = [Y, ASR18] in<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; font-family:Monospace">def SMACrr : F3_1<3, 0b111110,<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; font-family:Monospace"> (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2, ASRRegs:$asr18),<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; font-family:Monospace"> "smac $rs1, $rs2, $rd",<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; font-family:Monospace"> [(set i32:$rd,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:Monospace"> (add i32:$asr18, (mul i32:$rs1, i32:$rs2)))] >;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:Monospace"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:Monospace">Perhaps a well-chosen “let Constraints=” might be used here? If so, I’m not sure I know what to put in there. If not, can anyone help me how I might define the lowering rules for this
instruction please?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:Monospace"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:Monospace">Chris Dewhurst, University of Limerick.</span><u></u><u></u></p>
</div>
</div>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</body>
</html>