1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<html> 3 4<head> 5<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 6<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.0.0 for Windows"> 7<META http-equiv="Content-Style-Type" content="text/css"> 8<title>The Divider: Overview</title> 9<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css"> 10</head> 11 12<body> 13 14<h1 align="left">Divider: Overview</h1> 15<P>The DS has accelerators for division and square-root computations. This section explains the Divider.</P> 16<HR> 17<P><B>Registers for Division</B></P> 18 19<P>Data registers have been prepared for the dividend, the divisor, the quotient and the remainder.</P> 20<BLOCKQUOTE><IMG src="image_reg_DIV_NUMER.gif" border="0"></BLOCKQUOTE> 21<BLOCKQUOTE><IMG src="image_reg_DIV_DENOM.gif" border="0"></BLOCKQUOTE> 22<BLOCKQUOTE><IMG src="image_reg_DIV_RESULT.gif" border="0"></BLOCKQUOTE> 23<BLOCKQUOTE><IMG src="image_reg_DIVREM_RESULT.gif" border="0"></BLOCKQUOTE> 24<P>The relationship between these registers is as follows:</P> 25<BLOCKQUOTE><IMG src="image_Divider1.gif" border="0"></BLOCKQUOTE> 26<P>Also, a control register is provided to control the Divider.</P> 27<BLOCKQUOTE><IMG src="image_reg_DIVCNT.gif" border="0"></BLOCKQUOTE> 28<HR> 29<P><B>Operations of the Divider</B></P> 30<P>To perform calculations, the Divider sets the dividend and the divisor in the data registers <code>DIV_NUMER</code> and <code>DIV_DENOM</code>. After the control register <code>DIVCNT</code> is appropriately set, the results of the division are saved in <code>DIV_RESULT</code> and <code>DIVREM_RESULT</code>. (In actuality, the calculation begins right after a value has been set in either <code>DIV_NUMER</code>, <code>DIV_DENOM</code>, or <code>DIVCNT</code>. If data is written to the registers during the calculation, the calculation begins all over again.)</P> 31<P>There are three modes for division:<br /><UL> 32<LI>32 bits divided by 32 bits, with the result being a 32-bit quotient and a 32-bit remainder. 33<LI>64 bits divided by 32 bits, with the result being a 64-bit quotient and a 32-bit remainder. 34<LI>64 bits divided by 64 bits, with the result being a 64-bit quotient and a 32-bit remainder. 35</UL> 36<P>You can switch between modes by changing the value set in the <code>MODE</code> bit of the <code>DIVCNT</code> register.</P> 37 38<P>When the Divider begins a division calculation, the <code>DIVCNT</code> register's <code>BUSY</code> bit becomes <code>1</code>. The bit retains that value until the result are computed. When this bit changes to <code>0</code>, the values in the <code>DIV_RESULT</code> and <code>DIVREM_RESULT</code> registers hold the completed computation result.</P> 39<P>When the divisor is <code>0</code>, the <code>DIVCNT</code> register's <code>DIV0</code> bit becomes <code>1</code>. When this is the case, the calculation result is undefined.</P> 40<HR> 41<P><B>Calculation Cycles</B></P> 42<P>The number of cycles required by the Divider to perform a division calculation varies, depending on the division mode.<br /></P> 43 44 45<UL> 46<LI>Mode where the result of dividing 32 bits by 32 bits is obtained as a 64-bit quotient and a 32-bit remainder -- 36 CPU cycles (18 system clock cycles) 47<LI>Mode where the result of dividing 64 bits by 32 bits is obtained as a 64-bit quotient and a 32-bit remainder -- 68 CPU cycles (34 system clock cycles) 48<LI>Mode where the result of dividing 64 bits by 64 bits is obtained as a 64-bit quotient and a 32-bit remainder -- 68 CPU cycles (34 system clock cycles) 49</UL> 50<P>To make more efficient use of the Divider, you can perform another task while waiting for the results after setting the parameters in the Divider's data registers.</P> 51<HR> 52<P><B>Setting the Parameters</B></P> 53<P>Use the <a href="CP_SetDivImm.html"><code>CP_SetDivImm*</code></a> and <code><a href="CP_SetDiv.html">CP_SetDiv*</a></code> functions to set the parameters for the Divider. Both functions can set both the dividend and the divisor. The <a href="CP_SetDiv.html"><CODE>CP_SetDiv*</CODE></a> function can also be used to set the <code>DIVCNT</code> register's division mode.</P> 54<P><CODE><A href="CP_SetDivImm.html">CP_SetDivImm32_32()</A></CODE>, <CODE><A href="CP_SetDivImm.html">CP_SetDivImm64_32()</A></CODE>, <CODE><A href="CP_SetDivImm.html">CP_SetDivImm_64_64()</A></CODE><BR> <CODE><A href="CP_SetDiv.html">CP_SetDiv32_32()</A></CODE>, <CODE><A href="CP_SetDiv.html">CP_SetDiv64_32</A></CODE>, <CODE><A href="CP_SetDiv.html">CP_SetDiv64_64()</A></CODE></P> 55<P>Thus, if you plan to perform a succession of division calculations in the same division mode, you can use the <a href="CP_SetDiv.html"><CODE>CP_SetDiv*</CODE></a> function the first time and then use the <a href="CP_SetDivImm.html"><CODE>CP_SetDivImm*</CODE></a> function for all subsequent calculations.</P> 56<HR> 57<P><B>Waiting for Calculation to End</B></P> 58<P>To check whether the calculation has ended, call the <a href="CP_IsDivBusy.html"><CODE>CP_IsDivBusy</CODE></a> function.</P> 59<P>To wait for the calculation to end, call the <a href="CP_WaitDiv.html"><CODE>CP_WaitDiv</CODE></a> function.</P> 60<HR> 61<P><B>Getting the Calculation Result</B></P> 62<P>To get the quotient of the division calculation, call either the <a href="CP_GetDivResult.html"><CODE>CP_GetDivResult*</CODE></a> or the <a href="CP_GetDivResult.html"><CODE>CP_GetDivResultImm*</CODE></a> function.<br />The former waits until the <code>DIVCNT</code> register is no longer in the <code>BUSY</code> state before fetching the result. The latter acts immediately.</P> 63<P>To get the remainder, call the <a href="CP_GetDivRemainder.html"><CODE>CP_GetDivRemainder</CODE></a> or <a href="CP_GetDivRemainder.html"><CODE>CP_GetDivRemainderImm*</CODE></a> function.<br />The former waits until the <code>DIVCNT</code> register is no longer in the <code>BUSY</code> state before fetching the result. The latter acts immediately.</P> 64 65<HR> 66<P><B>Note</B></P> 67<P> 68When the division mode is "32-bit divided by 32-bit" or "64-bit divided by 32-bit," the upper 32 bits in data registers for which only 32 bits are being used need to be filled with zeros. The TWL-SDK functions do this automatically. However, don't forget to do this when your application directly sets values in the registers.</P> 69<P>If you are using the thread system, the Divider calculations are thread safe by default.</P> 70<HR> 71<P><B>Example</B></P> 72<P>The following is an example using the Divider to conduct a division calculation and then displaying the result.</P> 73<BLOCKQUOTE style="background-color : #eeeeee;"> 74<P><CODE>u32 quotient;<BR> u32 remainder;<BR> <BR> //---- set parameter and div-mode<BR> CP_SetDiv( 0x12345678, 0x300, CP_DIV_32_32BIT_MODE );<BR> <BR> //---- wait for division to finish<BR> CP_WaitDiv();<BR> <BR> //---- display result<BR> quotient = CP_GetDivResultImm32();<BR> remainder = CP_GetDivRemainderImm32();<BR> OS_Printf( "quotient=%x, remainder=%x\n", quotient, remainder );<BR></CODE></P> 75</BLOCKQUOTE> 76 77<HR> 78 79<P><A name="use_in_intr"><B>Precautions on Use Inside Interrupts</B></A></P> 80<P> 81When using a divider or square root calculator inside an interrupt, <B><FONT color="#ff3300">there is a chance that the calculated result for the interrupt source will be destroyed.</FONT></B>Be sure to back up and restore the status of any divider or square root calculator used inside an interrupt with the <A href="../CP_SaveContext.html"><CODE>CP_SaveContext</CODE></A> and <A href="../CP_RestoreContext.html"><CODE>CP_RestoreContext</CODE></A> functions, respectively. When threads are switched, the contents of dividers are also automatically restored from thread context.</FONT></B> 82 83<BLOCKQUOTE style="background-color : #eeeeee;"> 84<P><CODE>void intr_func( void ) <BR> {<BR> CPContext context;<BR> <BR> CP_SaveContext( &context );<BR> CP_SetDiv32_32( 1000, 5 );<BR> CP_WaitDiv();<BR> result = CP_GetDivResult();<BR> CP_RestoreContext( &context );<BR> }</CODE></P> 85</BLOCKQUOTE> 86 87 88<H2>Revision History</H2> 89<P>2008/07/11 Changed notation from Nitro-SDK to TWL-SDK.<BR>2006/08/07 Changed the calculation cycles given to CPU cycles and added a note regarding the use of dividers inside interrupts.<BR> 2004/12/27 Initial version.</P> 90 91<table border="0" height="100%"><tr><td style="background-color : white;"></td></tr></table> 92 93<hr><p>CONFIDENTIAL</p></body> 94</html> 95