<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>multiplication_scs.c Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </center> <hr><h1>multiplication_scs.c</h1><a href="multiplication__scs_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/** Functions for SCS multiplication operations </font> 00002 <font class="comment">@file multiplication_scs.c</font> 00003 <font class="comment"></font> 00004 <font class="comment">@author Defour David David.Defour@ens-lyon.fr</font> 00005 <font class="comment">@author Florent de Dinechin Florent.de.Dinechin@ens-lyon.fr </font> 00006 <font class="comment"></font> 00007 <font class="comment"> This file is part of the SCS library.</font> 00008 <font class="comment">*/</font> 00009 00010 <font class="comment">/*</font> 00011 <font class="comment">Copyright (C) 2002 David Defour and Florent de Dinechin</font> 00012 <font class="comment"></font> 00013 <font class="comment"> This library is free software; you can redistribute it and/or</font> 00014 <font class="comment"> modify it under the terms of the GNU Lesser General Public</font> 00015 <font class="comment"> License as published by the Free Software Foundation; either</font> 00016 <font class="comment"> version 2.1 of the License, or (at your option) any later version.</font> 00017 <font class="comment"></font> 00018 <font class="comment"> This library is distributed in the hope that it will be useful,</font> 00019 <font class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00020 <font class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> 00021 <font class="comment"> Lesser General Public License for more details.</font> 00022 <font class="comment"></font> 00023 <font class="comment"> You should have received a copy of the GNU Lesser General Public</font> 00024 <font class="comment"> License along with this library; if not, write to the Free Software</font> 00025 <font class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font> 00026 <font class="comment"></font> 00027 <font class="comment">*/</font> 00028 00029 <font class="preprocessor">#include "<a class="code" href="scs_8h.html">scs.h</a>"</font> 00030 <font class="preprocessor">#include "<a class="code" href="scs__private_8h.html">scs_private.h</a>"</font> 00031 00032 <font class="preprocessor">#if 0 </font><font class="comment">/* used to help debugging */</font> 00033 <font class="keywordtype">void</font> pr(<font class="keywordtype">char</font>* s,<font class="keywordtype">double</font> d) { 00034 scs_db_number x; 00035 x.d=d; 00036 printf(s);printf(<font class="stringliteral">" "</font>); 00037 printf(<font class="stringliteral">"%8x%8x . 2^%d (%8f %8x %8x) \n"</font>, 00038 (x.i[HI_ENDIAN]&0x000FFFFF)+0x00100000, 00039 x.i[LO_ENDIAN], 00040 (x.i[HI_ENDIAN]>>20)-1023, 00041 x.d, 00042 x.i[HI_ENDIAN], 00043 x.i[LO_ENDIAN]); 00044 } 00045 <font class="preprocessor">#endif</font> 00046 <font class="preprocessor"></font> 00047 00048 <font class="comment">/***************************************************************/</font> 00049 <font class="comment">/* First a few #defines selecting between architectures where integer</font> 00050 <font class="comment"> multiplication is faster than FP multiplication (the normal case)</font> 00051 <font class="comment"> and those where it is the opposite (some Sparcs). The latter</font> 00052 <font class="comment"> doesn't work but might at some point, so the code remains */</font> 00053 00054 <font class="preprocessor">#ifdef SCS_USE_FLT_MULT</font> 00055 <font class="preprocessor"></font><font class="comment">/* Compute the carry of r1, remove it from r1, and add it to r0. This</font> 00056 <font class="comment"> doesn't work: how to get a value truncated using only</font> 00057 <font class="comment"> round-to-nearest FP ? Besides it doesn't work on x86 for at least two</font> 00058 <font class="comment"> reasons : extended precision FP arithmetic, and a #define below. */</font> 00059 <font class="preprocessor">#define SCS_CARRY_PROPAGATE(r1,r0,tmp) \</font> 00060 <font class="preprocessor"> {tmp=((r1-SCS_FLT_TRUNC_CST)+SCS_FLT_SHIFT_CST)-SCS_FLT_SHIFT_CST; r1-= tmp; r0+=tmp*SCS_RADIX_MONE_DOUBLE;} </font> 00061 <font class="preprocessor"></font> 00062 <font class="keyword">typedef</font> <font class="keywordtype">double</font> SCS_CONVERSION_MUL; 00063 00064 <font class="preprocessor">#else </font><font class="comment">/* SCS_USE_FLT_MULT*/</font> 00065 00066 <font class="comment">/* Compute the carry of r1, remove it from r1, and add it to r0 */</font> 00067 <font class="preprocessor">#define SCS_CARRY_PROPAGATE(r1,r0,tmp) \</font> 00068 <font class="preprocessor"> {tmp = r1>>SCS_NB_BITS; r0 += tmp; r1 -= (tmp<<SCS_NB_BITS);} </font> 00069 <font class="preprocessor"></font><font class="keyword">typedef</font> <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> <font class="keywordtype">long</font> <font class="keywordtype">int</font> SCS_CONVERSION_MUL; 00070 <font class="preprocessor">#endif </font><font class="comment">/* SCS_USE_FLT_MULT */</font> 00071 00072 00073 00074 00075 00076 00077 00078 <font class="comment">/************************************************************/</font> 00079 <font class="comment">/* We have unrolled the loops for SCS_NB_WORDS==4 or 8 </font> 00080 <font class="comment"></font> 00081 <font class="comment"> We just wish gcc would do it for us ! There are option switches,</font> 00082 <font class="comment"> but they don't lead to any performance improvement. When they do,</font> 00083 <font class="comment"> this part of the source code will be removed.</font> 00084 <font class="comment"></font> 00085 <font class="comment"> In the meantime, feel free to unroll for other values. */</font> 00086 00087 00088 <font class="comment">/***************************/</font> 00089 <font class="preprocessor">#if (SCS_NB_WORDS==4)</font> 00090 <font class="preprocessor"></font><font class="comment">/***************************/</font> 00091 <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a2">scs_mul</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x, <a class="code" href="structscs.html">scs_ptr</a> y){ 00092 SCS_CONVERSION_MUL val, tmp; 00093 SCS_CONVERSION_MUL r0,r1,r2,r3,r4; 00094 SCS_CONVERSION_MUL x0,x1,x2,x3; 00095 <font class="keywordtype">int</font> y0,y1,y2,y3; 00096 00097 R_EXP = X_EXP * Y_EXP; 00098 R_SGN = X_SGN * Y_SGN; 00099 R_IND = X_IND + Y_IND; 00100 00101 <font class="comment">/* Partial products computation */</font> 00102 x3=X_HW[3]; y3=Y_HW[3]; x2=X_HW[2]; y2=Y_HW[2]; 00103 x1=X_HW[1]; y1=Y_HW[1]; x0=X_HW[0]; y0=Y_HW[0]; 00104 00105 r4 = x3*y1 + x2*y2 + x1*y3; 00106 r3 = x3*y0 + x2*y1 + x1*y2 + x0*y3; 00107 r2 = x2*y0 + x1*y1 + x0*y2; 00108 r1 = x1*y0 + x0*y1 ; 00109 r0 = x0*y0; 00110 00111 val= 0; 00112 <font class="comment">/* Carry Propagate */</font> 00113 SCS_CARRY_PROPAGATE(r4,r3,tmp) 00114 SCS_CARRY_PROPAGATE(r3,r2,tmp) 00115 SCS_CARRY_PROPAGATE(r2,r1,tmp) 00116 SCS_CARRY_PROPAGATE(r1,r0,tmp) 00117 SCS_CARRY_PROPAGATE(r0,val,tmp) 00118 00119 <font class="keywordflow">if</font>(val != 0){ 00120 <font class="comment">/* shift all the digits ! */</font> 00121 R_HW[0] = val; R_HW[1] = r0; R_HW[2] = r1; R_HW[3] = r2; 00122 R_IND += 1; 00123 } 00124 <font class="keywordflow">else</font> { 00125 R_HW[0] = r0; R_HW[1] = r1; R_HW[2] = r2; R_HW[3] = r3; 00126 } 00127 00128 } 00129 00130 00131 <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a3">scs_square</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x){ 00132 SCS_CONVERSION_MUL r0,r1,r2,r3,r4; 00133 SCS_CONVERSION_MUL x0,x1,x2,x3; 00134 SCS_CONVERSION_MUL val, tmp; 00135 00136 00137 R_EXP = X_EXP * X_EXP; 00138 R_IND = X_IND + X_IND; 00139 R_SGN = 1; 00140 00141 <font class="comment">/*</font> 00142 <font class="comment"> * Calcul des PP</font> 00143 <font class="comment"> */</font> 00144 x3=X_HW[3]; x2=X_HW[2]; x1=X_HW[1]; x0=X_HW[0]; 00145 00146 r0 = x0*x0; 00147 r1 = (x0*x1)* 2 ; 00148 r2 = x1*x1 + (x0*x2*2); 00149 r3 = (x1*x2 + x0*x3)* 2; 00150 r4 = x2*x2 + (x1*x3)* 2; 00151 00152 val= 0; 00153 <font class="comment">/* Propagation des retenues */</font> 00154 SCS_CARRY_PROPAGATE(r4,r3,tmp) 00155 SCS_CARRY_PROPAGATE(r3,r2,tmp) 00156 SCS_CARRY_PROPAGATE(r2,r1,tmp) 00157 SCS_CARRY_PROPAGATE(r1,r0,tmp) 00158 SCS_CARRY_PROPAGATE(r0,val,tmp) 00159 00160 <font class="keywordflow">if</font>(val != 0){ 00161 <font class="comment">/* shift all the digits ! */</font> 00162 R_HW[0] = val; R_HW[1] = r0; R_HW[2] = r1; R_HW[3] = r2; 00163 R_IND += 1; 00164 } 00165 <font class="keywordflow">else</font> { 00166 R_HW[0] = r0; R_HW[1] = r1; R_HW[2] = r2; R_HW[3] = r3; 00167 } 00168 00169 } 00170 00171 00172 00173 00174 00175 00176 00177 <font class="comment">/***************************/</font> 00178 <font class="preprocessor">#elif (SCS_NB_WORDS==8)</font> 00179 <font class="preprocessor"></font><font class="comment">/***************************/</font> 00180 <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a2">scs_mul</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x, <a class="code" href="structscs.html">scs_ptr</a> y){ 00181 SCS_CONVERSION_MUL val, tmp; 00182 SCS_CONVERSION_MUL r0,r1,r2,r3,r4,r5,r6,r7,r8; 00183 SCS_CONVERSION_MUL x0,x1,x2,x3,x4,x5,x6,x7; 00184 <font class="keywordtype">int</font> y0,y1,y2,y3,y4,y5,y6,y7; 00185 00186 R_EXP = X_EXP * Y_EXP; 00187 R_SGN = X_SGN * Y_SGN; 00188 R_IND = X_IND + Y_IND; 00189 00190 <font class="comment">/* Partial products computation */</font> 00191 x7=X_HW[7]; y7=Y_HW[7]; x6=X_HW[6]; y6=Y_HW[6]; 00192 x5=X_HW[5]; y5=Y_HW[5]; x4=X_HW[4]; y4=Y_HW[4]; 00193 x3=X_HW[3]; y3=Y_HW[3]; x2=X_HW[2]; y2=Y_HW[2]; 00194 x1=X_HW[1]; y1=Y_HW[1]; x0=X_HW[0]; y0=Y_HW[0]; 00195 00196 r8 = x7*y1 + x6*y2 + x5*y3 + x4*y4 + x3*y5 + x2*y6 + x1*y7; 00197 r7 = x7*y0 + x6*y1 + x5*y2 + x4*y3 + x3*y4 + x2*y5 + x1*y6 + x0*y7; 00198 r6 = x6*y0 + x5*y1 + x4*y2 + x3*y3 + x2*y4 + x1*y5 + x0*y6; 00199 r5 = x5*y0 + x4*y1 + x3*y2 + x2*y3 + x1*y4 + x0*y5; 00200 r4 = x4*y0 + x3*y1 + x2*y2 + x1*y3 + x0*y4 ; 00201 r3 = x3*y0 + x2*y1 + x1*y2 + x0*y3; 00202 r2 = x2*y0 + x1*y1 + x0*y2; 00203 r1 = x1*y0 + x0*y1 ; 00204 r0 = x0*y0 ; 00205 00206 val= 0; 00207 <font class="comment">/* Carry Propagate */</font> 00208 SCS_CARRY_PROPAGATE(r8,r7,tmp) 00209 SCS_CARRY_PROPAGATE(r7,r6,tmp) 00210 SCS_CARRY_PROPAGATE(r6,r5,tmp) 00211 SCS_CARRY_PROPAGATE(r5,r4,tmp) 00212 SCS_CARRY_PROPAGATE(r4,r3,tmp) 00213 SCS_CARRY_PROPAGATE(r3,r2,tmp) 00214 SCS_CARRY_PROPAGATE(r2,r1,tmp) 00215 SCS_CARRY_PROPAGATE(r1,r0,tmp) 00216 SCS_CARRY_PROPAGATE(r0,val,tmp) 00217 00218 <font class="keywordflow">if</font>(val != 0){ 00219 <font class="comment">/* shift all the digits ! */</font> 00220 R_HW[0] = val; R_HW[1] = r0; R_HW[2] = r1; R_HW[3] = r2; 00221 R_HW[4] = r3; R_HW[5] = r4; R_HW[6] = r5; R_HW[7] = r6; 00222 R_IND += 1; 00223 } 00224 <font class="keywordflow">else</font> { 00225 R_HW[0] = r0; R_HW[1] = r1; R_HW[2] = r2; R_HW[3] = r3; 00226 R_HW[4] = r4; R_HW[5] = r5; R_HW[6] = r6; R_HW[7] = r7; 00227 } 00228 00229 } 00230 00231 00232 <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a3">scs_square</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x){ 00233 SCS_CONVERSION_MUL r0,r1,r2,r3,r4,r5,r6,r7,r8; 00234 SCS_CONVERSION_MUL x0,x1,x2,x3,x4,x5,x6,x7; 00235 SCS_CONVERSION_MUL val, tmp; 00236 00237 00238 R_EXP = X_EXP * X_EXP; 00239 R_IND = X_IND + X_IND; 00240 R_SGN = 1; 00241 00242 <font class="comment">/*</font> 00243 <font class="comment"> * Partial products</font> 00244 <font class="comment"> */</font> 00245 x7=X_HW[7]; x6=X_HW[6]; x5=X_HW[5]; x4=X_HW[4]; 00246 x3=X_HW[3]; x2=X_HW[2]; x1=X_HW[1]; x0=X_HW[0]; 00247 00248 r0 = x0*x0; 00249 r1 = (x0*x1)* 2 ; 00250 r2 = x1*x1 + (x0*x2*2); 00251 r3 = (x1*x2 + x0*x3)* 2; 00252 r4 = x2*x2 + (x1*x3 + x0*x4)* 2; 00253 r5 = (x2*x3 + x1*x4 + x0*x5)* 2; 00254 r6 = x3*x3 + (x2*x4 + x1*x5 + x0*x6)* 2; 00255 r7 = (x3*x4 + x2*x5 + x1*x6 + x0*x7)* 2; 00256 r8 = x4*x4 + (x3*x5 + x2*x6 + x1*x7)* 2; 00257 00258 val= 0; 00259 <font class="comment">/* Carry propagation */</font> 00260 SCS_CARRY_PROPAGATE(r8,r7,tmp) 00261 SCS_CARRY_PROPAGATE(r7,r6,tmp) 00262 SCS_CARRY_PROPAGATE(r6,r5,tmp) 00263 SCS_CARRY_PROPAGATE(r5,r4,tmp) 00264 SCS_CARRY_PROPAGATE(r4,r3,tmp) 00265 SCS_CARRY_PROPAGATE(r3,r2,tmp) 00266 SCS_CARRY_PROPAGATE(r2,r1,tmp) 00267 SCS_CARRY_PROPAGATE(r1,r0,tmp) 00268 SCS_CARRY_PROPAGATE(r0,val,tmp) 00269 00270 <font class="keywordflow">if</font>(val != 0){ 00271 <font class="comment">/* shift all the digits ! */</font> 00272 R_HW[0] = val; R_HW[1] = r0; R_HW[2] = r1; R_HW[3] = r2; 00273 R_HW[4] = r3; R_HW[5] = r4; R_HW[6] = r5; R_HW[7] = r6; 00274 R_IND += 1; 00275 } 00276 <font class="keywordflow">else</font> { 00277 R_HW[0] = r0; R_HW[1] = r1; R_HW[2] = r2; R_HW[3] = r3; 00278 R_HW[4] = r4; R_HW[5] = r5; R_HW[6] = r6; R_HW[7] = r7; 00279 } 00280 00281 } 00282 00283 00284 00285 <font class="comment">/***************************/</font> 00286 <font class="preprocessor">#else</font> 00287 <font class="preprocessor"></font><font class="comment">/***************************/</font> 00288 <font class="comment">/* From there on, the normal, unrolled case */</font> 00289 00290 <a name="l00291"></a><a class="code" href="multiplication__scs_8c.html#a2">00291</a> <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a2">scs_mul</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x, <a class="code" href="structscs.html">scs_ptr</a> y){ 00292 SCS_CONVERSION_MUL RES[SCS_NB_WORDS+1]; 00293 SCS_CONVERSION_MUL val, tmp; 00294 <font class="keywordtype">int</font> i, j; 00295 00296 R_EXP = X_EXP * Y_EXP; 00297 R_SGN = X_SGN * Y_SGN; 00298 R_IND = X_IND + Y_IND; 00299 00300 <font class="keywordflow">for</font>(i=0; i<=SCS_NB_WORDS; i++) 00301 RES[i]=0; 00302 00303 <font class="comment">/* Compute only the first half of the partial product. See the</font> 00304 <font class="comment"> unrolled code for an example of what we compute */</font> 00305 00306 <font class="preprocessor">#ifdef SCS_TYPECPU_X86</font> 00307 <font class="preprocessor"></font> <font class="comment">/* This is the only place where there is assembly code to force 64-bit</font> 00308 <font class="comment"> arithmetic. Someday gcc will catch up here, too.</font> 00309 <font class="comment"> */</font> 00310 { 00311 scs_db_number t; 00312 <font class="comment">/* i=0 */</font> 00313 <font class="keywordflow">for</font>(j=0; j<(SCS_NB_WORDS); j++) { 00314 __asm__ <font class="keyword">volatile</font>(<font class="stringliteral">"mull %3"</font> 00315 : <font class="stringliteral">"=a"</font> (t.i[LO_ENDIAN]), <font class="stringliteral">"=d"</font> (t.i[HI_ENDIAN]) 00316 : <font class="stringliteral">"a"</font> (X_HW[0]) , <font class="stringliteral">"g"</font> (Y_HW[j])); 00317 RES[j] += t.l; 00318 } 00319 <font class="comment">/* i = 1..SCS_NB_WORDS-1 */</font> 00320 <font class="keywordflow">for</font>(i=1 ; i<SCS_NB_WORDS; i++){ 00321 <font class="keywordflow">for</font>(j=0; j<(SCS_NB_WORDS-i); j++){ 00322 __asm__ <font class="keyword">volatile</font>(<font class="stringliteral">"mull %3"</font> 00323 : <font class="stringliteral">"=a"</font> (t.i[LO_ENDIAN]), <font class="stringliteral">"=d"</font> (t.i[HI_ENDIAN]) 00324 : <font class="stringliteral">"a"</font> (X_HW[i]) , <font class="stringliteral">"g"</font> (Y_HW[j])); 00325 RES[i+j] += t.l; 00326 } 00327 __asm__ <font class="keyword">volatile</font>(<font class="stringliteral">"mull %3"</font> 00328 : <font class="stringliteral">"=a"</font> (t.i[LO_ENDIAN]), <font class="stringliteral">"=d"</font> (t.i[HI_ENDIAN]) 00329 : <font class="stringliteral">"a"</font> (X_HW[i]) , <font class="stringliteral">"g"</font> (Y_HW[j])); 00330 <font class="comment">/* here j==SCS_NB_WORDS-i */</font> 00331 RES[SCS_NB_WORDS] += t.l; 00332 } 00333 } 00334 00335 <font class="preprocessor">#else </font><font class="comment">/* other architectures */</font> 00336 00337 <font class="comment">/* i=0 */</font> 00338 tmp = X_HW[0]; 00339 <font class="keywordflow">for</font>(j=0; j<(SCS_NB_WORDS); j++) 00340 RES[j] += tmp * Y_HW[j]; 00341 <font class="comment">/* i = 1..SCS_NB_WORDS-1 */</font> 00342 <font class="keywordflow">for</font>(i=1 ; i<SCS_NB_WORDS; i++){ 00343 tmp = X_HW[i]; 00344 <font class="keywordflow">for</font>(j=0; j<(SCS_NB_WORDS-i); j++) 00345 RES[i+j] += tmp * Y_HW[j]; 00346 RES[SCS_NB_WORDS] += tmp * Y_HW[j]; <font class="comment">/* here j==SCS_NB_WORDS-i */</font> 00347 } 00348 <font class="preprocessor">#endif</font><font class="comment">/* SCS_TYPECPU_X86 */</font> 00349 00350 val = 0; 00351 00352 <font class="comment">/* Carry propagate */</font> 00353 <font class="keywordflow">for</font>(i=SCS_NB_WORDS; i>0; i--) 00354 SCS_CARRY_PROPAGATE(RES[i],RES[i-1],tmp) 00355 SCS_CARRY_PROPAGATE(RES[0],val,tmp) 00356 00357 00358 <font class="comment">/* Store the result */</font> 00359 <font class="keywordflow">if</font>(val != 0){ 00360 <font class="comment">/* shift all the digits ! */</font> 00361 R_HW[0] = val; 00362 <font class="keywordflow">for</font>(i=1; i<SCS_NB_WORDS; i++) 00363 R_HW[i] = RES[i-1]; 00364 00365 R_IND += 1; 00366 }<font class="keywordflow">else</font> { 00367 <font class="keywordflow">for</font>(i=0; i<SCS_NB_WORDS; i++) 00368 R_HW[i] = RES[i]; 00369 } 00370 } 00371 00372 00373 00374 00375 00376 00377 <a name="l00378"></a><a class="code" href="multiplication__scs_8c.html#a3">00378</a> <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a3">scs_square</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <a class="code" href="structscs.html">scs_ptr</a> x){ 00379 SCS_CONVERSION_MUL RES[SCS_NB_WORDS+1]; 00380 SCS_CONVERSION_MUL val, tmp; 00381 <font class="keywordtype">int</font> i, j; 00382 00383 00384 R_EXP = X_EXP * X_EXP; 00385 R_SGN = 1; 00386 R_IND = X_IND + X_IND; 00387 00388 <font class="comment">/* Set to 0 intermediate register */</font> 00389 <font class="keywordflow">for</font>(i=0; i<=SCS_NB_WORDS; i++) 00390 RES[i] = 0; 00391 00392 <font class="comment">/* Compute all the double partial products: 2 x_i * x_j, i!=j */</font> 00393 tmp = (SCS_CONVERSION_MUL)X_HW[0]; 00394 <font class="keywordflow">for</font>(j=1; j<SCS_NB_WORDS; j++) 00395 RES[j] += tmp * X_HW[j]; 00396 <font class="keywordflow">for</font>(i=1 ; i<(SCS_NB_WORDS+1)/2; i++){ 00397 tmp = (SCS_CONVERSION_MUL)X_HW[i]; 00398 <font class="keywordflow">for</font>(j=i+1; j<(SCS_NB_WORDS-i); j++) 00399 RES[i+j] += tmp * X_HW[j]; 00400 RES[SCS_NB_WORDS] += tmp * X_HW[SCS_NB_WORDS-i]; 00401 } 00402 00403 <font class="comment">/* All these partial products are double */</font> 00404 <font class="keywordflow">for</font>(i=0; i<=SCS_NB_WORDS; i++) 00405 RES[i] *=2; 00406 00407 <font class="comment">/* Add partial product of the form x_i^2 */</font> 00408 <font class="keywordflow">for</font>(i=0, j=0; i<=SCS_NB_WORDS; i+=2, j++){ 00409 RES[i] += (SCS_CONVERSION_MUL)X_HW[j] * X_HW[j]; 00410 } 00411 00412 val = 0; 00413 <font class="comment">/* Carry propagate */</font> 00414 <font class="keywordflow">for</font>(i=SCS_NB_WORDS; i>0; i--) 00415 SCS_CARRY_PROPAGATE(RES[i],RES[i-1],tmp) 00416 00417 SCS_CARRY_PROPAGATE(RES[0],val,tmp) 00418 00419 00420 <font class="comment">/* Store the result */</font> 00421 <font class="keywordflow">if</font>(val != 0){ 00422 <font class="comment">/* shift all the digits ! */</font> 00423 R_HW[0] = val; 00424 <font class="keywordflow">for</font>(i=1; i<SCS_NB_WORDS; i++) 00425 R_HW[i] = RES[i-1]; 00426 00427 R_IND += 1; 00428 }<font class="keywordflow">else</font> { 00429 <font class="keywordflow">for</font>(i=0; i<SCS_NB_WORDS; i++) 00430 R_HW[i] = RES[i]; 00431 } 00432 00433 } 00434 00435 00436 <font class="comment">/* </font> 00437 <font class="comment"> * #endif corresponding to the test #if (SCS_NB_WORDS==8)</font> 00438 <font class="comment"> */</font> 00439 <font class="preprocessor">#endif</font> 00440 <font class="preprocessor"></font> 00441 00442 00443 00444 00445 <font class="comment">/*</font> 00446 <font class="comment"> Multiply x by an integer val; result is returned in x.</font> 00447 <font class="comment"> */</font> <a name="l00448"></a><a class="code" href="multiplication__scs_8c.html#a4">00448</a> <font class="keywordtype">void</font> <a class="code" href="multiplication__scs_8c.html#a4">scs_mul_ui</a>(<a class="code" href="structscs.html">scs_ptr</a> x, <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> val_int){ 00449 SCS_CONVERSION_MUL val, tmp, vald, rr; 00450 <font class="keywordtype">int</font> i; 00451 00452 <font class="keywordflow">if</font> (val_int == 0) 00453 X_EXP = 0; 00454 00455 vald = val_int; 00456 00457 val = 0; 00458 rr = 0; 00459 <font class="keywordflow">for</font>(i=(SCS_NB_WORDS-1); i>=0; i--){ 00460 val += vald * X_HW[i]; 00461 SCS_CARRY_PROPAGATE(val, rr, tmp) 00462 X_HW[i] = val; 00463 val = rr; 00464 rr = 0; 00465 } 00466 00467 <font class="keywordflow">if</font>(val != 0){ 00468 <font class="comment">/* shift all the digits ! */</font> 00469 <font class="keywordflow">for</font>(i=(SCS_NB_WORDS-1); i>0; i--) 00470 X_HW[i] = X_HW[i-1]; 00471 00472 X_HW[0] = val; 00473 X_IND += 1; 00474 } 00475 00476 <font class="keywordflow">return</font>; 00477 } </pre></div><hr><address align="right"><small>Generated on Tue Jun 17 10:15:51 2003 for SCSLib by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>