You copied the Doc URL to your clipboard.

# `__usad8 `intrinsic

This intrinsic inserts a `USAD8 `instruction into the instruction stream generated by the compiler. It enables you to perform four unsigned 8-bit subtractions, and add the absolute values of the differences together, returning the result as a single unsigned integer.

```unsigned int __usad8(unsigned int `val1`, unsigned int `val2`)
```

Where:

`val1`

holds the first four 8-bit operands for the subtractions

`val2`

holds the second four 8-bit operands for the subtractions.

The `__usad8 `intrinsic returns the sum of the absolute differences of:

• the subtraction of the first byte in the second operand from the first byte in the first operand

• the subtraction of the second byte in the second operand from the second byte in the first operand

• the subtraction of the third byte in the second operand from the third byte in the first operand

• the subtraction of the fourth byte in the second operand from the fourth byte in the first operand.

The sum is returned as a single unsigned integer.

Example:

```unsigned int subtract_add_abs(unsigned int val1, unsigned int val2)
{
unsigned int res;

res = __usad8(val1,val2); /* absdiff1 = val1[7:0] - val2[7:0]
absdiff2 = val1[15:8] - val2[15:8]
absdiff3 = val1[23:16] - val2[23:16]
absdiff4 = val1[31:24] - val2[31:24]
res[31:0] = absdiff1 + absdiff2 + absdiff3
+ absdiff4
*/
return res;
}
```