9 static int traceOn = 0 ;
10 static int freeemptyblocks = 1 ;
18 #define BLOCK_SIZE 65536
53 static char* tapblock = NULL ;
61 static unsigned int adbitbuf = 0 ;
62 static int adbitibuf = 0 ;
65 static u_int64_t pushPopTraffic = 0 ;
68 static u_int64_t maxBlocks = 0 ;
76 #pragma omp threadprivate(tappos, tapblock, curStack, adbitbuf, adbitibuf, topRepetitionPoint)
94 repetitionLevel->
backPop = tappos ;
100 tappos = repetitionLevel->
backPop ;
116 repetitionLevel->
freePush = tappos ;
122 tappos = repetitionLevel->
freePush ;
128 int curL1 = curStack->
rank ;
131 int fpL2 = repetitionLevel->
freePush ;
134 return (curL1<fpL1 || (curL1==fpL1 && curL2<fpL2)) ;
140 int curL1 = curStack->
rank ;
143 int fpL2 = repetitionLevel->
freePush ;
146 return (curL1==fpL1 && curL2==fpL2) ;
150 printf(
"%1i.%05i", (locBlock ? locBlock->
rank : 0), loc) ;
155 while (repetitionPoint) {
156 printf(
" REPETITION LEVEL ACTIVE:%s BP:%s",
157 (repetitionPoint->
active?
"yes":
"no"),
166 repetitionPoint = repetitionPoint->
previous ;
167 if (repetitionPoint) printf(
" ...in") ;
178 while (topActive && !topActive->
active) {
185 printf(
"BEFORE PUSH AT ") ;
187 printf(
" WITH REPETITION LEVELS:\n") ;
189 printf(
" MOVE TO FREE PUSH LOCATION ") ;
201 if (traceOn && moves) {
202 printf(
"AFTER POP, LOCATION WAS ") ;
204 printf(
" WITH REPETITION LEVELS:\n") ;
207 int canEraseInactive = 1 ;
208 int canRemoveBackPop = 1 ;
213 if (canRemoveBackPop) oldCell->
hasBackPop = 0 ;
215 repetitionPoint = oldCell->
previous ;
216 if (!oldCell->
active && canEraseInactive) {
220 canEraseInactive = 0 ;
221 canRemoveBackPop = 0 ;
223 }
while (repetitionPoint) ;
224 if (traceOn && moves) {
225 printf(
" MOVED TO BACK POP LOCATION:") ;
237 printf(
"BEFORE START REPEAT AT ") ;
246 newRepetitionLevel->
active = 1 ;
248 newRepetitionLevel->
backPop = 0 ;
257 if (curStack==NULL) {
275 printf(
">AFTER START REPEAT AT:") ;
287 printf(
"BEFORE RESET REPEAT AT ") ;
304 printf(
">AFTER RESET REPEAT AT ") ;
314 printf(
"BEFORE END REPEAT AT ") ;
321 while (!topActive->
active) {
328 printf(
">AFTER END REPEAT AT ") ;
339 if (curStack && curStack->
next) {
340 curStack = curStack->
next ;
343 if (newStack == NULL) {
345 printf(
"Out of memory in AD Stack.\n") ;
348 if(curStack != NULL) {
349 curStack->
next = newStack ;
350 newStack->
rank = curStack->
rank + 1 ;
355 newStack->
prev = curStack ;
356 newStack->
next = NULL ;
357 curStack = newStack ;
359 #ifdef _ADSTACKPROFILE
360 if (curStack->
rank > maxBlocks) maxBlocks = curStack->
rank ;
368 curStack = curStack->
prev ;
369 if (freeemptyblocks) {
374 if (curStack) curStack->
next = NULL ;
378 return (curStack ? curStack->
contents : NULL) ;
393 memcpy(tapblock+tappos,
x,wsize) ;
398 else if (nbChars > 0) {
402 }
while(nbChars > 0) ;
408 int wsize = (nbChars<tappos)?nbChars:tappos ;
410 memcpy(
x-wsize,tapblock+tappos-wsize,wsize) ;
415 else if (nbChars > 0) {
419 }
while(nbChars > 0) ;
425 #ifdef _ADSTACKPROFILE
426 pushPopTraffic += (int)(n*4) ;
433 #ifdef _ADSTACKPROFILE
434 pushPopTraffic += (int)(n*4) ;
441 #ifdef _ADSTACKPROFILE
442 pushPopTraffic += (int)(n*8) ;
449 #ifdef _ADSTACKPROFILE
450 pushPopTraffic += (int)(n*8) ;
457 #ifdef _ADSTACKPROFILE
458 pushPopTraffic += (int)(n*4) ;
465 #ifdef _ADSTACKPROFILE
466 pushPopTraffic += (int)(n*4) ;
473 #ifdef _ADSTACKPROFILE
474 pushPopTraffic += (int)(n*8) ;
481 #ifdef _ADSTACKPROFILE
482 pushPopTraffic += (int)(n*8) ;
489 #ifdef _ADSTACKPROFILE
490 pushPopTraffic += (int)(n*16) ;
497 #ifdef _ADSTACKPROFILE
498 pushPopTraffic += (int)(n*16) ;
505 #ifdef _ADSTACKPROFILE
506 pushPopTraffic += (int)(n*8) ;
513 #ifdef _ADSTACKPROFILE
514 pushPopTraffic += (int)(n*8) ;
521 #ifdef _ADSTACKPROFILE
522 pushPopTraffic += (int)(n*16) ;
529 #ifdef _ADSTACKPROFILE
530 pushPopTraffic += (int)(n*16) ;
537 #ifdef _ADSTACKPROFILE
538 pushPopTraffic += (int)n ;
545 #ifdef _ADSTACKPROFILE
546 pushPopTraffic += (int)n ;
558 *(
char*)(tapblock+tappos) = val;
559 tappos = tappos + 1 ;
561 #ifdef _ADSTACKPROFILE
562 pushPopTraffic += 1 ;
571 tappos = tappos - 1 ;
572 *val = *(
char*)(tapblock+tappos);
575 #ifdef _ADSTACKPROFILE
576 pushPopTraffic += 1 ;
586 *(
float*)(tapblock+tappos) = val;
587 tappos = tappos + 4 ;
589 #ifdef _ADSTACKPROFILE
590 pushPopTraffic += 4 ;
599 tappos = tappos - 4 ;
600 *val = *(
float*)(tapblock+tappos);
603 #ifdef _ADSTACKPROFILE
604 pushPopTraffic += 4 ;
614 *(
double*)(tapblock+tappos) = val;
615 tappos = tappos + 8 ;
617 #ifdef _ADSTACKPROFILE
618 pushPopTraffic += 8 ;
627 tappos = tappos - 8 ;
628 *val = *(
double*)(tapblock+tappos);
631 #ifdef _ADSTACKPROFILE
632 pushPopTraffic += 8 ;
642 memcpy(tapblock+tappos, (
void *)val, 16);
643 tappos = tappos + 16 ;
645 #ifdef _ADSTACKPROFILE
646 pushPopTraffic += 16 ;
651 if(tappos - 16 < 0) {
655 tappos = tappos - 16 ;
656 memcpy((
void *)val, tapblock+tappos, 16) ;
659 #ifdef _ADSTACKPROFILE
660 pushPopTraffic += 16 ;
670 *(
int*)(tapblock+tappos) = val;
671 tappos = tappos + 4 ;
673 #ifdef _ADSTACKPROFILE
674 pushPopTraffic += 4 ;
683 tappos = tappos - 4 ;
684 *val = *(
int*)(tapblock+tappos);
687 #ifdef _ADSTACKPROFILE
688 pushPopTraffic += 4 ;
698 *(
long*)(tapblock+tappos) = val;
699 tappos = tappos + 8 ;
701 #ifdef _ADSTACKPROFILE
702 pushPopTraffic += 8 ;
711 tappos = tappos - 8 ;
712 *val = *(
long*)(tapblock+tappos);
715 #ifdef _ADSTACKPROFILE
716 pushPopTraffic += 8 ;
726 *(
ccmplx*)(tapblock+tappos) = val;
727 tappos = tappos + 8 ;
729 #ifdef _ADSTACKPROFILE
730 pushPopTraffic += 8 ;
739 tappos = tappos - 8 ;
740 *val = *(
ccmplx*)(tapblock+tappos);
743 #ifdef _ADSTACKPROFILE
744 pushPopTraffic += 8 ;
754 *(
double complex *)(tapblock+tappos) = val;
755 tappos = tappos + 16 ;
757 #ifdef _ADSTACKPROFILE
758 pushPopTraffic += 16 ;
763 if(tappos - 16 < 0) {
767 tappos = tappos - 16 ;
768 *val = *(
double complex *)(tapblock+tappos);
771 #ifdef _ADSTACKPROFILE
772 pushPopTraffic += 16 ;
782 *(
void**)(tapblock+tappos) = val;
783 tappos = tappos + 4 ;
785 #ifdef _ADSTACKPROFILE
786 pushPopTraffic += 4 ;
795 tappos = tappos - 4 ;
796 *val = *(
void**)(tapblock+tappos);
799 #ifdef _ADSTACKPROFILE
800 pushPopTraffic += 4 ;
810 *(
void**)(tapblock+tappos) = val;
811 tappos = tappos + 8 ;
813 #ifdef _ADSTACKPROFILE
814 pushPopTraffic += 8 ;
823 tappos = tappos - 8 ;
824 *val = *(
void**)(tapblock+tappos);
827 #ifdef _ADSTACKPROFILE
828 pushPopTraffic += 8 ;
841 #ifdef _ADSTACKPROFILE
842 pushPopTraffic += 4 ;
852 #ifdef _ADSTACKPROFILE
853 pushPopTraffic += 4 ;
857 int result = adbitbuf%2 ;
1065 printf(
"Peak stack size (%1li blocks): %1llu bytes\n",
1066 maxBlocks, maxBlocks*((
long int)
BLOCK_SIZE)) ;
1070 printf(
"Total push/pop traffic %1lu bytes\n", pushPopTraffic) ;
1074 printf(
" %i--> <",label) ;
1080 if (!curStack || (tappos==0 && !curStack->
prev)) {
1081 printf (
"Stack at %s is empty\n", locationName) ;
1083 printf (
"Stack top at %s is %1i.%05i :\n", locationName, curStack->
rank, tappos) ;
1084 int bytesToShow = 20 ;
1085 int blocksToShow = 3 ;
1087 int inPos = tappos ;
1088 while (blocksToShow>0 && inStack) {
1089 printf(
" Block %d:", inStack->
rank) ;
1090 while (bytesToShow>0 && inPos>0) {
1091 printf(
" %02x", (
unsigned char)inStack->
contents[--inPos]) ;
1095 printf(
" ...<%d more bytes>...", inPos) ;
1098 inStack = inStack->
prev ;
1102 printf(
" %d more blocks below\n", inStack->
rank) ;
1105 printf(
"Bit buffer is empty\n") ;
1107 printf(
"Bit buffer:%1i in %08x\n", adbitibuf, adbitbuf) ;
1110 printf(
"Repetition levels:\n ") ;
1113 printf(
"----------------\n") ;
1206 #ifdef _ADSTACKPROFILE
1207 pushPopTraffic += *n*4 ;
1214 #ifdef _ADSTACKPROFILE
1215 pushPopTraffic += *n*4 ;
void adStack_showStackSize(int label)
void popReal16Array(long double *x, int n)
void pushControl6b(int cc)
void popNArray(char *x, int nbChars)
void popreal4array_(float *ii, int *ll)
void popcontrol1b_(int *cc)
void popReal8(double *val)
void pushreal16_(long double *val)
RepetitionLevel * topRepetitionPoint
void pushInteger8Array(long *x, int n)
void adStack_resetRepeat()
void setCurrentLocationToResumePoint(RepetitionLevel *repetitionLevel)
void pushcharacter_(char *val)
void pushbooleanarray_(char *x, int *n)
void setCurrentLocationToBackPop(RepetitionLevel *repetitionLevel)
void pushReal8Array(double *x, int n)
void pushinteger4_(int *val)
void adstack_resetrepeat_()
void pushReal4(float val)
void pushControl7b(int cc)
void pushComplex16(double complex val)
void popcomplex16_(cdcmplx *val)
void adstack_showstack_(char *locationName)
void setResumePointToCurrentLocation(RepetitionLevel *repetitionLevel)
void pushReal16Array(long double *x, int n)
void popcontrol6b_(int *cc)
void poppointer4_(void **val)
void popControl1b(int *cc)
void popinteger8_(long *val)
void pushpointer8_(void **val)
void popcontrol4b_(int *cc)
void pushboolean_(int *x)
void popreal8_(double *val)
void popPointer8(void **val)
void adStack_showStack(char *locationName)
void pushcomplex8array_(ccmplx *ii, int *ll)
void popComplex16Array(double complex *x, int n)
void adStack_showTotalTraffic()
void pushinteger8_(long *val)
void popcontrol8b_(int *cc)
struct _RepetitionLevel RepetitionLevel
int currentLocationEqualsFreePush(RepetitionLevel *repetitionLevel)
void pushComplex16Array(double complex *x, int n)
void checkPushInReadOnly()
struct _DoubleChainedBlock DoubleChainedBlock
void pushComplex8Array(ccmplx *x, int n)
void pushcontrol5b_(int *cc)
void pushcharacterarray_(char *ii, int *ll)
void pushcomplex16_(cdcmplx *val)
void poppointer8_(void **val)
void adstack_showpeaksize_()
void pushcontrol6b_(int *cc)
void pushPointer8(void *val)
void popInteger8Array(long *x, int n)
void pushCharacter(char val)
void popComplex8(ccmplx *val)
void popcomplex16array_(cdcmplx *ii, int *ll)
void popComplex16(double complex *val)
void adStack_startRepeat()
void pushInteger4Array(int *x, int n)
void popControl8b(int *cc)
void popControl3b(int *cc)
void pushControl8b(int cc)
void pushReal8(double val)
void popreal16_(long double *val)
void showRepetitionLevels()
void popInteger4(int *val)
void pushcontrol7b_(int *cc)
void popReal16(long double *val)
void pushControl3b(int cc)
void pushInteger8(long val)
void popcontrol2b_(int *cc)
void pushcontrol3b_(int *cc)
void pushControl4b(int cc)
void pushreal4_(float *val)
void popreal4_(float *val)
void popcontrol5b_(int *cc)
void pushreal8array_(double *ii, int *ll)
void popControl2b(int *cc)
void popReal4Array(float *x, int n)
void pushreal16array_(long double *ii, int *ll)
void pushReal4Array(float *x, int n)
void pushcontrol2b_(int *cc)
void pushpointer4_(void **val)
void popcharacterarray_(char *ii, int *ll)
void pushinteger4array_(int *ii, int *ll)
void popControl7b(int *cc)
void popControl5b(int *cc)
void popCharacter(char *val)
void pushinteger8array_(long *ii, int *ll)
void adstack_endrepeat_()
void pushNArray(char *x, int nbChars)
void adStack_showPeakSize()
void pushPointer4(void *val)
void popInteger4Array(int *x, int n)
void adstack_showstacksize_(int *label)
void pushControl2b(int cc)
void popInteger8(long *val)
void pushReal16(long double *val)
void popinteger4array_(int *ii, int *ll)
void pushcontrol4b_(int *cc)
void popreal16array_(long double *ii, int *ll)
void popcomplex8_(ccmplx *val)
void setCurrentLocationToFreePush(RepetitionLevel *repetitionLevel)
void popComplex8Array(ccmplx *x, int n)
void pushcomplex16array_(cdcmplx *ii, int *ll)
void popcharacter_(char *val)
void popinteger8array_(long *ii, int *ll)
void popReal8Array(double *x, int n)
void popcomplex8array_(ccmplx *ii, int *ll)
void pushControl5b(int cc)
void pushreal4array_(float *ii, int *ll)
void pushcomplex8_(ccmplx *val)
void popcontrol3b_(int *cc)
void popReal4(float *val)
int currentLocationStrictBelowFreePush(RepetitionLevel *repetitionLevel)
void popcontrol7b_(int *cc)
void showLocation(DoubleChainedBlock *locBlock, int loc)
void popreal8array_(double *ii, int *ll)
void popPointer4(void **val)
void popControl6b(int *cc)
void pushControl1b(int cc)
void popCharacterArray(char *x, int n)
void popControl4b(int *cc)
void pushcontrol8b_(int *cc)
void pushComplex8(ccmplx val)
void adstack_showtotaltraffic_()
void popinteger4_(int *val)
void pushCharacterArray(char *x, int n)
void checkPopToReadOnly()
void pushreal8_(double *val)
void setBackPopToCurrentLocation(RepetitionLevel *repetitionLevel)
void pushInteger4(int val)
void pushcontrol1b_(int *cc)
void popbooleanarray_(char *x, int *n)
void adstack_startrepeat_()
void setFreePushToCurrentLocation(RepetitionLevel *repetitionLevel)
real(kind=realtype), dimension(:, :, :, :), pointer x
char contents[BLOCK_SIZE]
struct _DoubleChainedBlock * next
struct _DoubleChainedBlock * prev
DoubleChainedBlock * backPopBlock
DoubleChainedBlock * freePushBlock
unsigned int storedadbitbuf
DoubleChainedBlock * resumePointBlock
struct _RepetitionLevel * previous