12.9 Operations on SIMD Variables
Some specific C operators can be applied to SIMD variables. They are +, -, *, /, unary minus, ^, |, &, ~. The DSP-enhanced core provides SIMD addition and subtraction instructions for v4i8 and v2q15, allowing the XC32 to generate appropriate instructions for addition and subtraction of v4i8 and v2q15 variables. For other operators, the compiler synthesizes a sequence of instructions. The examples here show compiler-generated SIMD instructions when the appropriate operator is applied to SIMD variables.
Example:
/* v4i8 Addition */
v4i8 test (v4i8 a, v4i8 b)
{
return a + b;
}
# Illustrative generated assembly with optimizations
test:
addu.qb $2, $4, $5
j $31
# ----------------------------------------------------------
Example:
/* v4i8 Subtraction */
v4i8 test (v4i8 a, v4i8 b)
{
return a - b;
}
# Illustrative generated assembly with optimizations
test:
subu.qb $2, $4, $5
j $31
# ----------------------------------------------------------
Example:
/* v2q15 Addition */
v2q15 test (v2q15 a, v2q15 b)
{
return a + b;
}
# Illustrative generated assembly with optimizations
test:
addq.ph $2, $4, $5
j $31
# ----------------------------------------------------------
Example:
/* v2q15 Subtraction */
v2q15 test (v2q15 a, v2q15 b)
{
return a - b;
}
# Illustrative generated assembly with optimizations
test:
subq.ph $2, $4, $5
j $31
In situations where your application requires special integer and fractional calculations and the compiler cannot generate them automatically, you can use the DSP built-in functions (see 29 Built-In Functions).