NEURON
machine.c
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /**************************************************************************
4 **
5 ** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
6 **
7 ** Meschach Library
8 **
9 ** This Meschach Library is provided "as is" without any express
10 ** or implied warranty of any kind with respect to this software.
11 ** In particular the authors shall not be liable for any direct,
12 ** indirect, special, incidental or consequential damages arising
13 ** in any way from use of the software.
14 **
15 ** Everyone is granted permission to copy, modify and redistribute this
16 ** Meschach Library, provided:
17 ** 1. All copies contain this copyright notice.
18 ** 2. All modified copies shall carry a notice stating who
19 ** made the last modification and the date of such modification.
20 ** 3. No charge is made for this software or works derived from it.
21 ** This clause shall not be construed as constraining other software
22 ** distributed on the same medium as this software, nor is a
23 ** distribution fee considered a charge.
24 **
25 ***************************************************************************/
26 
27 /*
28  This file contains basic routines which are used by the functions
29  in meschach.a etc.
30  These are the routines that should be modified in order to take
31  full advantage of specialised architectures (pipelining, vector
32  processors etc).
33  */
34 
35 static char *rcsid = "machine.c,v 1.1 1997/12/04 17:55:33 hines Exp";
36 
37 #include "machine.h"
38 
39 /* __ip__ -- inner product */
40 double __ip__(dp1,dp2,len)
41 register Real *dp1, *dp2;
42 int len;
43 {
44 #ifdef VUNROLL
45  register int len4;
46  register Real sum1, sum2, sum3;
47 #endif
48  register int i;
49  register Real sum;
50 
51  sum = 0.0;
52 #ifdef VUNROLL
53  sum1 = sum2 = sum3 = 0.0;
54 
55  len4 = len / 4;
56  len = len % 4;
57 
58  for ( i = 0; i < len4; i++ )
59  {
60  sum += dp1[4*i]*dp2[4*i];
61  sum1 += dp1[4*i+1]*dp2[4*i+1];
62  sum2 += dp1[4*i+2]*dp2[4*i+2];
63  sum3 += dp1[4*i+3]*dp2[4*i+3];
64  }
65  sum += sum1 + sum2 + sum3;
66  dp1 += 4*len4; dp2 += 4*len4;
67 #endif
68 
69  for ( i = 0; i < len; i++ )
70  sum += dp1[i]*dp2[i];
71 
72  return sum;
73 }
74 
75 /* __mltadd__ -- scalar multiply and add c.f. v_mltadd() */
76 void __mltadd__(dp1,dp2,s,len)
77 register Real *dp1, *dp2;
78 register double s;
79 register int len;
80 {
81  register int i;
82 #ifdef VUNROLL
83  register int len4;
84 
85  len4 = len / 4;
86  len = len % 4;
87  for ( i = 0; i < len4; i++ )
88  {
89  dp1[4*i] += s*dp2[4*i];
90  dp1[4*i+1] += s*dp2[4*i+1];
91  dp1[4*i+2] += s*dp2[4*i+2];
92  dp1[4*i+3] += s*dp2[4*i+3];
93  }
94  dp1 += 4*len4; dp2 += 4*len4;
95 #endif
96 
97  for ( i = 0; i < len; i++ )
98  dp1[i] += s*dp2[i];
99 }
100 
101 /* __smlt__ scalar multiply array c.f. sv_mlt() */
102 void __smlt__(dp,s,out,len)
103 register Real *dp, *out;
104 register double s;
105 register int len;
106 {
107  register int i;
108  for ( i = 0; i < len; i++ )
109  out[i] = s*dp[i];
110 }
111 
112 /* __add__ -- add arrays c.f. v_add() */
113 void __add__(dp1,dp2,out,len)
114 register Real *dp1, *dp2, *out;
115 register int len;
116 {
117  register int i;
118  for ( i = 0; i < len; i++ )
119  out[i] = dp1[i] + dp2[i];
120 }
121 
122 /* __sub__ -- subtract arrays c.f. v_sub() */
123 void __sub__(dp1,dp2,out,len)
124 register Real *dp1, *dp2, *out;
125 register int len;
126 {
127  register int i;
128  for ( i = 0; i < len; i++ )
129  out[i] = dp1[i] - dp2[i];
130 }
131 
132 /* __zero__ -- zeros an array of floating point numbers */
133 void __zero__(dp,len)
134 register Real *dp;
135 register int len;
136 {
137 #ifdef CHAR0ISDBL0
138  /* if a floating point zero is equivalent to a string of nulls */
139  MEM_ZERO((char *)dp,len*sizeof(Real));
140 #else
141  /* else, need to zero the array entry by entry */
142  int i;
143  for ( i = 0; i < len; i++ )
144  dp[i] = 0.0;
145 #endif
146 }
147 
void MEM_ZERO(char *ptr, int len)
Definition: extras.c:58
void __zero__(Real *dp, int len)
Definition: machine.c:133
void __add__(Real *dp1, Real *dp2, Real *out, int len)
Definition: machine.c:113
double __ip__(Real *dp1, Real *dp2, int len)
Definition: machine.c:40
void __smlt__(Real *dp, double s, Real *out, int len)
Definition: machine.c:102
void __mltadd__(Real *dp1, Real *dp2, double s, int len)
Definition: machine.c:76
void __sub__(Real *dp1, Real *dp2, Real *out, int len)
Definition: machine.c:123
static char * rcsid
Definition: machine.c:35
#define Real
Definition: machine.h:189
#define i
Definition: md1redef.h:12