You copied the Doc URL to your clipboard.

__shadd8 intrinsic

This intrinsic inserts a SHADD8 instruction into the instruction stream generated by the compiler. It enables you to perform four signed 8-bit integer additions, halving the results.

unsigned int __shadd8(unsigned int val1, unsigned int val2)

Where:

val1

holds the first four 8-bit summands

val2

holds the second four 8-bit summands.

The __shadd8 intrinsic returns:

  • the halved addition of the first bytes from each operand, in the first byte of the return value

  • the halved addition of the second bytes from each operand, in the second byte of the return value

  • the halved addition of the third bytes from each operand, in the third byte of the return value

  • the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.

Example:

unsigned int add_and_halve(unsigned int val1, unsigned int val2)
{
  unsigned int res;

    res = __shadd8(val1,val2); /* res[7:0] = (val1[7:0] + val2[7:0]) >> 1
                                  res[15:8] = (val1[15:8] + val2[15:8]) >> 1
                                  res[23:16] = (val1[23:16] + val2[23:16]) >> 1
                                  res[31:24] = (val1[31:24] + val2[31:24]) >> 1
                               */
    return res;
}

See also

Was this page helpful? Yes No