Browse Source

use `SWAP' macro

pre-master-46
rlar 10 years ago
parent
commit
bd0bc3038b
  1. 4
      src/frontend/com_compose.c
  2. 4
      src/frontend/com_measure2.c
  3. 8
      src/frontend/evaluate.c
  4. 21
      src/frontend/plotting/clip.c
  5. 5
      src/frontend/plotting/grid.c
  6. 9
      src/frontend/plotting/plotit.c
  7. 10
      src/frontend/plotting/x11.c
  8. 8
      src/frontend/trannoise/FastNorm3.c
  9. 6
      src/frontend/trannoise/wallace.c
  10. 9
      src/maths/ni/niaciter.c
  11. 25
      src/maths/ni/niditer.c
  12. 9
      src/maths/ni/niiter.c
  13. 8
      src/maths/poly/polyfit.c
  14. 9
      src/misc/wlist.c
  15. 6
      src/spicelib/analysis/cktpzset.c
  16. 6
      src/spicelib/analysis/distoan.c
  17. 8
      src/spicelib/devices/cpl/cplsetup.c
  18. 7
      src/spicelib/devices/jfet/jfetdset.c
  19. 5
      src/spicelib/devices/mesa/mesaload.c
  20. 8
      src/spicelib/devices/soi3/soi3load.c
  21. 8
      src/spicelib/devices/txl/txlsetup.c

4
src/frontend/com_compose.c

@ -378,9 +378,7 @@ com_compose(wordlist *wl)
} }
if (startgiven && stopgiven && (start > stop)) { if (startgiven && stopgiven && (start > stop)) {
tt = start;
start = stop;
stop = tt;
SWAP(double, start, stop);
reverse = TRUE; reverse = TRUE;
} }

4
src/frontend/com_measure2.c

@ -1232,9 +1232,7 @@ measure_parse_stdParams(
/* dc: make m_from always less than m_to */ /* dc: make m_from always less than m_to */
if (cieq("dc", meas->m_analysis)) if (cieq("dc", meas->m_analysis))
if (meas->m_to < meas->m_from) { if (meas->m_to < meas->m_from) {
double tmp_val = meas->m_to;
meas->m_to = meas->m_from;
meas->m_from = tmp_val;
SWAP(double, meas->m_to, meas->m_from);
} }
return 1; return 1;

8
src/frontend/evaluate.c

@ -597,9 +597,7 @@ op_range(struct pnode *arg1, struct pnode *arg2)
} }
if (up < low) { if (up < low) {
td = up;
up = low;
low = td;
SWAP(double, up, low);
rev = TRUE; rev = TRUE;
} }
@ -727,9 +725,7 @@ op_ind(struct pnode *arg1, struct pnode *arg2)
up = (int)floor(imagpart(ind->v_compdata[0]) + 0.5); up = (int)floor(imagpart(ind->v_compdata[0]) + 0.5);
} }
if (up < down) { if (up < down) {
i = up;
up = down;
down = i;
SWAP(int, up, down);
rev = TRUE; rev = TRUE;
} }
if (up < 0) { if (up < 0) {

21
src/frontend/plotting/clip.c

@ -106,7 +106,6 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
double dtheta; double dtheta;
double theta1, theta2, tt, alpha, beta, gamma; double theta1, theta2, tt, alpha, beta, gamma;
bool flip = FALSE; bool flip = FALSE;
int i;
/* Get the angles between the origin and the endpoints. */ /* Get the angles between the origin and the endpoints. */
if ((*x1-cx) || (*y1-cy)) if ((*x1-cx) || (*y1-cy))
@ -131,15 +130,9 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
/* Make sure that p1 is the first point */ /* Make sure that p1 is the first point */
if (dtheta < 0) { if (dtheta < 0) {
tt = theta1;
theta1 = theta2;
theta2 = tt;
i = *x1;
*x1 = *x2;
*x2 = i;
i = *y1;
*y1 = *y2;
*y2 = i;
SWAP(double, theta1, theta2);
SWAP(int, *x1, *x2);
SWAP(int, *y1, *y2);
flip = TRUE; flip = TRUE;
dtheta = -dtheta; dtheta = -dtheta;
} }
@ -209,12 +202,8 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
} }
if (flip) { if (flip) {
i = *x1;
*x1 = *x2;
*x2 = i;
i = *y1;
*y1 = *y2;
*y2 = i;
SWAP(int, *x1, *x2);
SWAP(int, *y1, *y2);
} }
return (FALSE); return (FALSE);

5
src/frontend/plotting/grid.c

@ -1491,10 +1491,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
if (in) { if (in) {
if (start > d) { if (start > d) {
double tmp;
tmp = start;
start = d;
d = tmp;
SWAP(double, start, d);
} }
DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start); DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start);
sclip = start; sclip = start;

9
src/frontend/plotting/plotit.c

@ -219,7 +219,6 @@ plotit(wordlist *wl, char *hcopy, char *devname)
struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL; struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL;
char *xn; char *xn;
int i, y_type, xt; int i, y_type, xt;
double tt;
wordlist *wwl, *tail; wordlist *wwl, *tail;
char *cline = NULL, buf[BSIZE_SP], *pname; char *cline = NULL, buf[BSIZE_SP], *pname;
char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL; char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL;
@ -831,14 +830,10 @@ plotit(wordlist *wl, char *hcopy, char *devname)
ylims[1] = 1.0; ylims[1] = 1.0;
} }
if (xlims[0] > xlims[1]) { if (xlims[0] > xlims[1]) {
tt = xlims[1];
xlims[1] = xlims[0];
xlims[0] = tt;
SWAP(double, xlims[1], xlims[0]);
} }
if (ylims[0] > ylims[1]) { if (ylims[0] > ylims[1]) {
tt = ylims[1];
ylims[1] = ylims[0];
ylims[0] = tt;
SWAP(double, ylims[1], ylims[0]);
} }
if (AlmostEqualUlps(xlims[0], xlims[1], 10)) { if (AlmostEqualUlps(xlims[0], xlims[1], 10)) {
xlims[0] *= (xlims[0] > 0) ? 0.9 : 1.1; xlims[0] *= (xlims[0] > 0) ? 0.9 : 1.1;

10
src/frontend/plotting/x11.c

@ -753,7 +753,7 @@ zoomin(GRAPH *graph)
/* note: need to add circular boxes XXX */ /* note: need to add circular boxes XXX */
int x0, y0, x1, y1; int x0, y0, x1, y1;
double fx0, fx1, fy0, fy1, ftemp;
double fx0, fx1, fy0, fy1;
char buf[BSIZE_SP]; char buf[BSIZE_SP];
char buf2[128]; char buf2[128];
char *t; char *t;
@ -811,14 +811,10 @@ zoomin(GRAPH *graph)
X_ScreentoData(graph, x1, y1, &fx1, &fy1); X_ScreentoData(graph, x1, y1, &fx1, &fy1);
if (fx0 > fx1) { if (fx0 > fx1) {
ftemp = fx0;
fx0 = fx1;
fx1 = ftemp;
SWAP(double, fx0, fx1);
} }
if (fy0 > fy1) { if (fy0 > fy1) {
ftemp = fy0;
fy0 = fy1;
fy1 = ftemp;
SWAP(double, fy0, fy1);
} }
strncpy(buf2, graph->plotname, sizeof(buf2)); strncpy(buf2, graph->plotname, sizeof(buf2));

8
src/frontend/trannoise/FastNorm3.c

@ -600,7 +600,7 @@ Sf wk1 [WL], wk2 [WL]; /* Pools of variates. */
static void static void
regen(void) regen(void)
{ {
Sw i, j, k, m;
Sw i, j, m;
Sf p, q, r, s, t; Sf p, q, r, s, t;
Sw topv[6], ord[4], *top; Sw topv[6], ord[4], *top;
Sf *ppt[4], *ptn; Sf *ppt[4], *ptn;
@ -626,10 +626,8 @@ reran1:
for (i = 2; i >= 0; i--) for (i = 2; i >= 0; i--)
for (j = 0; j <= i; j++) for (j = 0; j <= i; j++)
if (top[j] < top[j+1]) { if (top[j] < top[j+1]) {
k = top[j]; top[j] = top[j+1];
top[j+1] = k;
k = ord[j]; ord[j] = ord[j+1];
ord[j+1] = k;
SWAP(Sw, top[j], top[j+1]);
SWAP(Sw, ord[j], ord[j+1]);
} }
/* Ensure all different */ /* Ensure all different */

6
src/frontend/trannoise/wallace.c

@ -197,10 +197,8 @@ reran1:
for (i = 2; i >= 0; i--) for (i = 2; i >= 0; i--)
for (j = 0; j <= i; j++) for (j = 0; j <= i; j++)
if (top[j] < top[j+1]) { if (top[j] < top[j+1]) {
k = top[j]; top[j] = top[j+1];
top[j+1] = k;
k = ord[j]; ord[j] = ord[j+1];
ord[j+1] = k;
SWAP(int, top[j], top[j+1]);
SWAP(int, ord[j], ord[j+1]);
} }
/* Ensure all different */ /* Ensure all different */

9
src/maths/ni/niaciter.c

@ -25,7 +25,6 @@ NIacIter(CKTcircuit *ckt)
{ {
int error; int error;
int ignore; int ignore;
double *temp;
double startTime; double startTime;
retry: retry:
@ -77,13 +76,9 @@ retry:
*ckt->CKTirhsSpare = 0; *ckt->CKTirhsSpare = 0;
*ckt->CKTirhsOld = 0; *ckt->CKTirhsOld = 0;
temp = ckt->CKTirhsOld;
ckt->CKTirhsOld = ckt->CKTirhs;
ckt->CKTirhs = temp;
SWAP(double *, ckt->CKTirhsOld, ckt->CKTirhs);
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
return(OK); return(OK);
} }

25
src/maths/ni/niditer.c

@ -23,31 +23,22 @@ NIdIter(CKTcircuit *ckt)
{ {
int error; int error;
int ignore; int ignore;
double *temp;
ckt->CKTnoncon = 0; ckt->CKTnoncon = 0;
goto skip; goto skip;
retry: retry:
ckt->CKTnoncon=0; ckt->CKTnoncon=0;
temp = ckt->CKTrhs;
ckt->CKTrhs = ckt->CKTrhsSpare;
ckt->CKTrhsSpare = temp;
SWAP(double *, ckt->CKTrhs, ckt->CKTrhsSpare);
temp = ckt->CKTirhs;
ckt->CKTirhs = ckt->CKTirhsSpare;
ckt->CKTirhsSpare = temp;
SWAP(double *, ckt->CKTirhs, ckt->CKTirhsSpare);
error = CKTacLoad(ckt); error = CKTacLoad(ckt);
if(error) return(error); if(error) return(error);
temp = ckt->CKTrhs;
ckt->CKTrhs = ckt->CKTrhsSpare;
ckt->CKTrhsSpare = temp;
SWAP(double *, ckt->CKTrhs, ckt->CKTrhsSpare);
temp = ckt->CKTirhs;
ckt->CKTirhs = ckt->CKTirhsSpare;
ckt->CKTirhsSpare = temp;
SWAP(double *, ckt->CKTirhs, ckt->CKTirhsSpare);
skip: skip:
if(ckt->CKTniState & NIACSHOULDREORDER) { if(ckt->CKTniState & NIACSHOULDREORDER) {
@ -85,12 +76,8 @@ skip:
*ckt->CKTirhsSpare = 0; *ckt->CKTirhsSpare = 0;
*ckt->CKTirhsOld = 0; *ckt->CKTirhsOld = 0;
temp = ckt->CKTirhsOld;
ckt->CKTirhsOld = ckt->CKTirhs;
ckt->CKTirhs = temp;
SWAP(double *, ckt->CKTirhsOld, ckt->CKTirhs);
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
return(OK); return(OK);
} }

9
src/maths/ni/niiter.c

@ -29,7 +29,6 @@ NIiter(CKTcircuit *ckt, int maxIter)
int ipass; int ipass;
int error; int error;
int i,j; /* temporaries for finding error location */ int i,j; /* temporaries for finding error location */
double *temp;
double startTime; double startTime;
static char *msg = "Too many iterations without convergence"; static char *msg = "Too many iterations without convergence";
@ -43,9 +42,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
if( (ckt->CKTmode & MODETRANOP) && (ckt->CKTmode & MODEUIC)) { if( (ckt->CKTmode & MODETRANOP) && (ckt->CKTmode & MODEUIC)) {
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
error = CKTload(ckt); error = CKTload(ckt);
if(error) { if(error) {
return(error); return(error);
@ -269,9 +266,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
} }
/* build up the lvnim1 array from the lvn array */ /* build up the lvnim1 array from the lvn array */
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
/*printf("after loading, after solving\n");*/ /*printf("after loading, after solving\n");*/
/*CKTdump(ckt);*/ /*CKTdump(ckt);*/
} }

8
src/maths/poly/polyfit.c

@ -53,13 +53,9 @@ ft_polyfit(double *xdata, double *ydata, double *result,
if (lindex != i) { if (lindex != i) {
/* swap rows i and lindex */ /* swap rows i and lindex */
for (k = 0; k < n; k++) { for (k = 0; k < n; k++) {
d = mat1[i * n + k];
mat1[i * n + k] = mat1[lindex * n + k];
mat1[lindex * n + k] = d;
SWAP(double, mat1[i * n + k], mat1[lindex * n + k]);
} }
d = mat2[i];
mat2[i] = mat2[lindex];
mat2[lindex] = d;
SWAP(double, mat2[i], mat2[lindex]);
} }
/* Make sure we have a non-zero pivot. */ /* Make sure we have a non-zero pivot. */
if (mat1[i * n + i] == 0.0) { if (mat1[i * n + i] == 0.0) {

9
src/misc/wlist.c

@ -151,9 +151,7 @@ wl_reverse(wordlist *wl)
return (wl); return (wl);
for (;;) { for (;;) {
wordlist *t = wl->wl_next;
wl->wl_next = wl->wl_prev;
wl->wl_prev = t;
SWAP(wordlist *, wl->wl_next, wl->wl_prev);
if (!wl->wl_prev) if (!wl->wl_prev)
return (wl); return (wl);
wl = wl->wl_prev; wl = wl->wl_prev;
@ -231,14 +229,11 @@ wl_sort(wordlist *wl)
wordlist * wordlist *
wl_range(wordlist *wl, int low, int up) wl_range(wordlist *wl, int low, int up)
{ {
int i;
wordlist *tt; wordlist *tt;
bool rev = FALSE; bool rev = FALSE;
if (low > up) { if (low > up) {
i = up;
up = low;
low = i;
SWAP(int, up, low);
rev = TRUE; rev = TRUE;
} }
up -= low; up -= low;

6
src/spicelib/analysis/cktpzset.c

@ -22,7 +22,7 @@ CKTpzSetup(CKTcircuit *ckt, int type)
SMPmatrix *matrix; SMPmatrix *matrix;
int error; int error;
int i, temp, solution_col, balance_col;
int i, solution_col, balance_col;
int input_pos, input_neg, output_pos, output_neg; int input_pos, input_neg, output_pos, output_neg;
NIdestroy(ckt); NIdestroy(ckt);
@ -71,9 +71,7 @@ CKTpzSetup(CKTcircuit *ckt, int type)
balance_col = output_neg; balance_col = output_neg;
} else { } else {
solution_col = output_neg; solution_col = output_neg;
temp = input_pos;
input_pos = input_neg;
input_neg = temp;
SWAP(int, input_pos, input_neg);
} }
if (input_pos) if (input_pos)

6
src/spicelib/analysis/distoan.c

@ -12,11 +12,7 @@ Author: 1988 Jaijeet S Roychowdhury
static void static void
DISswap(double **a, double **b) DISswap(double **a, double **b)
{ {
double *c;
c = *a;
*a = *b;
*b = c;
SWAP(double *, *a, *b);
} }
static void static void

8
src/spicelib/devices/cpl/cplsetup.c

@ -769,9 +769,7 @@ Gaussian_Elimination2(int dims, int type)
} }
if (imax != i) if (imax != i)
for (k = i; k <= dim; k++) { for (k = i; k <= dim; k++) {
f = A[i][k];
A[i][k] = A[imax][k];
A[imax][k] = f;
SWAP(double, A[i][k], A[imax][k]);
} }
f = 1.0 / A[i][i]; f = 1.0 / A[i][i];
@ -1699,9 +1697,7 @@ Gaussian_Elimination(int dims)
} }
if (imax != i) if (imax != i)
for (k = i; k <= dim; k++) { for (k = i; k <= dim; k++) {
f = At[i][k];
At[i][k] = At[imax][k];
At[imax][k] = f;
SWAP(double, At[i][k], At[imax][k]);
} }
f = 1.0 / At[i][i]; f = 1.0 / At[i][i];

7
src/spicelib/devices/jfet/jfetdset.c

@ -31,7 +31,6 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt)
double lcapgs1; double lcapgs1;
double cd; double cd;
double cdrain; double cdrain;
double temp;
double cg; double cg;
double cgd; double cgd;
double csat; double csat;
@ -95,10 +94,8 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt)
if (vds < 0.0) { if (vds < 0.0) {
vds = -vds; vds = -vds;
temp = vgs;
vgs = vgd;
vgd = temp; /* so now these have become the
local variables */
SWAP(double, vgs, vgd);
/* so now these have become the local variables */
here->JFETmode = -1; here->JFETmode = -1;
} else { } else {
here->JFETmode = 1; here->JFETmode = 1;

5
src/spicelib/devices/mesa/mesaload.c

@ -81,7 +81,6 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt)
#ifndef PREDICTOR #ifndef PREDICTOR
double xfact; double xfact;
#endif #endif
double temp;
double vted; double vted;
double vtes; double vtes;
double vtd; double vtd;
@ -321,9 +320,7 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt)
if(inverse) { if(inverse) {
cdrain = -cdrain; cdrain = -cdrain;
vds = -vds; vds = -vds;
temp = capgs;
capgs = capgd;
capgd = temp;
SWAP(double, capgs, capgd);
} }
/* /*
* compute equivalent drain current source * compute equivalent drain current source

8
src/spicelib/devices/soi3/soi3load.c

@ -984,9 +984,7 @@ SOI3load(GENmodel *inModel, CKTcircuit *ckt)
/* Now we use a nasty trick - if device is A over T, must "swap" drain and source /* Now we use a nasty trick - if device is A over T, must "swap" drain and source
potentials. we do a literal switch and change it back for the outside world. */ potentials. we do a literal switch and change it back for the outside world. */
if (here->SOI3mode == -1) { if (here->SOI3mode == -1) {
tmp = vsb;
vsb = vdb;
vdb = tmp;
SWAP(double, vsb, vdb);
} }
/* Intrinsic Electrical Bit - has a bit of thermal due to TTC */ /* Intrinsic Electrical Bit - has a bit of thermal due to TTC */
@ -1667,9 +1665,7 @@ SOI3load(GENmodel *inModel, CKTcircuit *ckt)
/* now end nasty trick - if vsb and vdb have been switched, reverse them back */ /* now end nasty trick - if vsb and vdb have been switched, reverse them back */
if (here->SOI3mode == -1) if (here->SOI3mode == -1)
{ {
tmp = vsb;
vsb = vdb;
vdb = tmp;
SWAP(double, vsb, vdb);
} }
/* /*

8
src/spicelib/devices/txl/txlsetup.c

@ -550,9 +550,7 @@ Gaussian_Elimination1(int dims)
} }
if (imax != i) if (imax != i)
for (k = i; k <= dim; k++) { for (k = i; k <= dim; k++) {
f = A[i][k];
A[i][k] = A[imax][k];
A[imax][k] = f;
SWAP(double, A[i][k], A[imax][k]);
} }
f = 1.0 / A[i][i]; f = 1.0 / A[i][i];
@ -913,9 +911,7 @@ Gaussian_Elimination2(int dims)
} }
if (imax != i) if (imax != i)
for (k = i; k <= dim; k++) { for (k = i; k <= dim; k++) {
f = AA[i][k];
AA[i][k] = AA[imax][k];
AA[imax][k] = f;
SWAP(double, AA[i][k], AA[imax][k]);
} }
f = 1.0 / AA[i][i]; f = 1.0 / AA[i][i];

Loading…
Cancel
Save