Here we will briefly describe several important arithmetic operation commands.
1. Horizontal addition command
The ssse3 Instruction Set adds commands that add integers horizontally, similar to the floating point commands of sse3.
Phaddd
Add a 32-bit unsigned integer in the horizontal direction of the Register
Phaddw
Add the registers horizontally according to the unsigned 16-bit integer
Phaddsw
Registers are saturated based on 16-digit integers in the horizontal direction.
Phsubd
The registers are subtracted horizontally by unsigned 32-bit integers.
Phsubw
The registers are subtracted horizontally by unsigned 16-bit integers.
Phsubsw
Perform saturation subtraction based on 16-digit integers in the horizontal direction of registers
Example:
PhaddwDeST, SRC
Add and package the source and target data horizontally, applicable to MMX and SSE registers:
Dest [] includest [31: 16] + Dest [];
Dest [31: 16] includest [63: 48] + Dest [47: 32];
Dest [47: 32] parse SRC [31: 16] + SRC [];
Dest [63: 48]Using SRC [63: 48] + SRC [47: 32];
The XMM registers are similar.
2. Saturated byte multiplication and addition command
Pmaddubsw
Perform multiplication based on the location of the byte. When the adjacent two numbers are added, the 16-bit signed number is saturated.
Example:Pmaddubsw DEST, SRC
Obtains the signed saturation value of the multiplication of the source and target data. It is applicable to MMX and SSE registers:
Dest [] ← saturatetosword (SRC [] * DST [] + SRC [] * DST []);
Dest [31: 16] ← saturatetosword (SRC [31: 24] * DST [31: 24] + SRC [23:16] * DST [23:16]);
Dest [47: 32] ← saturatetosword (SRC [47: 40] * DST [47: 40] + SRC [39: 32] * DST [39: 32]);
Dest [63: 48] ← saturatetosword (SRC [63: 56] * DST [63: 56] + SRC [55: 48] * DST [55: 48]);
The XMM registers are similar.
3. Use 16-bit multiplication to obtain a high value
Pmulhrsw
This command is specially designed for fixed-point operations.
Use pseudoCodeThe description is more convenient:
Signed Short A [ 8 ] ; // Input Signed Short B [ 8 ] ; // Input B Signed Short R [ 8 ] ; // Output R For ( I = 0 ; I < 8 ; I ++ ) R [ I ] = Int16 ( ( A [ I ] * B [ I ] + Zero X 4000 ) > 15 ) ;
This is a rounding shift operation in q15 fixed-point format,It is quite common in speech signal processing.
4. Absolute Value operation
Pabsb/pabsw/pabsd
Example:Pabsw
Take the absolute value of the source data, applicable to MMX and SSE registers:
Dest [] Reverse ABS (SRC []);
Dest [31: 16] Reverse ABS (SRC [31: 16]);
Dest [47: 32] Reverse ABS (SRC [47: 32]);
Dest [63: 48] Reverse ABS (SRC [63: 48]);
The XMM registers are similar.
5. byte mixed selection command
Pshufb
This command is flexible and used to select any byte of the source register and re-arrange it to the destination register.
The pseudocode is described as follows:
Char A [ 16 ] ; // Input Char B [ 16 ] ; // Input B Char R [ 16 ] ; // Output R For ( I = 0 ; I < 16 ; I ++ ) R [ I ] = ( B [ I ] < 0 ) ? 0 : A [ B [ I ] % 16 ] ;
If the high sign bit of the source operand is 1, that is, when the source operand is smaller than zero, the destination register is assigned to zero.
Otherwise, select the destination operand based on the lower 4 bits of the source operand and copy it to the corresponding bits of the destination operand.