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
1 change: 1 addition & 0 deletions sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ extern WORD *MakeDollarInteger(PHEAD WORD *,WORD **);
extern WORD *MakeDollarMod(PHEAD WORD *,WORD **);
extern int GetDolNum(PHEAD WORD *, WORD *);
extern void AddPotModdollar(WORD);
extern int DollarLocalCopy(WORD);

extern int Optimize(WORD, int);
extern int ClearOptimize(void);
Expand Down
100 changes: 53 additions & 47 deletions sources/dollar.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int AssignDollar(PHEAD WORD *term, WORD level)
Terminate(-1);
}
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand All @@ -252,8 +252,7 @@ int AssignDollar(PHEAD WORD *term, WORD level)
*/
#ifdef WITHPTHREADS
if ( dtype > 0 ) {
/* LOCK(d->pthreadslockwrite); */
LOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { LOCK(d->pthreadslockread); }
NewValIsZero:;
switch ( d->type ) {
case DOLZERO: goto NoChangeZero;
Expand All @@ -278,8 +277,7 @@ NewValIsZero:;
cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
NoChangeZero:;
CleanDollarFactors(d);
/* UNLOCK(d->pthreadslockwrite); */
UNLOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
AN.ncmod = oldncmod;
return(0);
}
Expand All @@ -301,8 +299,7 @@ NoChangeZero:;
*/
#ifdef WITHPTHREADS
if ( dtype > 0 ) {
/* LOCK(d->pthreadslockwrite); */
LOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { LOCK(d->pthreadslockread); }
if ( d->size < MINALLOC ) {
WORD oldsize, *oldwhere, i;
oldsize = d->size; oldwhere = d->where;
Expand Down Expand Up @@ -365,8 +362,7 @@ HandleDolZero:;
cbuf[AM.dbufnum].NumTerms[numdollar] = 1;
NoChangeOne:;
CleanDollarFactors(d);
/* UNLOCK(d->pthreadslockwrite); */
UNLOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
AN.ncmod = oldncmod;
return(0);
}
Expand Down Expand Up @@ -398,7 +394,7 @@ NoChangeOne:;
depends on the dollar variable.
*/
#ifdef WITHPTHREADS
LOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { LOCK(d->pthreadslockread); }
#endif
CleanDollarFactors(d);
/*
Expand Down Expand Up @@ -566,8 +562,7 @@ HandleDolZero1:;
}
#ifdef WITHPTHREADS
NoChange:;
/* UNLOCK(d->pthreadslockwrite); */
UNLOCK(d->pthreadslockread);
if ( ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
AN.ncmod = oldncmod;
return(0);
Expand Down Expand Up @@ -924,7 +919,7 @@ void WildDollars(PHEAD WORD *term)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1084,7 +1079,7 @@ WORD DolToTensor(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1122,7 +1117,7 @@ WORD DolToTensor(PHEAD WORD numdollar)
retval = 0;
}
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(retval);
}
Expand All @@ -1145,7 +1140,7 @@ WORD DolToFunction(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1179,7 +1174,7 @@ WORD DolToFunction(PHEAD WORD numdollar)
retval = 0;
}
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(retval);
}
Expand All @@ -1202,7 +1197,7 @@ WORD DolToVector(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1243,7 +1238,7 @@ WORD DolToVector(PHEAD WORD numdollar)
retval = 0;
}
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(retval);
}
Expand All @@ -1265,7 +1260,7 @@ WORD DolToNumber(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -1325,7 +1320,7 @@ WORD DolToSymbol(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1356,7 +1351,7 @@ WORD DolToSymbol(PHEAD WORD numdollar)
retval = -1;
}
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(retval);
}
Expand All @@ -1379,7 +1374,7 @@ WORD DolToIndex(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1432,7 +1427,7 @@ WORD DolToIndex(PHEAD WORD numdollar)
retval = 0;
}
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(retval);
}
Expand Down Expand Up @@ -1461,7 +1456,7 @@ DOLLARS DolToTerms(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -1608,7 +1603,7 @@ LONG DolToLong(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -1759,11 +1754,10 @@ int InsideDollar(PHEAD WORD *ll, WORD level)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
/* LOCK(d->pthreadslockwrite); */
LOCK(d->pthreadslockread);
}
}
Expand Down Expand Up @@ -1816,10 +1810,7 @@ int InsideDollar(PHEAD WORD *ll, WORD level)
Now we have a little cleaning up to do
*/
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) {
/* UNLOCK(d->pthreadslockwrite); */
UNLOCK(d->pthreadslockread);
}
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
if ( newd->factors ) M_free(newd->factors,"Dollar factors");
M_free(newd,"Copy of dollar variable");
Expand Down Expand Up @@ -1870,7 +1861,7 @@ LONG TermsInDollar(WORD num)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand All @@ -1895,7 +1886,7 @@ LONG TermsInDollar(WORD num)
else if ( d->type == DOLZERO ) n = 0;
else n = 1;
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(n);
}
Expand All @@ -1919,7 +1910,7 @@ LONG SizeOfDollar(WORD num)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -1947,7 +1938,7 @@ LONG SizeOfDollar(WORD num)
else if ( d->type == DOLZERO ) n = 0;
else n = 1;
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(n);
}
Expand Down Expand Up @@ -2656,7 +2647,7 @@ WORD EvalDoLoopArg(PHEAD WORD *arg, WORD par)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -2784,7 +2775,7 @@ WORD TestDoLoop(PHEAD WORD *lhsbuf, WORD level)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -2862,7 +2853,7 @@ WORD TestEndDoLoop(PHEAD WORD *lhsbuf, WORD level)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
}
Expand Down Expand Up @@ -2970,7 +2961,7 @@ int DollarFactorize(PHEAD WORD numdollar)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand All @@ -2981,7 +2972,7 @@ int DollarFactorize(PHEAD WORD numdollar)
#endif
CleanDollarFactors(d);
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
if ( d->type != DOLTERMS ) { /* only one term */
if ( d->type != DOLZERO ) d->nfactors = 1;
Expand Down Expand Up @@ -3231,13 +3222,13 @@ int DollarFactorize(PHEAD WORD numdollar)
Be careful: there should be more than one factor now.
*/
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { LOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { LOCK(d->pthreadslockread); }
#endif
if ( nfactors == 1 && extrafactor == 0 ) { /* we can use the buf1 contents */
if ( factorsincontent == 0 ) {
d->nfactors = 1;
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
/*
We used here (before 3-sep-2015) the original and did not make
Expand Down Expand Up @@ -3289,7 +3280,7 @@ getout2: AR.SortType = oldsorttype;
M_free(d->factors,"factors in dollar");
d->factors = 0;
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
M_free(buf3,"DollarFactorize-4");
if ( buf2 != buf1 && buf2 ) M_free(buf2,"DollarFactorize-4");
Expand Down Expand Up @@ -3533,7 +3524,7 @@ nextj:;
#] Step 8:
*/
#ifdef WITHPTHREADS
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslockread); }
#endif
return(0);
}
Expand Down Expand Up @@ -3852,7 +3843,7 @@ int GetDolNum(PHEAD WORD *t, WORD *tstop)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -3906,7 +3897,7 @@ int GetDolNum(PHEAD WORD *t, WORD *tstop)
}
if ( nummodopt < NumModOptdollars ) {
dtype = ModOptdollars[nummodopt].type;
if ( dtype == MODLOCAL ) {
if ( DollarLocalCopy(dtype) ) {
d = ModOptdollars[nummodopt].dstruct+AT.identity;
}
else {
Expand Down Expand Up @@ -3962,4 +3953,19 @@ void AddPotModdollar(WORD numdollar)

/*
#] AddPotModdollar :
#[ DollarLocalCopy :
*/

/**
* Returns 1 if the ModOptdollar type implies a thread-local copy when running
* in TFORM (WITHPTHREADS), and 0 otherwise.
*/
inline int DollarLocalCopy(WORD type) {
if ( type == MODLOCAL ) { return 1; };
if ( type == MODMIN ) { return 1; };
if ( type == MODMAX ) { return 1; };
return 0;
}
/*
#] DollarLocalCopy :
*/
Loading
Loading