Automatic Generation of DMAC Instructions

The compiler automatically generates DMAC instructions if the compiler recognizes the C-language statements as a DMAC opportunity and the compiler can verify that the data addresses being operated upon are 32-bit aligned. This is the best scenario, because it requires no code modification aside from data alignment pragmas. The following is an example:

int src1[N], src2[N]; #pragma DATA_ALIGN(src1,2); // int arrays must be 32-bit aligned #pragma DATA_ALIGN(src2,2); {...} int i; long res = 0; for (i = 0; i < N; i++) // N must be a known even constant res += (long)src1[i] * src2[i]; // Arrays must be accessed via array indices

At optimization levels >= -O2, the compiler generates a RPT || DMAC instruction for the example code above if N is a known even constant.

DMAC instructions can also shift the product left by 1 or right by 1 to 6 before accumulation. For example:

for (i = 0; i < N; i++) res += (long)src1[i] * src2[i] >> 1; // product shifted right by 1