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 divide function (DIV) computes with a known dividend and divisor.
Table 6-7 shows the data types that the DIV function can perform.
Data Type (Dividend and Divisor) | Data Type (Quotient) | Data Type (Remainder) |
---|---|---|
Uint32_t | Uint32_t | Uint32_t |
Int32_t | Int32_t | Int32_t |
SQm.n | SQm.n | N/A |
UQm.n | UQm.n | N/A |
Table 6-8 shows the configuration registers for the DIV function.
Register (Bit Field) | Value | Description |
---|---|---|
OP1 | User value | Dividend |
OP2 | User value | Divisor |
CTL.FUNC | 4h | DIV |
CTL.QVAL | User value | Number of fractional bits (unsigned or signed number data type only) |
CTL.OPTYPE | 0 = unsigned operands 1 = signed operands | Operand sign |
RES1 | 32-bit result | Quotient (same data type as dividend and divisor) |
RES2 | 32-bit result | Remainder (same data type as dividend and divisor) |
Signed integer (int32_t) calculations requires 4 cycles to compute results in RES1 and RES2 from an OP2 write. Examples of DIV for int32_t are in Table 6-9.
Dividend | Divisor | Quotient | Remainder |
---|---|---|---|
15 (0x0000000F) | 2 (0x00000002) | 7 (0x00000007) | 1 (0x00000001) |
-15 (0xFFFFFFF1) | 2 (0x00000002) | -7 (0xFFFFFFF9) | -1 (0xFFFFFFFF) |
15 (0x0000000F) | -2 (0xFFFFFFFE) | -7 (0xFFFFFFF9) | 1 (0x00000001) |
-15 (0xFFFFFFF1) | -2 (0xFFFFFFFE) | 7 (0x00000007) | -1 (0xFFFFFFFF) |
Signed number (SQm.n) calculations requires n cycles to compute results in RES1 and RES2 from an OP2 write, where n is the number of fractional bits. Examples of DIV for SQ15.16 are in Table 6-10.
Dividend | Divisor | Quotient | Remainder |
---|---|---|---|
7.5 (0x00078000) | 4.5 (0x00048000) | 1.666657 (0x0001AAAA) | N/A |
-7.5 (0xFFF88000) | 4.5 (0x00048000) | -1.666657 (0xFFFE5556) | N/A |
7.5 (0x00078000) | -4.5 (0xFFFB8000) | -1.666657 (0xFFFE5556) | N/A |
-7.5 (0xFFF88000) | -4.5 (0xFFFB8000) | 1.666657 (0x0001AAAA) | N/A |
Status, Errors, and Overflow
If the divisor is 0, then the STATUS.ERR flag is set.
If the result of the operation is more than 32 bits, STATUS.OVF is set to indicate that an overflow has occurred. It will remain set until cleared by writing a 1 to CLR.CLR_OVF.
For signed 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 (0x7FFFFFFF) and the minimum negative result (0x80000000).
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 DIV:
Set the divisor in OP2.