# CP_SetSqrt*

## C Specification

  `#include <nitro/cp.h>`
  `void CP_SetSqrt64( u64 param );`
  `void CP_SetSqrt32( u32 param );`

## Arguments

param | Value of the square root to be calculated.

## Return Values

None.

## Description

Sets the parameters for square root calculations. Sets the square root calculation mode first, and then stores parameters. There are two calculation modes, as follows:

Square Root Calculation Mode | Calculation | Calculation Cycles | CPU Cycle Conversion
--- | --- | --- | ---
CP_SQRT_32BIT_MODE | Square root calculation of 32-bit value | 13 cycles | 26 cycles
CP_SQRT_64BIT_MODE | Square root calculation of 64-bit value | 13 cycles | 26 cycles

Note: With the square root calculator, sometimes the value is overwritten in the interrupt. If the parameters are set up and an interrupt occurs during square root calculation when using a square root calculator, the original calculated result will be broken. Therefore, if you are using the square root calculator in an interrupt, its status needs to be temporarily saved/restored using `CP_SaveContext` and `CP_RestoreContext`.
The status of square root calculators is also automatically saved/restored when threads are switched.

> Example: Restore the square root calculator status

>     intr_func( void )
>           {
>             CPContext context;

>             CP_SaveContext( &context );
>             CP_SetSqrt32( 1000 );
>             CP_WaitSqrt();
>             result = CP_GetSqrtResult32();
>             CP_RestoreContext( &context );
>           }

## Internal Operation

`Stores values in `SQRTCNT(0x40002B0)` and `SQRT_PARAM(0x40002B8)` of the IO register.
`

## See Also

`CP_SetSqrtImm*, CP_IsSqrtBusy, CP_WaitSqrt, CP_GetSqrtResult*, CP_SaveContext, CP_RestoreContext`

## Revision History

03/08/2005 Standardized the Japanese term for "interrupt."
05/06/2004 Added description about status restoration.
01/09/2004 Added content.
12/01/2003 Initial version.

CONFIDENTIAL