4.8. Leveraging DMAC instructions

Dual Multiply and Accumulate (DMAC) instructions perform multiply-accumulate operations on two adjacent signed integers (16-bit) simultaneously, optionally shifting the products. A multiply-accumulate operation multiplies two numbers and adds that product to an accumulator.

Table 4.8 Generating DMAC from C source

C source

Assembly output with DMAC

long dmac(int* array1, int* array2, int M)
    // Assert to the compiler that both arrays are 32bit aligned
    _nassert((long)array1 % 2 == 0);
    _nassert((long)array2 % 2 == 0);

    // Assert to the compiler that M is even and > 0
    _nassert((M > 0) && (M % 2 == 0));

    int j;
    long sum = 0;
    for (j=0; j < M; j++)
        sum += (long)array1[j] * array2[j];

    return sum;
        ASR       AL,1
        MOVL      XAR7,XAR5
        ADDB      AL,#-1
        MOVZ      AR5,AL
        MOV       P,#0
        MOVB      ACC,#0
        RPT       AR5
||      DMAC      ACC:P,*XAR4++,*XAR7++
        ADDL      ACC,P

Table 4.8 illustrates an approach to generating the DMAC instruction from C source. Refer to the TMS320C28x Optimizing C/C++ Compiler User’s Guide, Section 3.15, “Compiler Support for Generating DMAC Instructions” for details.