From bd0bc3038be604b447ccb0c884ec4dd63fae8805 Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 22 Mar 2016 13:04:13 +0100 Subject: [PATCH] use `SWAP' macro --- src/frontend/com_compose.c | 4 +--- src/frontend/com_measure2.c | 4 +--- src/frontend/evaluate.c | 8 ++------ src/frontend/plotting/clip.c | 21 +++++---------------- src/frontend/plotting/grid.c | 5 +---- src/frontend/plotting/plotit.c | 9 ++------- src/frontend/plotting/x11.c | 10 +++------- src/frontend/trannoise/FastNorm3.c | 8 +++----- src/frontend/trannoise/wallace.c | 6 ++---- src/maths/ni/niaciter.c | 9 ++------- src/maths/ni/niditer.c | 25 ++++++------------------- src/maths/ni/niiter.c | 9 ++------- src/maths/poly/polyfit.c | 8 ++------ src/misc/wlist.c | 9 ++------- src/spicelib/analysis/cktpzset.c | 6 ++---- src/spicelib/analysis/distoan.c | 6 +----- src/spicelib/devices/cpl/cplsetup.c | 8 ++------ src/spicelib/devices/jfet/jfetdset.c | 7 ++----- src/spicelib/devices/mesa/mesaload.c | 5 +---- src/spicelib/devices/soi3/soi3load.c | 8 ++------ src/spicelib/devices/txl/txlsetup.c | 8 ++------ 21 files changed, 46 insertions(+), 137 deletions(-) diff --git a/src/frontend/com_compose.c b/src/frontend/com_compose.c index 9bc3790c7..e3f2211c7 100644 --- a/src/frontend/com_compose.c +++ b/src/frontend/com_compose.c @@ -378,9 +378,7 @@ com_compose(wordlist *wl) } if (startgiven && stopgiven && (start > stop)) { - tt = start; - start = stop; - stop = tt; + SWAP(double, start, stop); reverse = TRUE; } diff --git a/src/frontend/com_measure2.c b/src/frontend/com_measure2.c index ebf217783..e0518493b 100644 --- a/src/frontend/com_measure2.c +++ b/src/frontend/com_measure2.c @@ -1232,9 +1232,7 @@ measure_parse_stdParams( /* dc: make m_from always less than m_to */ if (cieq("dc", meas->m_analysis)) 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; diff --git a/src/frontend/evaluate.c b/src/frontend/evaluate.c index 9f0827b44..9597059e3 100644 --- a/src/frontend/evaluate.c +++ b/src/frontend/evaluate.c @@ -597,9 +597,7 @@ op_range(struct pnode *arg1, struct pnode *arg2) } if (up < low) { - td = up; - up = low; - low = td; + SWAP(double, up, low); rev = TRUE; } @@ -727,9 +725,7 @@ op_ind(struct pnode *arg1, struct pnode *arg2) up = (int)floor(imagpart(ind->v_compdata[0]) + 0.5); } if (up < down) { - i = up; - up = down; - down = i; + SWAP(int, up, down); rev = TRUE; } if (up < 0) { diff --git a/src/frontend/plotting/clip.c b/src/frontend/plotting/clip.c index d851f57e6..097eca9d0 100644 --- a/src/frontend/plotting/clip.c +++ b/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 theta1, theta2, tt, alpha, beta, gamma; bool flip = FALSE; - int i; /* Get the angles between the origin and the endpoints. */ 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 */ 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; 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) { - i = *x1; - *x1 = *x2; - *x2 = i; - i = *y1; - *y1 = *y2; - *y2 = i; + SWAP(int, *x1, *x2); + SWAP(int, *y1, *y2); } return (FALSE); diff --git a/src/frontend/plotting/grid.c b/src/frontend/plotting/grid.c index 41dccfd24..4f9e217fa 100644 --- a/src/frontend/plotting/grid.c +++ b/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 (start > d) { - double tmp; - tmp = start; - start = d; - d = tmp; + SWAP(double, start, d); } DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start); sclip = start; diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index ca9f9016e..2020cfe9d 100644 --- a/src/frontend/plotting/plotit.c +++ b/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; char *xn; int i, y_type, xt; - double tt; wordlist *wwl, *tail; char *cline = NULL, buf[BSIZE_SP], *pname; char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL; @@ -831,14 +830,10 @@ plotit(wordlist *wl, char *hcopy, char *devname) ylims[1] = 1.0; } 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]) { - tt = ylims[1]; - ylims[1] = ylims[0]; - ylims[0] = tt; + SWAP(double, ylims[1], ylims[0]); } if (AlmostEqualUlps(xlims[0], xlims[1], 10)) { xlims[0] *= (xlims[0] > 0) ? 0.9 : 1.1; diff --git a/src/frontend/plotting/x11.c b/src/frontend/plotting/x11.c index ca9f810f3..c29a62eb4 100644 --- a/src/frontend/plotting/x11.c +++ b/src/frontend/plotting/x11.c @@ -753,7 +753,7 @@ zoomin(GRAPH *graph) /* note: need to add circular boxes XXX */ int x0, y0, x1, y1; - double fx0, fx1, fy0, fy1, ftemp; + double fx0, fx1, fy0, fy1; char buf[BSIZE_SP]; char buf2[128]; char *t; @@ -811,14 +811,10 @@ zoomin(GRAPH *graph) X_ScreentoData(graph, x1, y1, &fx1, &fy1); if (fx0 > fx1) { - ftemp = fx0; - fx0 = fx1; - fx1 = ftemp; + SWAP(double, fx0, fx1); } if (fy0 > fy1) { - ftemp = fy0; - fy0 = fy1; - fy1 = ftemp; + SWAP(double, fy0, fy1); } strncpy(buf2, graph->plotname, sizeof(buf2)); diff --git a/src/frontend/trannoise/FastNorm3.c b/src/frontend/trannoise/FastNorm3.c index 428db5e85..28c97fca2 100644 --- a/src/frontend/trannoise/FastNorm3.c +++ b/src/frontend/trannoise/FastNorm3.c @@ -600,7 +600,7 @@ Sf wk1 [WL], wk2 [WL]; /* Pools of variates. */ static void regen(void) { - Sw i, j, k, m; + Sw i, j, m; Sf p, q, r, s, t; Sw topv[6], ord[4], *top; Sf *ppt[4], *ptn; @@ -626,10 +626,8 @@ reran1: for (i = 2; i >= 0; i--) for (j = 0; j <= i; j++) 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 */ diff --git a/src/frontend/trannoise/wallace.c b/src/frontend/trannoise/wallace.c index ff5a9118c..2136d9e5d 100644 --- a/src/frontend/trannoise/wallace.c +++ b/src/frontend/trannoise/wallace.c @@ -197,10 +197,8 @@ reran1: for (i = 2; i >= 0; i--) for (j = 0; j <= i; j++) 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 */ diff --git a/src/maths/ni/niaciter.c b/src/maths/ni/niaciter.c index 4c5dc1b00..8f847ff49 100644 --- a/src/maths/ni/niaciter.c +++ b/src/maths/ni/niaciter.c @@ -25,7 +25,6 @@ NIacIter(CKTcircuit *ckt) { int error; int ignore; - double *temp; double startTime; retry: @@ -77,13 +76,9 @@ retry: *ckt->CKTirhsSpare = 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); } diff --git a/src/maths/ni/niditer.c b/src/maths/ni/niditer.c index 1b9f19689..a7a54d267 100644 --- a/src/maths/ni/niditer.c +++ b/src/maths/ni/niditer.c @@ -23,31 +23,22 @@ NIdIter(CKTcircuit *ckt) { int error; int ignore; - double *temp; ckt->CKTnoncon = 0; goto skip; retry: 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); 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: if(ckt->CKTniState & NIACSHOULDREORDER) { @@ -85,12 +76,8 @@ skip: *ckt->CKTirhsSpare = 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); } diff --git a/src/maths/ni/niiter.c b/src/maths/ni/niiter.c index 7d165070c..d5b7be7f1 100644 --- a/src/maths/ni/niiter.c +++ b/src/maths/ni/niiter.c @@ -29,7 +29,6 @@ NIiter(CKTcircuit *ckt, int maxIter) int ipass; int error; int i,j; /* temporaries for finding error location */ - double *temp; double startTime; static char *msg = "Too many iterations without convergence"; @@ -43,9 +42,7 @@ NIiter(CKTcircuit *ckt, int maxIter) 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); if(error) { return(error); @@ -269,9 +266,7 @@ NIiter(CKTcircuit *ckt, int maxIter) } /* 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");*/ /*CKTdump(ckt);*/ } diff --git a/src/maths/poly/polyfit.c b/src/maths/poly/polyfit.c index 7424e6097..f7c77749f 100644 --- a/src/maths/poly/polyfit.c +++ b/src/maths/poly/polyfit.c @@ -53,13 +53,9 @@ ft_polyfit(double *xdata, double *ydata, double *result, if (lindex != i) { /* swap rows i and lindex */ 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. */ if (mat1[i * n + i] == 0.0) { diff --git a/src/misc/wlist.c b/src/misc/wlist.c index 099218a59..4dd6bf5d4 100644 --- a/src/misc/wlist.c +++ b/src/misc/wlist.c @@ -151,9 +151,7 @@ wl_reverse(wordlist *wl) return (wl); 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) return (wl); wl = wl->wl_prev; @@ -231,14 +229,11 @@ wl_sort(wordlist *wl) wordlist * wl_range(wordlist *wl, int low, int up) { - int i; wordlist *tt; bool rev = FALSE; if (low > up) { - i = up; - up = low; - low = i; + SWAP(int, up, low); rev = TRUE; } up -= low; diff --git a/src/spicelib/analysis/cktpzset.c b/src/spicelib/analysis/cktpzset.c index 4c637595f..5d9a58a0b 100644 --- a/src/spicelib/analysis/cktpzset.c +++ b/src/spicelib/analysis/cktpzset.c @@ -22,7 +22,7 @@ CKTpzSetup(CKTcircuit *ckt, int type) SMPmatrix *matrix; int error; - int i, temp, solution_col, balance_col; + int i, solution_col, balance_col; int input_pos, input_neg, output_pos, output_neg; NIdestroy(ckt); @@ -71,9 +71,7 @@ CKTpzSetup(CKTcircuit *ckt, int type) balance_col = output_neg; } else { solution_col = output_neg; - temp = input_pos; - input_pos = input_neg; - input_neg = temp; + SWAP(int, input_pos, input_neg); } if (input_pos) diff --git a/src/spicelib/analysis/distoan.c b/src/spicelib/analysis/distoan.c index c7c2aea10..d266f7970 100644 --- a/src/spicelib/analysis/distoan.c +++ b/src/spicelib/analysis/distoan.c @@ -12,11 +12,7 @@ Author: 1988 Jaijeet S Roychowdhury static void DISswap(double **a, double **b) { -double *c; - -c = *a; -*a = *b; -*b = c; + SWAP(double *, *a, *b); } static void diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c index e70d9ce7d..bedb65f20 100644 --- a/src/spicelib/devices/cpl/cplsetup.c +++ b/src/spicelib/devices/cpl/cplsetup.c @@ -769,9 +769,7 @@ Gaussian_Elimination2(int dims, int type) } if (imax != i) 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]; @@ -1699,9 +1697,7 @@ Gaussian_Elimination(int dims) } if (imax != i) 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]; diff --git a/src/spicelib/devices/jfet/jfetdset.c b/src/spicelib/devices/jfet/jfetdset.c index 329a35337..6189e7ef3 100644 --- a/src/spicelib/devices/jfet/jfetdset.c +++ b/src/spicelib/devices/jfet/jfetdset.c @@ -31,7 +31,6 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt) double lcapgs1; double cd; double cdrain; - double temp; double cg; double cgd; double csat; @@ -95,10 +94,8 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt) if (vds < 0.0) { 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; } else { here->JFETmode = 1; diff --git a/src/spicelib/devices/mesa/mesaload.c b/src/spicelib/devices/mesa/mesaload.c index 979f56696..aaf23df6e 100644 --- a/src/spicelib/devices/mesa/mesaload.c +++ b/src/spicelib/devices/mesa/mesaload.c @@ -81,7 +81,6 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt) #ifndef PREDICTOR double xfact; #endif - double temp; double vted; double vtes; double vtd; @@ -321,9 +320,7 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt) if(inverse) { cdrain = -cdrain; vds = -vds; - temp = capgs; - capgs = capgd; - capgd = temp; + SWAP(double, capgs, capgd); } /* * compute equivalent drain current source diff --git a/src/spicelib/devices/soi3/soi3load.c b/src/spicelib/devices/soi3/soi3load.c index cab4b2b02..6e019f9b0 100644 --- a/src/spicelib/devices/soi3/soi3load.c +++ b/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 potentials. we do a literal switch and change it back for the outside world. */ 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 */ @@ -1667,9 +1665,7 @@ SOI3load(GENmodel *inModel, CKTcircuit *ckt) /* now end nasty trick - if vsb and vdb have been switched, reverse them back */ if (here->SOI3mode == -1) { - tmp = vsb; - vsb = vdb; - vdb = tmp; + SWAP(double, vsb, vdb); } /* diff --git a/src/spicelib/devices/txl/txlsetup.c b/src/spicelib/devices/txl/txlsetup.c index 98a5210e2..1840f2beb 100644 --- a/src/spicelib/devices/txl/txlsetup.c +++ b/src/spicelib/devices/txl/txlsetup.c @@ -550,9 +550,7 @@ Gaussian_Elimination1(int dims) } if (imax != i) 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]; @@ -913,9 +911,7 @@ Gaussian_Elimination2(int dims) } if (imax != i) 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];