NMSIS-Core  Version 1.2.0
NMSIS-Core support for Nuclei processor-based devices
SIMD 8-bit Addition & Subtraction Instructions

SIMD 8-bit Addition & Subtraction Instructions. More...

Functions

__STATIC_FORCEINLINE unsigned long __RV_ADD8 (unsigned long a, unsigned long b)
 ADD8 (SIMD 8-bit Addition) More...
 
__STATIC_FORCEINLINE unsigned long __RV_KADD8 (unsigned long a, unsigned long b)
 KADD8 (SIMD 8-bit Signed Saturating Addition) More...
 
__STATIC_FORCEINLINE unsigned long __RV_KSUB8 (unsigned long a, unsigned long b)
 KSUB8 (SIMD 8-bit Signed Saturating Subtraction) More...
 
__STATIC_FORCEINLINE unsigned long __RV_RADD8 (unsigned long a, unsigned long b)
 RADD8 (SIMD 8-bit Signed Halving Addition) More...
 
__STATIC_FORCEINLINE unsigned long __RV_RSUB8 (unsigned long a, unsigned long b)
 RSUB8 (SIMD 8-bit Signed Halving Subtraction) More...
 
__STATIC_FORCEINLINE unsigned long __RV_SUB8 (unsigned long a, unsigned long b)
 SUB8 (SIMD 8-bit Subtraction) More...
 
__STATIC_FORCEINLINE unsigned long __RV_UKADD8 (unsigned long a, unsigned long b)
 UKADD8 (SIMD 8-bit Unsigned Saturating Addition) More...
 
__STATIC_FORCEINLINE unsigned long __RV_UKSUB8 (unsigned long a, unsigned long b)
 UKSUB8 (SIMD 8-bit Unsigned Saturating Subtraction) More...
 
__STATIC_FORCEINLINE unsigned long __RV_URADD8 (unsigned long a, unsigned long b)
 URADD8 (SIMD 8-bit Unsigned Halving Addition) More...
 
__STATIC_FORCEINLINE unsigned long __RV_URSUB8 (unsigned long a, unsigned long b)
 URSUB8 (SIMD 8-bit Unsigned Halving Subtraction) More...
 

Detailed Description

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.

Function Documentation

◆ __RV_ADD8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 449 of file core_feature_dsp.h.

450 {
451  unsigned long result;
452  __ASM volatile("add8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
453  return result;
454 }

References __ASM.

◆ __RV_KADD8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 1553 of file core_feature_dsp.h.

1554 {
1555  unsigned long result;
1556  __ASM volatile("kadd8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
1557  return result;
1558 }

References __ASM.

◆ __RV_KSUB8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 5382 of file core_feature_dsp.h.

5383 {
5384  unsigned long result;
5385  __ASM volatile("ksub8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
5386  return result;
5387 }

References __ASM.

◆ __RV_RADD8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 6303 of file core_feature_dsp.h.

6304 {
6305  unsigned long result;
6306  __ASM volatile("radd8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
6307  return result;
6308 }

References __ASM.

◆ __RV_RSUB8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 6719 of file core_feature_dsp.h.

6720 {
6721  unsigned long result;
6722  __ASM volatile("rsub8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
6723  return result;
6724 }

References __ASM.

◆ __RV_SUB8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 10668 of file core_feature_dsp.h.

10669 {
10670  unsigned long result;
10671  __ASM volatile("sub8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
10672  return result;
10673 }

References __ASM.

◆ __RV_UKADD8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 11417 of file core_feature_dsp.h.

11418 {
11419  unsigned long result;
11420  __ASM volatile("ukadd8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
11421  return result;
11422 }

References __ASM.

◆ __RV_UKSUB8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 12005 of file core_feature_dsp.h.

12006 {
12007  unsigned long result;
12008  __ASM volatile("uksub8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
12009  return result;
12010 }

References __ASM.

◆ __RV_URADD8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 12894 of file core_feature_dsp.h.

12895 {
12896  unsigned long result;
12897  __ASM volatile("uradd8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
12898  return result;
12899 }

References __ASM.

◆ __RV_URSUB8()

__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
Parameters
[in]aunsigned long type of value stored in a
[in]bunsigned long type of value stored in b
Returns
value stored in unsigned long type

Definition at line 13284 of file core_feature_dsp.h.

13285 {
13286  unsigned long result;
13287  __ASM volatile("ursub8 %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
13288  return result;
13289 }

References __ASM.

__ASM
#define __ASM
Pass information from the compiler to the assembler.
Definition: nmsis_gcc.h:55