SLAU846A June 2023 – October 2023 MSPM0G1105 , MSPM0G1106 , MSPM0G1107 , MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G3105 , MSPM0G3105-Q1 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3505 , MSPM0G3505-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1
The square root function (SQRT) computes the square root of a number (radicand). The square root is computed incrementally by the number of iterations in the CTL.NUMITER field. A higher number of iterations calculates more accurate results but takes longer to compute.
The radicand must be in UQm.n data type, and it is broken down into two components: an unscaled number (UN) and a scaled number (SN). The unscaled number is the floor of the number, and the scaled number is between 1.0 and 2.0 in UQ2.30 format. The relationship between the scaled number (SN) and unscaled number (UN) is the scale factor (SFACTOR), which is shown in Equation 16.
To calculate the SN and SFACTOR from a radicand in UQm.n format, the algorithm below can be used.
//Compute scale factor and scaled number from radicand
UN = floor(radicand); //unsigned number
SFACTOR = 0; //scale factor
count = 2; //scaled number must be between 1 and 2
do {
SFACTOR++; //incease SFACTOR
count <<= 1; //multiply by 2
} while (count < UN) //repeat until UN is less than count
SN = radicand / (count >> 1); //scale number = radicand / 2^SN
For example, if the 10.375 is the radicand, the unscaled number is 10, SFACTOR = 3 (10.375 / 23 = 1.297), and 1.297 is the scaled number between 1.0 and 2.0.
Table 5-6 shows the configuration registers for the SQRT function.
Register (Bit Field) | Value | Description |
---|---|---|
OP1 | User value | Scaled number (SN) in UQ2.30 format. The scaled number is scaled from the unscaled number, and the scaled number has to be between 1.0 and 2.0. |
CTL.FUNC | 5h | SQRT |
CTL.SFACTOR | User value | Scaling factor n. The scaled number (SN) = (Unscaled number)/2n. This is a signed integer and takes a positive value or negative value in two’s compliment. |
CTL.NUMITER | User value | Number of iterations |
RES1 | 32-bit result | Square root of unscaled number in UQ16.16 format. |
A higher number of iterations (NUMITER) calculates more accurate results but takes longer to compute.
Status, Errors, and Overflow
There are no status, error, or overflow bits for SQRT.
Configuration
To perform a SQRT:
In the CTL register: