AI Engine-ML v2 Intrinsics User Guide  v2025.1
Loading...
Searching...
No Matches
Merge of Multiply Accumulate operations

We have available ADDMAC and ADDMSC intrinsics (please refer to Multiply Accumulate). For this reason, we include pattern-matching rules in the compiler to merge the operations ADD + MAC/MSC when these patterns are found in the code, i.e.:

For all the available datatypes and configuration parameters (i.e., _conf variants for the addition and multiplication), we have defined the following rules (these are simplified and do not show the actual datatypes or the configuration parameters):

// Pattern-matching rule for add + mac -> addmac
rule(a, b, acc0, acc1) {
tmp = mac(a,b,acc0);
return add(acc1, tmp);
} -> {
return addmac(a,b,acc0,acc1);
}
// Pattern-matching rule for sub + mac -> addmac
rule(a, b, acc0, acc1) {
tmp = mac(a,b,acc0);
return add(acc1, tmp);
} -> {
return addmac_conf(a,b,acc0,acc1,1);
}
// Pattern-matching rule for add + msc -> addmsc
rule(a, b, acc0, acc1) {
tmp = msc(a,b,acc0);
return add(acc1, tmp);
} -> {
return addmsc(a,b,acc0,acc1);
}
// Pattern-matching rule for sub + msc -> addmsc
rule(a, b, acc0, acc1) {
tmp = msc(a,b,acc0);
return add(acc1, tmp);
} -> {
return addmsc_conf(a,b,acc0,acc1,1);
}

All of these rules have been defined for all native datatypes, since emulated datatypes are based on these types.

Note
For these optimizations to take place when using the _conf variants for the mac and add instrinsics, the input values must be known at compile time.