NMSIS-Core  Version 1.2.0
NMSIS-Core support for Nuclei processor-based devices
Non-SIMD Q15 saturation ALU Instructions

Non-SIMD Q15 saturation ALU Instructions. More...

Functions

__STATIC_FORCEINLINE long __RV_KADDH (int a, int b)
 KADDH (Signed Addition with Q15 Saturation) More...
 
__STATIC_FORCEINLINE long __RV_KHMBB (unsigned int a, unsigned int b)
 KHMBB (Signed Saturating Half Multiply B16 x B16) More...
 
__STATIC_FORCEINLINE long __RV_KHMBT (unsigned int a, unsigned int b)
 KHMBT (Signed Saturating Half Multiply B16 x T16) More...
 
__STATIC_FORCEINLINE long __RV_KHMTT (unsigned int a, unsigned int b)
 KHMTT (Signed Saturating Half Multiply T16 x T16) More...
 
__STATIC_FORCEINLINE long __RV_KSUBH (int a, int b)
 KSUBH (Signed Subtraction with Q15 Saturation) More...
 
__STATIC_FORCEINLINE unsigned long __RV_UKADDH (unsigned int a, unsigned int b)
 UKADDH (Unsigned Addition with U16 Saturation) More...
 
__STATIC_FORCEINLINE unsigned long __RV_UKSUBH (unsigned int a, unsigned int b)
 UKSUBH (Unsigned Subtraction with U16 Saturation) More...
 

Detailed Description

Non-SIMD Q15 saturation ALU Instructions.

there are 7 Non-SIMD Q15 saturation ALU Instructions

Function Documentation

◆ __RV_KADDH()

__STATIC_FORCEINLINE long __RV_KADDH ( int  a,
int  b 
)

KADDH (Signed Addition with Q15 Saturation)

Type: DSP

Syntax:

KADDH Rd, Rs1, Rs2

Purpose:
Add the signed lower 32-bit content of two registers with Q15 saturation.

Description:
The signed lower 32-bit content of Rs1 is added with the signed lower 32-bit content of Rs2. And the result is saturated to the 16-bit signed integer range of [-2^15, 2^15-1] and then sign- extended and written to Rd. If saturation happens, this instruction sets the OV flag.

Operations:

tmp = Rs1.W[0] + Rs2.W[0];
if (tmp > 32767) {
res = 32767;
OV = 1;
} else if (tmp < -32768) {
res = -32768;
OV = 1
} else {
res = tmp;
}
Rd = SE(tmp[15:0]);
Parameters
[in]aint type of value stored in a
[in]bint type of value stored in b
Returns
value stored in long type

Definition at line 1713 of file core_feature_dsp.h.

1714 {
1715  long result;
1716  __ASM volatile("kaddh %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
1717  return result;
1718 }

References __ASM.

◆ __RV_KHMBB()

__STATIC_FORCEINLINE long __RV_KHMBB ( unsigned int  a,
unsigned int  b 
)

KHMBB (Signed Saturating Half Multiply B16 x B16)

Type: DSP

Syntax:

KHMxy Rd, Rs1, Rs2 (xy = BB, BT, TT)

Purpose:
Multiply the signed Q15 number contents of two 16-bit data in the corresponding portion of the lower 32-bit chunk in registers and then right-shift 15 bits to turn the Q30 result into a Q15 number again and saturate the Q15 result into the destination register. If saturation happens, an overflow flag OV will be set.

Description:
Multiply the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs1 with the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs2. The Q30 result is then right- shifted 15-bits and saturated into a Q15 value. The Q15 value is then sing-extended and written into Rd. When both the two Q15 inputs are 0x8000, saturation will happen. The result will be saturated to 0x7FFF and the overflow flag OV will be set.

Operations:

aop = Rs1.H[0]; bop = Rs2.H[0]; // KHMBB
aop = Rs1.H[0]; bop = Rs2.H[1]; // KHMBT
aop = Rs1.H[1]; bop = Rs2.H[1]; // KHMTT
If (0x8000 != aop | 0x8000 != bop) {
Mresult[31:0] = aop * bop;
res[15:0] = Mresult[30:15];
} else {
res[15:0] = 0x7FFF;
OV = 1;
}
Rd = SE32(res[15:0]); // Rv32
Rd = SE64(res[15:0]); // RV64
Parameters
[in]aunsigned int type of value stored in a
[in]bunsigned int type of value stored in b
Returns
value stored in long type

Definition at line 2535 of file core_feature_dsp.h.

2536 {
2537  long result;
2538  __ASM volatile("khmbb %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
2539  return result;
2540 }

References __ASM.

◆ __RV_KHMBT()

__STATIC_FORCEINLINE long __RV_KHMBT ( unsigned int  a,
unsigned int  b 
)

KHMBT (Signed Saturating Half Multiply B16 x T16)

Type: DSP

Syntax:

KHMxy Rd, Rs1, Rs2 (xy = BB, BT, TT)

Purpose:
Multiply the signed Q15 number contents of two 16-bit data in the corresponding portion of the lower 32-bit chunk in registers and then right-shift 15 bits to turn the Q30 result into a Q15 number again and saturate the Q15 result into the destination register. If saturation happens, an overflow flag OV will be set.

Description:
Multiply the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs1 with the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs2. The Q30 result is then right- shifted 15-bits and saturated into a Q15 value. The Q15 value is then sing-extended and written into Rd. When both the two Q15 inputs are 0x8000, saturation will happen. The result will be saturated to 0x7FFF and the overflow flag OV will be set.

Operations:

aop = Rs1.H[0]; bop = Rs2.H[0]; // KHMBB
aop = Rs1.H[0]; bop = Rs2.H[1]; // KHMBT
aop = Rs1.H[1]; bop = Rs2.H[1]; // KHMTT
If (0x8000 != aop | 0x8000 != bop) {
Mresult[31:0] = aop * bop;
res[15:0] = Mresult[30:15];
} else {
res[15:0] = 0x7FFF;
OV = 1;
}
Rd = SE32(res[15:0]); // Rv32
Rd = SE64(res[15:0]); // RV64
Parameters
[in]aunsigned int type of value stored in a
[in]bunsigned int type of value stored in b
Returns
value stored in long type

Definition at line 2588 of file core_feature_dsp.h.

2589 {
2590  long result;
2591  __ASM volatile("khmbt %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
2592  return result;
2593 }

References __ASM.

◆ __RV_KHMTT()

__STATIC_FORCEINLINE long __RV_KHMTT ( unsigned int  a,
unsigned int  b 
)

KHMTT (Signed Saturating Half Multiply T16 x T16)

Type: DSP

Syntax:

KHMxy Rd, Rs1, Rs2 (xy = BB, BT, TT)

Purpose:
Multiply the signed Q15 number contents of two 16-bit data in the corresponding portion of the lower 32-bit chunk in registers and then right-shift 15 bits to turn the Q30 result into a Q15 number again and saturate the Q15 result into the destination register. If saturation happens, an overflow flag OV will be set.

Description:
Multiply the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs1 with the top or bottom 16-bit Q15 content of the lower 32-bit portion in Rs2. The Q30 result is then right- shifted 15-bits and saturated into a Q15 value. The Q15 value is then sing-extended and written into Rd. When both the two Q15 inputs are 0x8000, saturation will happen. The result will be saturated to 0x7FFF and the overflow flag OV will be set.

Operations:

aop = Rs1.H[0]; bop = Rs2.H[0]; // KHMBB
aop = Rs1.H[0]; bop = Rs2.H[1]; // KHMBT
aop = Rs1.H[1]; bop = Rs2.H[1]; // KHMTT
If (0x8000 != aop | 0x8000 != bop) {
Mresult[31:0] = aop * bop;
res[15:0] = Mresult[30:15];
} else {
res[15:0] = 0x7FFF;
OV = 1;
}
Rd = SE32(res[15:0]); // Rv32
Rd = SE64(res[15:0]); // RV64
Parameters
[in]aunsigned int type of value stored in a
[in]bunsigned int type of value stored in b
Returns
value stored in long type

Definition at line 2641 of file core_feature_dsp.h.

2642 {
2643  long result;
2644  __ASM volatile("khmtt %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
2645  return result;
2646 }

References __ASM.

◆ __RV_KSUBH()

__STATIC_FORCEINLINE long __RV_KSUBH ( int  a,
int  b 
)

KSUBH (Signed Subtraction with Q15 Saturation)

Type: DSP

Syntax:

KSUBH Rd, Rs1, Rs2

Purpose:
Subtract the signed lower 32-bit content of two registers with Q15 saturation.

Description:
The signed lower 32-bit content of Rs2 is subtracted from the signed lower 32-bit content of Rs1. And the result is saturated to the 16-bit signed integer range of [-2^15, 2^15-1] and then sign-extended and written to Rd. If saturation happens, this instruction sets the OV flag.

Operations:

tmp = Rs1.W[0] - Rs2.W[0];
if (tmp > (2^15)-1) {
res = (2^15)-1;
OV = 1;
} else if (tmp < -2^15) {
res = -2^15;
OV = 1
} else {
res = tmp;
}
Rd = SE(res[15:0]);
Parameters
[in]aint type of value stored in a
[in]bint type of value stored in b
Returns
value stored in long type

Definition at line 5543 of file core_feature_dsp.h.

5544 {
5545  long result;
5546  __ASM volatile("ksubh %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
5547  return result;
5548 }

References __ASM.

◆ __RV_UKADDH()

__STATIC_FORCEINLINE unsigned long __RV_UKADDH ( unsigned int  a,
unsigned int  b 
)

UKADDH (Unsigned Addition with U16 Saturation)

Type: DSP

Syntax:

UKADDH Rd, Rs1, Rs2

Purpose:
Add the unsigned lower 32-bit content of two registers with U16 saturation.

Description:
The unsigned lower 32-bit content of Rs1 is added with the unsigned lower 32-bit content of Rs2. And the result is saturated to the 16-bit unsigned integer range of [0, 2^16-1] and then sign-extended and written to Rd. If saturation happens, this instruction sets the OV flag.

Operations:

tmp = Rs1.W[0] + Rs2.W[0];
if (tmp > (2^16)-1) {
tmp = (2^16)-1;
OV = 1;
}
Rd = SE(tmp[15:0]);
Parameters
[in]aunsigned int type of value stored in a
[in]bunsigned int type of value stored in b
Returns
value stored in unsigned long type

Definition at line 11566 of file core_feature_dsp.h.

11567 {
11568  unsigned long result;
11569  __ASM volatile("ukaddh %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
11570  return result;
11571 }

References __ASM.

◆ __RV_UKSUBH()

__STATIC_FORCEINLINE unsigned long __RV_UKSUBH ( unsigned int  a,
unsigned int  b 
)

UKSUBH (Unsigned Subtraction with U16 Saturation)

Type: DSP

Syntax:

UKSUBH Rd, Rs1, Rs2

Purpose:
Subtract the unsigned lower 32-bit content of two registers with U16 saturation.

Description:
The unsigned lower 32-bit content of Rs2 is subtracted from the unsigned lower 32-bit content of Rs1. And the result is saturated to the 16-bit unsigned integer range of [0, 2^16-1] and then sign-extended and written to Rd. If saturation happens, this instruction sets the OV flag.

Operations:

tmp = Rs1.W[0] - Rs2.W[0];
if (tmp > (2^16)-1) {
tmp = (2^16)-1;
OV = 1;
}
else if (tmp < 0) {
tmp = 0;
OV = 1;
}
Rd = SE(tmp[15:0]);
Parameters
[in]aunsigned int type of value stored in a
[in]bunsigned int type of value stored in b
Returns
value stored in unsigned long type

Definition at line 12159 of file core_feature_dsp.h.

12160 {
12161  unsigned long result;
12162  __ASM volatile("uksubh %0, %1, %2" : "=r"(result) : "r"(a), "r"(b));
12163  return result;
12164 }

References __ASM.

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