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>Square Root Coprocessor: Overview</title> 9<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css"> 10</head> 11 12<body> 13 14<h1 align="left">Square Root Coprocessor: Overview</h1> 15<P>The DS has accelerators for division and square-root computations. This section describes the square root coprocessor.</P> 16<HR> 17<P><B>Registers for Square-Root Calculations</B></P> 18 19<P>The following data registers are available for the calculation parameters and calculation results.</P> 20<BLOCKQUOTE><IMG src="image_reg_SQRT_PARAM.gif" border="0"></BLOCKQUOTE> 21<BLOCKQUOTE><IMG src="image_reg_SQRT_RESULT.gif" border="0"></BLOCKQUOTE> 22<P>Also, a control register is available to control the square root coprocessor.</P> 23<BLOCKQUOTE><IMG src="image_reg_SQRTCNT.gif" border="0"></BLOCKQUOTE> 24<HR> 25<P><B>Operations of the Square Root Coprocessor</B></P> 26<P>To perform calculations, the square root coprocessor sets the parameters for the square-root calculation in the data register <code>SQRT_PARAM</code>. After the control register <code>SQRTCNT</code> is appropriately set, the results of the calculation are saved in <code>SQRT_RESULT</code>. (The calculation actually begins as soon as a value is set in either <code>SQRT_PARAM</code> or <code>SQRTCNT</code>. If data get written to the registers during the calculation, the calculation restarts from the beginning.)</P> 27<P>There are two modes for square-root calculations:<UL> 28<LI>Input parameters are 32bit 29<LI>Input parameters are 64bit 30</UL> 31<P>You can switch between these two modes by changing the value set in the <code>MODE</code> bit of the <code>SQRTCNT</code> register.</P> 32 33<P>When the square root coprocessor begins a calculation, the <code>SQRTCNT</code> register's <code>BUSY</code> bit becomes <code>1</code>. The bit remains <code>1</code> until the result is computed. When this bit becomes <code>0</code>, the value in the <code>SQRT_RESULT</code> register holds the correct computation result.</P> 34 35<HR> 36<P><B>Calculation Cycles</B></P> 37<P>The number of cycles required by the square root coprocessor to perform a calculation is the same, regardless of the mode.</P> 38 39 40<UL> 41<LI>Mode where the input parameter is 32 bits -- 26 CPU cycles (13 cycles of the system clock) 42<LI>Mode where the input parameter is 64 bits -- 26 CPU cycles (13 cycles of the system clock) 43</UL> 44<P>To make more efficient use of the square root coprocessor, you can perform another task while waiting for the results after setting the parameters in the registers of the coprocessor.</P> 45<HR> 46<P><B>Setting the Parameters</B></P> 47<P>The parameters for square-root calculations are set using <a href="CP_SetSqrtImm.html"><code>CP_SetSqrtImm*()</code></a> and <code><a href="CP_SetSqrt.html">CP_SetSqrt*()</a></code>. The latter function can also set the <code>SQRTCNT</code> register's calculation mode.</P> 48 49<P>Thus, if you plan to perform a succession of square-root calculations in the same mode, you can use <code><a href="CP_SetSqrt.html">CP_SetSqrt*()</a></code> the first time and then use <code><a href="CP_SetSqrtImm.html">CP_SetSqrtImm*()</a></code> all subsequent times.</P> 50<HR> 51<P><B>Waiting for Calculation to End</B></P> 52<P>To check whether the calculation has ended, call <code><a href="CP_IsSqrtBusy.html">CP_IsSqrtBusy()</a></code>.</P> 53<P>To wait for the calculation to end, call <code><a href="CP_WaitSqrt.html">CP_WaitSqrt()</a></code>.</P> 54<HR> 55<P><B>Getting the Calculation Result</B></P> 56<P>To get the result of the square-root calculation, call either <code><a href="CP_GetSqrtResult.html">CP_GetSqrtResult*()</a></code> or <code><a href="CP_GetSqrtResult.html">CP_GetSqrtResultImm*()</a></code>. The former waits until <code>SQRTCNT</code> is no longer in the BUSY state before getting the result. The latter acts immediately.</P> 57 58 59<HR> 60<P><B>Note</B></P> 61<P>If you are using the thread system, the square-root calculations are thread safe by default.</P> 62<HR> 63<P><B>Example</B></P> 64<P>In this example, the square root coprocessor is used to calculate the square root and the result are displayed.</P> 65<BLOCKQUOTE> 66<P><CODE>u32 result;<BR> <BR> //---- set parameter and sqrt-mode<BR> CP_SetSqrt( 0x12345678, CP_SQRT_32BIT_MODE );<BR> <BR> //---- wait for sqrt operation to finish<BR> CP_WaitSqrt();<BR> <BR> //---- display result<BR> result = CP_GetSqrtResultImm32();<BR> OS_Printf( "result=%x\n", result );<BR></CODE></P> 67</BLOCKQUOTE> 68 69 70<HR> 71 72<P><A name="use_in_intr"><B>Precautions Inside Interrupts</B></A></P> 73<P> 74When using a divider or square root calculator inside an interrupt, there is a chance that the calculated result for the interrupt source will be destroyed. Be sure to back up and restore the status of any divider or square root calculator used inside an interrupt with the <A><CODE>CP_SaveContext</CODE></A> and <A><CODE>CP_RestoreContext</CODE></A> functions, respectively. When threads are switched, the contents of dividers are also automatically restored from thread context.</FONT></B> 75 76<BLOCKQUOTE style="background-color : #eeeeee;"> 77<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> 78</BLOCKQUOTE> 79 80 81<H2>Revision History</H2> 82<P>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> 83 84<table border="0" height="100%"><tr><td style="background-color : white;"></td></tr></table> 85 86<hr><p>CONFIDENTIAL</p></body> 87</html> 88