SIMD 8-bit Addition & Subtraction InstructionsΒΆ

__STATIC_FORCEINLINE unsigned long __RV_ADD8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_KADD8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_KSUB8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_RADD8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_RSUB8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_SUB8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_UKADD8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_UKSUB8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_URADD8(unsigned long a, unsigned long b)
__STATIC_FORCEINLINE unsigned long __RV_URSUB8(unsigned long a, unsigned long b)
group NMSIS_Core_DSP_Intrinsic_SIMD_8B_ADDSUB

SIMD 8-bit Addition & Subtraction Instructions.

Based on the types of the four 8-bit arithmetic operations, the SIMD 8-bit add/subtract instructions can be classified into 2 main categories: Addition (four 8-bit addition), and Subtraction (four 8-bit subtraction). Based on the way of how an overflow condition is handled for singed or unsigned operation, the SIMD 8-bit add/subtract instructions can be classified into 5 groups: Wrap-around (dropping overflow), Signed Halving (keeping overflow by dropping 1 LSB bit), Unsigned Halving, Signed Saturation (clipping overflow), and Unsigned Saturation. Together, there are 10 SIMD 8-bit add/subtract instructions.

Functions

__STATIC_FORCEINLINE unsigned long __RV_ADD8(unsigned long a, unsigned long b)

ADD8 (SIMD 8-bit Addition)

Type: SIMD

Syntax:

ADD8 Rd, Rs1, Rs2

Purpose:

Do 8-bit integer element additions simultaneously.

Description:

This instruction adds the 8-bit integer elements in Rs1 with the 8-bit integer elements in Rs2, and then writes the 8-bit element results to Rd.

Note:

This instruction can be used for either signed or unsigned addition.

Operations:

Rd.B[x] = Rs1.B[x] + Rs2.B[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_KADD8(unsigned long a, unsigned long b)

KADD8 (SIMD 8-bit Signed Saturating Addition)

Type: SIMD

Syntax:

KADD8 Rd, Rs1, Rs2

Purpose:

Do 8-bit signed integer element saturating additions simultaneously.

Description:

This instruction adds the 8-bit signed integer elements in Rs1 with the 8-bit signed integer elements in Rs2. If any of the results are beyond the Q7 number range (-2^7 <= Q7 <= 2^7-1), they are saturated to the range and the OV bit is set to 1. The saturated results are written to Rd.

Operations:

res[x] = Rs1.B[x] + Rs2.B[x];
if (res[x] > 127) {
  res[x] = 127;
  OV = 1;
} else if (res[x] < -128) {
  res[x] = -128;
  OV = 1;
}
Rd.B[x] = res[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_KSUB8(unsigned long a, unsigned long b)

KSUB8 (SIMD 8-bit Signed Saturating Subtraction)

Type: SIMD

Syntax:

KSUB8 Rd, Rs1, Rs2

Purpose:

Do 8-bit signed elements saturating subtractions simultaneously.

Description:

This instruction subtracts the 8-bit signed integer elements in Rs2 from the 8-bit signed integer elements in Rs1. If any of the results are beyond the Q7 number range (-2^7 <= Q7 <= 27 -1), they are saturated to the range and the OV bit is set to 1. The saturated results are written to Rd.

Operations:

res[x] = Rs1.B[x] - Rs2.B[x];
if (res[x] > (2^7)-1) {
  res[x] = (2^7)-1;
  OV = 1;
} else if (res[x] < -2^7) {
  res[x] = -2^7;
  OV = 1;
}
Rd.B[x] = res[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_RADD8(unsigned long a, unsigned long b)

RADD8 (SIMD 8-bit Signed Halving Addition)

Type: SIMD

Syntax:

RADD8 Rd, Rs1, Rs2

Purpose:

Do 8-bit signed integer element additions simultaneously. The element results are halved to avoid overflow or saturation.

Description:

This instruction adds the 8-bit signed integer elements in Rs1 with the 8-bit signed integer elements in Rs2. The results are first arithmetically right-shifted by 1 bit and then written to Rd.

Examples:

* Rs1 = 0x7F, Rs2 = 0x7F, Rd = 0x7F
* Rs1 = 0x80, Rs2 = 0x80, Rd = 0x80
* Rs1 = 0x40, Rs2 = 0x80, Rd = 0xE0

Operations:

Rd.B[x] = (Rs1.B[x] + Rs2.B[x]) s>> 1; for RV32: x=3...0, for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_RSUB8(unsigned long a, unsigned long b)

RSUB8 (SIMD 8-bit Signed Halving Subtraction)

Type: SIMD

Syntax:

RSUB8 Rd, Rs1, Rs2

Purpose:

Do 8-bit signed integer element subtractions simultaneously. The results are halved to avoid overflow or saturation.

Description:

This instruction subtracts the 8-bit signed integer elements in Rs2 from the 8-bit signed integer elements in Rs1. The results are first arithmetically right-shifted by 1 bit and then written to Rd.

Examples:

* Rs1 = 0x7F, Rs2 = 0x80, Rd = 0x7F
* Rs1 = 0x80, Rs2 = 0x7F, Rd = 0x80
* Rs1= 0x80, Rs2 = 0x40, Rd = 0xA0

Operations:

Rd.B[x] = (Rs1.B[x] - Rs2.B[x]) s>> 1;
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_SUB8(unsigned long a, unsigned long b)

SUB8 (SIMD 8-bit Subtraction)

Type: SIMD

Syntax:

SUB8 Rd, Rs1, Rs2

Purpose:

Do 8-bit integer element subtractions simultaneously.

Description:

This instruction subtracts the 8-bit integer elements in Rs2 from the 8-bit integer elements in Rs1, and then writes the result to Rd.

Note:

This instruction can be used for either signed or unsigned subtraction.

Operations:

Rd.B[x] = Rs1.B[x] - Rs2.B[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_UKADD8(unsigned long a, unsigned long b)

UKADD8 (SIMD 8-bit Unsigned Saturating Addition)

Type: SIMD

Syntax:

UKADD8 Rd, Rs1, Rs2

Purpose:

Do 8-bit unsigned integer element saturating additions simultaneously.

Description:

This instruction adds the 8-bit unsigned integer elements in Rs1 with the 8-bit unsigned integer elements in Rs2. If any of the results are beyond the 8-bit unsigned number range (0 <= RES <= 28-1), they are saturated to the range and the OV bit is set to 1. The saturated results are written to Rd.

Operations:

res[x] = Rs1.B[x] + Rs2.B[x];
if (res[x] > (2^8)-1) {
  res[x] = (2^8)-1;
  OV = 1;
}
Rd.B[x] = res[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_UKSUB8(unsigned long a, unsigned long b)

UKSUB8 (SIMD 8-bit Unsigned Saturating Subtraction)

Type: SIMD

Syntax:

UKSUB8 Rd, Rs1, Rs2

Purpose:

Do 8-bit unsigned integer elements saturating subtractions simultaneously.

Description:

This instruction subtracts the 8-bit unsigned integer elements in Rs2 from the 8-bit unsigned integer elements in Rs1. If any of the results are beyond the 8-bit unsigned number range (0 <= RES <= 28-1), they are saturated to the range and the OV bit is set to 1. The saturated results are written to Rd.

Operations:

res[x] = Rs1.B[x] - Rs2.B[x];
if (res[x] < 0) {
  res[x] = 0;
  OV = 1;
}
Rd.B[x] = res[x];
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_URADD8(unsigned long a, unsigned long b)

URADD8 (SIMD 8-bit Unsigned Halving Addition)

Type: SIMD

Syntax:

URADD8 Rd, Rs1, Rs2

Purpose:

Do 8-bit unsigned integer element additions simultaneously. The results are halved to avoid overflow or saturation.

Description:

This instruction adds the 8-bit unsigned integer elements in Rs1 with the 8-bit unsigned integer elements in Rs2. The results are first logically right-shifted by 1 bit and then written to Rd.

Examples:

* Ra = 0x7F, Rb = 0x7F, Rt = 0x7F
* Ra = 0x80, Rb = 0x80, Rt = 0x80
* Ra = 0x40, Rb = 0x80, Rt = 0x60

Operations:

Rd.B[x] = (Rs1.B[x] + Rs2.B[x]) u>> 1;
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b

__STATIC_FORCEINLINE unsigned long __RV_URSUB8(unsigned long a, unsigned long b)

URSUB8 (SIMD 8-bit Unsigned Halving Subtraction)

Type: SIMD

Syntax:

URSUB8 Rd, Rs1, Rs2

Purpose:

Do 8-bit unsigned integer element subtractions simultaneously. The results are halved to avoid overflow or saturation.

Description:

This instruction subtracts the 8-bit unsigned integer elements in Rs2 from the 8-bit unsigned integer elements in Rs1. The results are first logically right-shifted by 1 bit and then written to Rd.

Examples:

* Ra = 0x7F, Rb = 0x80 Rt = 0xFF
* Ra = 0x80, Rb = 0x7F Rt = 0x00
* Ra = 0x80, Rb = 0x40 Rt = 0x20

Operations:

Rd.B[x] = (Rs1.B[x] - Rs2.B[x]) u>> 1;
for RV32: x=3...0,
for RV64: x=7...0

Return

value stored in unsigned long type

Parameters
  • [in] a: unsigned long type of value stored in a

  • [in] b: unsigned long type of value stored in b