[llvm-dev] multiply-accumulate instruction

Chris.Dewhurst via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 18 07:19:48 PDT 2015


I'm trying to define a multiply-accumulate instruction for the LEON processor, a Subtarget of the Sparc target.

The documentation for the processor is as follows:

===
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.

Assembler syntax:
    smac rs1, reg_imm, rd

Operation:
    prod[31:0] = rs1[15:0] * reg_imm[15:0]
    result[39:0] = (Y[7:0] & %asr18[31:0]) + prod[31:0]
    (Y[7:0] & %asr18[31:0]) = result[39:0]
    rd = result[31:0]

%asr18 can be read and written using the rdasr and wrasr instructions.
===

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.

let Predicates = [HasLeon3, HasLeon4], Defs = [Y, ASR18], Uses = [Y, ASR18] in
def SMACrr :  F3_1<3, 0b111110,
                (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2, ASRRegs:$asr18),
                 "smac $rs1, $rs2, $rd",
                 [(set i32:$rd,
                     (add i32:$asr18, (mul i32:$rs1, i32:$rs2)))] >;

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?

Chris Dewhurst, University of Limerick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150918/9c2df28c/attachment.html>


More information about the llvm-dev mailing list