home *** CD-ROM | disk | FTP | other *** search
-
- /**************************************************************************
- **
- ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
- **
- ** Meschach Library
- **
- ** This Meschach Library is provided "as is" without any express
- ** or implied warranty of any kind with respect to this software.
- ** In particular the authors shall not be liable for any direct,
- ** indirect, special, incidental or consequential damages arising
- ** in any way from use of the software.
- **
- ** Everyone is granted permission to copy, modify and redistribute this
- ** Meschach Library, provided:
- ** 1. All copies contain this copyright notice.
- ** 2. All modified copies shall carry a notice stating who
- ** made the last modification and the date of such modification.
- ** 3. No charge is made for this software or works derived from it.
- ** This clause shall not be construed as constraining other software
- ** distributed on the same medium as this software, nor is a
- ** distribution fee considered a charge.
- **
- ***************************************************************************/
-
-
- /*
- Memory port routines: MEM_COPY and MEM_ZERO
- */
-
- /* For BSD 4.[23] environments: using bcopy() and bzero() */
-
- #include "machine.h"
-
- #ifndef MEM_COPY
- void MEM_COPY(from,to,len)
- char *from, *to;
- int len;
- {
- int i;
-
- if ( from < to )
- {
- for ( i = 0; i < len; i++ )
- *to++ = *from++;
- }
- else
- {
- from += len; to += len;
- for ( i = 0; i < len; i++ )
- *(--to) = *(--from);
- }
- }
- #endif
-
- #ifndef MEM_ZERO
- void MEM_ZERO(ptr,len)
- char *ptr;
- int len;
- {
- int i;
-
- for ( i = 0; i < len; i++ )
- *(ptr++) = '\0';
- }
- #endif
-
- /*
- This file contains versions of something approximating the well-known
- BLAS routines in C, suitable for Meschach (hence the `m').
- These are "vanilla" implementations, at least with some consideration
- of the effects of caching and paging, and maybe some loop unrolling
- for register-rich machines
- */
-
- /*
- Organisation of matrices: it is assumed that matrices are represented
- by Real **'s. To keep flexibility, there is also an "initial
- column" parameter j0, so that the actual elements used are
- A[0][j0], A[0][j0+1], ..., A[0][j0+n-1]
- A[1][j0], A[1][j0+1], ..., A[1][j0+n-1]
- .. .. ... ..
- A[m-1][j0], A[m-1][j0+1], ..., A[m-1][j0+n-1]
- */
-
- static char rcsid[] = "$Id: extras.c,v 1.3 1994/01/13 05:45:36 des Exp $";
-
- #include <math.h>
-
- #define REGISTER_RICH 1
-
- /* mblar-1 routines */
-
- /* Mscale -- sets x <- alpha.x */
- void Mscale(len,alpha,x)
- int len;
- double alpha;
- Real *x;
- {
- register int i;
-
- for ( i = 0; i < len; i++ )
- x[i] *= alpha;
- }
-
- /* Mswap -- swaps x and y */
- void Mswap(len,x,y)
- int len;
- Real *x, *y;
- {
- register int i;
- register Real tmp;
-
- for ( i = 0; i < len; i++ )
- {
- tmp = x[i];
- x[i] = y[i];
- y[i] = tmp;
- }
- }
-
- /* Mcopy -- copies x to y */
- void Mcopy(len,x,y)
- int len;
- Real *x, *y;
- {
- register int i;
-
- for ( i = 0; i < len; i++ )
- y[i] = x[i];
- }
-
- /* Maxpy -- y <- y + alpha.x */
- void Maxpy(len,alpha,x,y)
- int len;
- double alpha;
- Real *x, *y;
- {
- register int i, len4;
-
- /****************************************
- for ( i = 0; i < len; i++ )
- y[i] += alpha*x[i];
- ****************************************/
-
- #ifdef REGISTER_RICH
- len4 = len / 4;
- len = len % 4;
- for ( i = 0; i < len4; i++ )
- {
- y[4*i] += alpha*x[4*i];
- y[4*i+1] += alpha*x[4*i+1];
- y[4*i+2] += alpha*x[4*i+2];
- y[4*i+3] += alpha*x[4*i+3];
- }
- x += 4*len4; y += 4*len4;
- #endif
- for ( i = 0; i < len; i++ )
- y[i] += alpha*x[i];
- }
-
- /* Mdot -- returns x'.y */
- double Mdot(len,x,y)
- int len;
- Real *x, *y;
- {
- register int i, len4;
- register Real sum;
-
- #ifndef REGISTER_RICH
- sum = 0.0;
- #endif
-
- #ifdef REGISTER_RICH
- register Real sum0, sum1, sum2, sum3;
-
- sum0 = sum1 = sum2 = sum3 = 0.0;
-
- len4 = len / 4;
- len = len % 4;
-
- for ( i = 0; i < len4; i++ )
- {
- sum0 += x[4*i ]*y[4*i ];
- sum1 += x[4*i+1]*y[4*i+1];
- sum2 += x[4*i+2]*y[4*i+2];
- sum3 += x[4*i+3]*y[4*i+3];
- }
- sum = sum0 + sum1 + sum2 + sum3;
- x += 4*len4; y += 4*len4;
- #endif
-
- for ( i = 0; i < len; i++ )
- sum += x[i]*y[i];
-
- return sum;
- }
-
- #ifndef ABS
- #define ABS(x) ((x) >= 0 ? (x) : -(x))
- #endif
-
- /* Mnorminf -- returns ||x||_inf */
- double Mnorminf(len,x)
- int len;
- Real *x;
- {
- register int i;
- register Real tmp, max_val;
-
- max_val = 0.0;
- for ( i = 0; i < len; i++ )
- < n; k++ )
- {
- /* tmp = A_me[j][k]; */
- tmp = m_entry(A,j,k);
- /* A_me[j][k] = A_me[i][k]; */
- m_set_val(A,j,k,m_entry(A,i,k));
- /* A_me[i][k] = tmp; */
- m_set_val(A,i,k,tmp);
- }
- for ( k = i+1; k < j; k++ )
- {
- /* tmp = A_me[k][j]; */
- tmp = m_entry(A,k,j);
- /* A_me[k][j] = A_me[i][k]; */
- m_set_val(A,k,j,m_entry(A,i,k));
- /* A_me[i][k] = tmp; */
- m_set_val(A,i,k,tmp);
- }
- /* tmp = A_me[i][i]; */
- tmp = m_entry(A,i,i);
- /* A_me[i][i] = A_me[j][j]; */
- m_set_val(A,i,i,m_entry(A,j,j));
- /* A_me[qÉ• Ø : ð! 0" P" † € `E € €+ € —! Ü (" u€ ~ A 0D À ‰À €$ ¤ o☓& €' €( —" ¨" ¨! Y €3 æÐEà⇧ # „ À ¶ `… €2 ™ € €q €$ `É 4 O D ¦ ® €]6 [ @– ø2 €0 3 €2 ☓ H3€ZCœ Àœ ⇦3 À³!Ú Ó ¨3 À‡ y Ï Ã ⇩
- ø3 h 4 Ð À¬Ŵ[$ €* €,h4 @²"