~ubuntu-branches/ubuntu/vivid/atlas/vivid

« back to all changes in this revision

Viewing changes to src/blas/reference/level1/ATL_drefnrm2.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-04-13 10:07:52 UTC
  • Revision ID: james.westby@ubuntu.com-20020413100752-va9zm0rd4gpurdkq
Tags: upstream-3.2.1ln
ImportĀ upstreamĀ versionĀ 3.2.1ln

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ---------------------------------------------------------------------
 
2
 *
 
3
 * -- Automatically Tuned Linear Algebra Software (ATLAS)
 
4
 *    (C) Copyright 2000 All Rights Reserved
 
5
 *
 
6
 * -- ATLAS routine -- Version 3.2 -- December 15, 2000
 
7
 *
 
8
 * -- Suggestions,  comments,  bugs reports should be sent to the follo-
 
9
 *    wing e-mail address: atlas@cs.utk.edu
 
10
 *
 
11
 * Author         : Antoine P. Petitet
 
12
 * University of Tennessee - Innovative Computing Laboratory
 
13
 * Knoxville TN, 37996-1301, USA.
 
14
 *
 
15
 * ---------------------------------------------------------------------
 
16
 *
 
17
 * -- Copyright notice and Licensing terms:
 
18
 *
 
19
 *  Redistribution  and  use in  source and binary forms, with or without
 
20
 *  modification, are  permitted provided  that the following  conditions
 
21
 *  are met:
 
22
 *
 
23
 * 1. Redistributions  of  source  code  must retain the above copyright
 
24
 *    notice, this list of conditions and the following disclaimer.
 
25
 * 2. Redistributions in binary form must reproduce  the above copyright
 
26
 *    notice,  this list of conditions, and the  following disclaimer in
 
27
 *    the documentation and/or other materials provided with the distri-
 
28
 *    bution.
 
29
 * 3. The name of the University,  the ATLAS group,  or the names of its
 
30
 *    contributors  may not be used to endorse or promote products deri-
 
31
 *    ved from this software without specific written permission.
 
32
 *
 
33
 * -- Disclaimer:
 
34
 *
 
35
 * THIS  SOFTWARE  IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
36
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING,  BUT NOT
 
37
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
38
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
 
39
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  INDIRECT, INCIDENTAL, SPE-
 
40
 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 
41
 * TO,  PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 
42
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-
 
43
 * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (IN-
 
44
 * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
45
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
46
 *
 
47
 * ---------------------------------------------------------------------
 
48
 */
 
49
/*
 
50
 * Include files
 
51
 */
 
52
#include "atlas_refmisc.h"
 
53
#include "atlas_reflevel1.h"
 
54
 
 
55
double ATL_drefnrm2
 
56
(
 
57
   const int                  N,
 
58
   const double               * X,
 
59
   const int                  INCX
 
60
)
 
61
{
 
62
/*
 
63
 * Purpose
 
64
 * =======
 
65
 *
 
66
 * ATL_drefnrm2 returns the 2-norm of an n-vector x.
 
67
 *
 
68
 * Arguments
 
69
 * =========
 
70
 *
 
71
 * N       (input)                       const int
 
72
 *         On entry, N specifies the length of the vector x. N  must  be
 
73
 *         at least zero. Unchanged on exit.
 
74
 *
 
75
 * X       (input)                       const double *
 
76
 *         On entry,  X  points to the  first entry to be accessed of an
 
77
 *         incremented array of size equal to or greater than
 
78
 *            ( 1 + ( n - 1 ) * abs( INCX ) ) * sizeof(   double  ),
 
79
 *         that contains the vector x. Unchanged on exit.
 
80
 *
 
81
 * INCX    (input)                       const int
 
82
 *         On entry, INCX specifies the increment for the elements of X.
 
83
 *         INCX must not be zero. Unchanged on exit.
 
84
 *
 
85
 * ---------------------------------------------------------------------
 
86
 */
 
87
/*
 
88
 * .. Local Variables ..
 
89
 */
 
90
   register double            absxi, scale = ATL_dZERO,
 
91
                              ssq = ATL_dONE, temp, x0, x1, x2, x3, x4,
 
92
                              x5, x6, x7;
 
93
   double                     * StX = (double *)(X) + N * INCX;
 
94
   register int               i;
 
95
   int                        n = (int)(N), nu;
 
96
   const int                  incX2 = 2 * INCX, incX3 = 3 * INCX,
 
97
                              incX4 = 4 * INCX, incX5 = 5 * INCX,
 
98
                              incX6 = 6 * INCX, incX7 = 7 * INCX,
 
99
                              incX8 = 8 * INCX;
 
100
/* ..
 
101
 * .. Executable Statements ..
 
102
 *
 
103
 */
 
104
   if(    ( N  < 1 ) || ( INCX < 1 ) ) return( ATL_dZERO );
 
105
   else if( N == 1 )                   return( Mdabs( *X ) );
 
106
 
 
107
   while( ( *X == ATL_dZERO ) && ( X != StX ) ) { X += INCX; n--; }
 
108
 
 
109
   if( X == StX ) return( ATL_dZERO );
 
110
 
 
111
   if( ( nu = ( n >> 3 ) << 3 ) != 0 )
 
112
   {
 
113
      StX = (double *)X + nu * INCX;
 
114
 
 
115
      do
 
116
      {
 
117
         x0 = (*X);     x4 = X[incX4]; x1 = X[INCX ]; x5 = X[incX5];
 
118
         x2 = X[incX2]; x6 = X[incX6]; x3 = X[incX3]; x7 = X[incX7];
 
119
 
 
120
         absxi = Mdabs( x0 );
 
121
         if( scale < absxi )
 
122
         {
 
123
            temp = scale / absxi; scale = absxi;
 
124
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
125
         }
 
126
         else { temp = absxi / scale; ssq += temp * temp; }
 
127
 
 
128
         absxi = Mdabs( x4 );
 
129
         if( scale < absxi )
 
130
         {
 
131
            temp = scale / absxi; scale = absxi;
 
132
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
133
         }
 
134
         else { temp = absxi / scale; ssq += temp * temp; }
 
135
 
 
136
         absxi = Mdabs( x1 );
 
137
         if( scale < absxi )
 
138
         {
 
139
            temp = scale / absxi; scale = absxi;
 
140
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
141
         }
 
142
         else { temp = absxi / scale; ssq += temp * temp; }
 
143
 
 
144
         absxi = Mdabs( x5 );
 
145
         if( scale < absxi )
 
146
         {
 
147
            temp = scale / absxi; scale = absxi;
 
148
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
149
         }
 
150
         else { temp = absxi / scale; ssq += temp * temp; }
 
151
 
 
152
         absxi = Mdabs( x2 );
 
153
         if( scale < absxi )
 
154
         {
 
155
            temp = scale / absxi; scale = absxi;
 
156
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
157
         }
 
158
         else { temp = absxi / scale; ssq += temp * temp; }
 
159
 
 
160
         absxi = Mdabs( x6 );
 
161
         if( scale < absxi )
 
162
         {
 
163
            temp = scale / absxi; scale = absxi;
 
164
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
165
         }
 
166
         else { temp = absxi / scale; ssq += temp * temp; }
 
167
 
 
168
         absxi = Mdabs( x3 );
 
169
         if( scale < absxi )
 
170
         {
 
171
            temp = scale / absxi; scale = absxi;
 
172
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
173
         }
 
174
         else { temp = absxi / scale; ssq += temp * temp; }
 
175
 
 
176
         absxi = Mdabs( x7 );
 
177
         if( scale < absxi )
 
178
         {
 
179
            temp = scale / absxi; scale = absxi;
 
180
            ssq  = ATL_dONE + ssq * ( temp * temp );
 
181
         }
 
182
         else { temp = absxi / scale; ssq += temp * temp; }
 
183
 
 
184
         X  += incX8;
 
185
 
 
186
      } while( X != StX );
 
187
   }
 
188
 
 
189
   for( i = n - nu; i != 0; i-- )
 
190
   {
 
191
      x0  = (*X);
 
192
 
 
193
      absxi = Mdabs( x0 );
 
194
      if( scale < absxi )
 
195
      {
 
196
         temp = scale / absxi; scale = absxi;
 
197
         ssq  = ATL_dONE + ssq * ( temp * temp );
 
198
      }
 
199
      else { temp = absxi / scale; ssq += temp * temp; }
 
200
 
 
201
      X  += INCX;
 
202
   }
 
203
   return( scale * sqrt( ssq ) );
 
204
/*
 
205
 * End of ATL_drefnrm2
 
206
 */
 
207
}