Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@
ParseNumber(x,s) if ( sgn ) x = -x; }

/* (n) is necessary here, since the macro is sometimes passed dereferenced pointers for n */
#define NCOPY(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } }
/*#define NCOPY(s,t,n) { memcpy(s,t,n*sizeof(WORD)); s+=n; t+=n; n = -1; }*/
/*#define NCOPY(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } }
#define NCOPYI(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } }
#define NCOPYB(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } }
#define NCOPYI32(s,t,n) { while ( (n)-- > 0 ) { *s++ = *t++; } }
#define WCOPY(s,t,n) { int nn=n; WORD *ss=(WORD *)s, *tt=(WORD *)t; while ( (nn)-- > 0 ) { *ss++ = *tt++; } }
#define WCOPY(s,t,n) { int nn=n; WORD *ss=(WORD *)s, *tt=(WORD *)t; while ( (nn)-- > 0 ) { *ss++ = *tt++; } }*/

/* Use memmove: we can't guarantee that s and t do not overlap in uses of the macros */
#define NCOPY(s,t,n) { memmove(s,t,(n)*sizeof(*s)); s+=n; t+=n; n=0; }
#define NCOPYI(s,t,n) { NCOPY(s,t,n); }
#define NCOPYB(s,t,n) { NCOPY(s,t,n); }
#define NCOPYI32(s,t,n) { NCOPY(s,t,n); }
#define WCOPY(s,t,n) { int nn=n; WORD *ss=(WORD *)s, *tt=(WORD *)t; NCOPY(ss,tt,nn); }

#define NeedNumber(x,s,err) { int sgn = 1; \
while ( *s == ' ' || *s == '\t' || *s == '-' || *s == '+' ) { \
Expand Down
4 changes: 3 additions & 1 deletion sources/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,9 @@ NextSymbol2:;
if ( AR.BracketOn < 0 ) {
s1 = t1; t1 = t2; t2 = s1;
}
do { *t2++ = *t++; } while ( t < (WORD *)tStopa );
/* Old code copied 1 element if copy == 0. This doesn't happen in the test suite. */
LONG copy = tStopa - t;
NCOPY(t2, t, copy);
t = AT.WorkPointer;
i = WORDDIF(t1,term1);
*t++ = 4 + i + WORDDIF(t2,term2);
Expand Down
2 changes: 1 addition & 1 deletion sources/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ donemul: if ( i ) { ncoef2 = 1; coef2 = Spac2; coef2[0] = coef2[1] = 1; }
}
coef1 = Spac1;
i = 2*ABS(ncoef2);
for ( j = 0; j < i; j++ ) coef1[j] = coef2[j];
WCOPY(coef1, coef2, i);
ncoef1 = ncoef2;
SkipCond:
ifp += ifp[1];
Expand Down
62 changes: 33 additions & 29 deletions sources/proces.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
if ( AR.TePos ) {
if ( ( term + AR.TePos ) == t ) {
m = termout;
while ( from < t ) *m++ = *from++;
LONG copy = t - from;
NCOPY(m, from, copy);
*m++ = DENOMINATOR;
*m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
*m++ = DIRTYFLAG;
Expand All @@ -2185,7 +2186,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
*m++ = t[1] + 4;
t[3] = -t[3];
v = t + t[1];
while ( t < v ) *m++ = *t++;
copy = v - t;
NCOPY(m, t, copy);
from[3] = -from[3];
*m++ = 1;
*m++ = 1;
Expand Down Expand Up @@ -2220,11 +2222,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
AR.DeferFlag = 0;
v = t + *t;
t += ARGHEAD; /* First term */
w = 0; /* to appease the compilers warning devices */
while ( from < t ) {
if ( from == u ) w = m;
*m++ = *from++;
}
LONG copy = t - from;
const LONG size = t - u;
NCOPY(m, from, copy);
w = m - size;
to = m;
NewSort(BHEAD0);
if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
Expand Down Expand Up @@ -2314,11 +2315,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
&& ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
AR.DeferFlag = 0;
v = t + 2;
w = 0; /* to appease the compilers warning devices */
while ( from < t ) {
if ( from == u ) w = m;
*m++ = *from++;
}
LONG copy = t - from;
const LONG size = t - u;
NCOPY(m, from, copy);
w = m - size;
to = m;
switch ( d->type ) {
case DOLINDEX:
Expand Down Expand Up @@ -2481,11 +2481,10 @@ int InFunction(PHEAD WORD *term, WORD *termout)
u points at the start of the function
t points at the start of the argument
*/
w = 0;
while ( from < t ) {
if ( from == u ) w = m;
*m++ = *from++;
}
LONG copy = t - from;
const LONG size = t - u;
NCOPY(m, from, copy);
w = m - size;
if ( ( numterms & MAXPOSITIVE ) == numterms ) {
*m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
w[1] += 1;
Expand All @@ -2505,7 +2504,8 @@ int InFunction(PHEAD WORD *term, WORD *termout)
}
from++; /* Skip our function */
r = term + *term;
while ( from < r ) *m++ = *from++;
copy = r - from;
NCOPY(m, from, copy);
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
Expand Down Expand Up @@ -2548,11 +2548,11 @@ int InFunction(PHEAD WORD *term, WORD *termout)
if ( ( AN.ncmod != 0 )
&& ( ( AC.modmode & ALSOFUNARGS ) == 0 )
&& ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
m = termout; w = 0;
while ( from < t ) {
if ( from == u ) w = m;
*m++ = *from++;
}
m = termout;
LONG copy = t - from;
const LONG size = t - u;
NCOPY(m, from, copy);
w = m - size;
to = m;
switch ( d->type ) {
case DOLINDEX:
Expand Down Expand Up @@ -2650,7 +2650,8 @@ wrongtype:;
w[1] = w[1] - 2 + (m-to);
from += 2;
term += *term;
while ( from < term ) *m++ = *from++;
copy = term - from;
NCOPY(m, from, copy);
if ( sign < 0 ) m[-1] = -m[-1];
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
Expand Down Expand Up @@ -3413,10 +3414,10 @@ SkipCount: level++;
are involved in a match(). Hence we have to make
a private copy here!!!!
*/
WORD ic, jc, *ifcode, *jfcode;
WORD jc, *ifcode, *jfcode;
jfcode = C->lhs[level]; jc = jfcode[1];
ifcode = AT.WorkPointer; AT.WorkPointer += jc;
for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
WCOPY(ifcode, jfcode, jc);
while ( !DoIfStatement(BHEAD ifcode,term) ) {
level = C->lhs[level][2];
if ( C->lhs[level][0] != TYPEELIF ) break;
Expand Down Expand Up @@ -5253,11 +5254,14 @@ int PrepPoly(PHEAD WORD *term,WORD par)
*/
m = term + *term;
if ( poly + poly[1] < tstop ) {
for ( i = 0; i < poly[1]; i++ ) m[i] = poly[i];
LONG copy = poly[1];
WCOPY(m, poly, copy);
t = poly; v = poly + poly[1];
while ( v < tstop ) *t++ = *v++;
copy = tstop - v;
NCOPY(t, v, copy);
poly = t;
for ( i = 0; i < m[1]; i++ ) t[i] = m[i];
copy = m[1];
WCOPY(t, m, copy);
t += m[1];
}
AT.PolyAct = WORDDIF(poly,term);
Expand Down
6 changes: 2 additions & 4 deletions sources/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -4624,9 +4624,7 @@ int StoreTerm(PHEAD WORD *term)
while ( ( t = *ss++ ) != 0 ) {
j = *t;
if ( j < 0 ) j = t[1] + 2;
while ( --j >= 0 ){
*lfill++ = *t++;
}
NCOPY(lfill, t, j);
}
}
*lfill++ = 0;
Expand All @@ -4636,7 +4634,7 @@ int StoreTerm(PHEAD WORD *term)
*(S->PoinFill) = S->sFill = S->sBuffer;
}
j = *term;
while ( --j >= 0 ) *S->sFill++ = *term++;
NCOPY(S->sFill, term, j);
S->sTerms++;
S->GenTerms++;
S->TermsLeft++;
Expand Down
6 changes: 3 additions & 3 deletions sources/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -3543,9 +3543,9 @@ int PutToMaster(PHEAD WORD *term)
fill = AT.SB.MasterFill[i]; /* Where we are filling */
top = AT.SB.MasterStop[i]; /* End of the block */
while ( j > 0 ) {
while ( j > 0 && fill < top ) {
*fill++ = *t++; j--;
}
LONG copy = MiN(top - fill, j);
j -= copy;
NCOPY(fill, t, copy);
if ( j > 0 ) {
/*
We reached the end of the block.
Expand Down
Loading