SLAU846B June 2023 – November 2024 MSPM0G1105 , MSPM0G1106 , MSPM0G1107 , MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G1519 , MSPM0G3105 , MSPM0G3105-Q1 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3505 , MSPM0G3505-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1 , MSPM0G3519
The Square32 (SQUARE32) function is a variation of the MPY32 function and performs a square operation on operand OP2 with the 32-bit result in RES1.
The SQUARE32 function can perform the data types shown inTable 6-21.
Data type (Base) | Data type (Result) | Condition |
---|---|---|
Uint32_t | Uint32_t | Result is < 232 - 1 |
Int32_t | Int32_t | Result is > -231 and < 231 - 1 |
SQm.n | SQm.n | Result is not outside the range representable in the chosen data format |
UQm.n | UQm.n |
Table 6-22 shows the operands and descriptions for the SQUARE32 function.
Register (Bit Field) | Value | Description |
---|---|---|
OP1 | User value | Base |
CTL.FUNC | 7h | MPY32 |
CTL.QVAL | User value | Number of fractional bits (unsigned or signed number data type only) |
CTL.OPTYPE | 0h = unsigned operands 1h = signed operands | Operand sign |
RES1 | 32-bit square result | Square result |
Signed integer (int32_t) calculations requires 1 cycle to compute results in RES1 from an OP2 write. Examples of SQUARE32 for int32_t data type are in Table 6-17.
Multiplicand/Multiplier | Square |
---|---|
4 (0x00000004) | 16 (0x00000010) |
-4 (0xFFFFFFFB) | 16 (0x00000010) |
Signed number (SQm.n) calculations requires n cycles to compute results in RES1 from an OP2 write, where n is the number of fractional bits. Examples of division for SQ15.16 are in Table 6-18.
Multiplicand/Multiplier | Square |
---|---|
1.5 (0x00018000) | 2.25 (0x00024000) |
-1.5 (0xFFFE8000) | 2.25 (0x00024000) |
Status, Errors, and Overflow
If the result of the operation is more than 32 bits, STAT.OVF is set to indicate that an overflow has occurred. It will remain set until cleared by writing setting CLR_OVF = 1 in the CLR register.
For signed operation, if result saturation is enabled (CTL.SATEN = 1), in the case of an overflow, the STAT.OVF bit is set and the result saturates to the maximum positive result (0x7FFFFFFF).
For unsigned operation, if result saturation is enabled (CTL.SATEN = 1) in the case of an overflow, the result will be saturated to the maximum positive result (0xFFFFFFFF).
Configuration
To perform a SQUARE32: