CP_SetDivImm*

C Specification

#include <nitro/cp.h>

void CP_SetDivImm32_32( u32 numer, u32 denom );
void CP_SetDivImm64_32( u64 numer, u32 denom );
void CP_SetDivImm64_64( u64 numer, u64 denom );

Arguments

numer Numerator of fraction. Represents dividend of division here.
denom Denominator of fraction. Represents divisor of division here.

Return Values

None

Description

Sets parameters for division. It does not set the division mode but merely stores the dividend and the divisor in registers. The three division modes are shown below.

Division Mode Calculation Results Calculation Cycles CPU Cycle Conversion
CP_DIV_32_32BIT_MODE 32-bit divided by 32-bit Quotient 32-bit, remainder 32-bit 18 cycles 36 cycles
CP_DIV_64_32BIT_MODE 64-bit divided by 32-bit Quotient 64-bit, remainder 32-bit 34 cycles 68 cycles
CP_DIV_64_64BIT_MODE 64-bit divided by 64-bit Quotient 64-bit, remainder 64-bit 34 cycles 68 cycles

Caution: With the Divider, sometimes the value is overwritten in the interrupt. If the division parameters are set up and an interrupt occurs during division when using a divider, the original calculated result will be broken. Therefore, if you are using the divider in an interrupt, the status of the divider needs to be temporarily stored/restored using CP_SaveContext() and CP_RestoreContext().
The status of dividers is also automatically saved/restored when threads are switched.


Example: Restore the Divider status

intr_func( void ) 
      {
        CPContext context;
        
        CP_SaveContext( &context );
        CP_SetDiv32_32( 1000, 5 );
        CP_WaitDiv();
        result = CP_GetDivResult();
        CP_RestoreContext( &context );
      }

Internal Operation

Stores values in DIV_NUMER(0x4000290) and DIV_DENOM(0x4000298) of the IO register.

See Also

CP_SetDiv*, CP_IsDivBusy, CP_WaitDiv, CP_GetDivResult*, CP_GetDivRemainder*

Revision History

08/09/2006 Added a note regarding use inside interrupts.
11/02/2004 Corrected the IO register address used for internal operations.
01/09/2004 Added content.
12/01/2003 Initial version.


CONFIDENTIAL