Back to home page

MITgcm

 
 

    


File indexing completed on 2023-05-28 05:10:57 UTC

view on githubraw file Latest commit b4daa243 on 2023-05-28 03:53:22 UTC
b4daa24319 Shre*0001 /*
                0002  * TAPENADE Automatic Differentiation Engine
                0003  * Copyright (C) 1999-2021 Inria
                0004  * See the LICENSE.md file in the project root for more information.
                0005  *
                0006  */
                0007 
                0008 #include <stdlib.h>
                0009 #include <stdio.h>
                0010 #include <string.h>
                0011 
                0012 #include "OLDadStack.h"
                0013 #include "OLDadBuffer.h"
                0014 
                0015 /************ MEASUREMENT OF PUSH TRAFFIC *************/
                0016 
                0017 static long int bufferTraffic = 0 ;
                0018 
                0019 void addBufferTraffic(int n) {
                0020   bufferTraffic += n ;
                0021 }
                0022 
                0023 void adStack_showTraffic() {
                0024   showTotalTraffic(bufferTraffic) ;
                0025 }
                0026 
                0027 /************************** integer*4 ************************/
                0028 /* The buffer array for I4. Suggested size 512 */
                0029 #define I4BUFSIZE 512
                0030 static int adi4buf[I4BUFSIZE] ;
                0031 static int adi4ibuf = 0 ;
                0032 
                0033 void pushInteger4(int x) {
                0034   addBufferTraffic(4) ;
                0035   adi4buf[adi4ibuf] = x ;
                0036   if (adi4ibuf>=I4BUFSIZE-1) {
                0037     pushNArray((char *)adi4buf, I4BUFSIZE*4, 1) ;
                0038     addBufferTraffic(-I4BUFSIZE*4) ;
                0039     adi4ibuf = 0 ;
                0040   } else
                0041     ++adi4ibuf ;
                0042 }
                0043 
                0044 void popInteger4(int *x) {
                0045   if (adi4ibuf<=0) {
                0046     popNArray((char *)adi4buf, I4BUFSIZE*4, 1) ;
                0047     adi4ibuf = I4BUFSIZE-1 ;
                0048   } else
                0049     --adi4ibuf ;
                0050   *x = adi4buf[adi4ibuf] ;
                0051 }
                0052 
                0053 /************************** integer*8 ************************/
                0054 /* The buffer array for I8. Suggested size 512 */
                0055 #define I8BUFSIZE 512
                0056 static long adi8buf[I8BUFSIZE] ;
                0057 static int adi8ibuf = 0 ;
                0058 
                0059 void pushInteger8(long x) {
                0060   addBufferTraffic(8) ;
                0061   adi8buf[adi8ibuf] = x ;
                0062   if (adi8ibuf>=I8BUFSIZE-1) {
                0063     pushNArray((char *)adi8buf, I8BUFSIZE*8, 1) ;
                0064     addBufferTraffic(-I8BUFSIZE*8) ;
                0065     adi8ibuf = 0 ;
                0066   } else
                0067     ++adi8ibuf ;
                0068 }
                0069 
                0070 void popInteger8(long *x) {
                0071   if (adi8ibuf<=0) {
                0072     popNArray((char *)adi8buf, I8BUFSIZE*8, 1) ;
                0073     adi8ibuf = I8BUFSIZE-1 ;
                0074   } else
                0075     --adi8ibuf ;
                0076   *x = adi8buf[adi8ibuf] ;
                0077 }
                0078 
                0079 /************************** real*4 ************************/
                0080 // The buffer array for R4. Suggested size 512
                0081 #define R4BUFSIZE 512
                0082 static float adr4buf[R4BUFSIZE] ;
                0083 static int adr4ibuf = 0 ;
                0084 
                0085 void pushReal4(float x) {
                0086   addBufferTraffic(4) ;
                0087   adr4buf[adr4ibuf] = x ;
                0088   if (adr4ibuf>=R4BUFSIZE-1) {
                0089     pushNArray((char *)adr4buf, R4BUFSIZE*4, 1) ;
                0090     addBufferTraffic(-R4BUFSIZE*4) ;
                0091     adr4ibuf = 0 ;
                0092   } else
                0093     ++adr4ibuf ;
                0094 }
                0095 
                0096 void popReal4(float *x) {
                0097   if (adr4ibuf<=0) {
                0098     popNArray((char *)adr4buf, R4BUFSIZE*4, 1) ;
                0099     adr4ibuf = R4BUFSIZE-1 ;
                0100   } else
                0101     --adr4ibuf ;
                0102   *x = adr4buf[adr4ibuf] ;
                0103 }
                0104 
                0105 /************************** real*8 ************************/
                0106 // The buffer array for r8. Suggested size 512
                0107 #define R8BUFSIZE 512
                0108 static double adr8buf[R8BUFSIZE] ;
                0109 static int adr8ibuf = 0 ;
                0110 
                0111 void pushReal8(double x) {
                0112   addBufferTraffic(8) ;
                0113   adr8buf[adr8ibuf] = x ;
                0114   if (adr8ibuf>=R8BUFSIZE-1) {
                0115     pushNArray((char *)adr8buf, R8BUFSIZE*8, 1) ;
                0116     addBufferTraffic(-R8BUFSIZE*8) ;
                0117     adr8ibuf = 0 ;
                0118   } else
                0119     ++adr8ibuf ;
                0120 }
                0121 
                0122 void popReal8(double *x) {
                0123   if (adr8ibuf<=0) {
                0124     popNArray((char *)adr8buf, R8BUFSIZE*8, 1) ;
                0125     adr8ibuf = R8BUFSIZE-1 ;
                0126   } else
                0127     --adr8ibuf ;
                0128   *x = adr8buf[adr8ibuf] ;
                0129 }
                0130 
                0131 /************************** complex*8 ************************/
                0132 // The buffer array for C8. Suggested size 512
                0133 #define C8BUFSIZE 512
                0134 static ccmplx adc8buf[C8BUFSIZE] ;
                0135 static int adc8ibuf = 0 ;
                0136 
                0137 void pushComplex8(ccmplx x) {
                0138   addBufferTraffic(8) ;
                0139   adc8buf[adc8ibuf] = x ;
                0140   if (adc8ibuf>=C8BUFSIZE-1) {
                0141     pushNArray((char *)adc8buf, C8BUFSIZE*8, 1) ;
                0142     addBufferTraffic(-C8BUFSIZE*8) ;
                0143     adc8ibuf = 0 ;
                0144   } else
                0145   ++adc8ibuf ;
                0146 }
                0147 
                0148 void popComplex8(ccmplx *x) {
                0149   if (adc8ibuf<=0) {
                0150     popNArray((char *)adc8buf, C8BUFSIZE*8, 1) ;
                0151     adc8ibuf = C8BUFSIZE-1 ;
                0152   } else
                0153     --adc8ibuf ;
                0154   *x = adc8buf[adc8ibuf] ;
                0155 }
                0156 
                0157 /************************** complex*16 ************************/
                0158 // The buffer array for C16. Suggested size 512
                0159 #define C16BUFSIZE 512
                0160 static cdcmplx adc16buf[C16BUFSIZE] ;
                0161 static int adc16ibuf = 0 ;
                0162 
                0163 void pushComplex16(cdcmplx x) {
                0164   addBufferTraffic(16) ;
                0165   adc16buf[adc16ibuf] = x ;
                0166   if (adc16ibuf>=C16BUFSIZE-1) {
                0167     pushNArray((char *)adc16buf, C16BUFSIZE*16, 1) ;
                0168     addBufferTraffic(-C16BUFSIZE*16) ;
                0169     adc16ibuf = 0 ;
                0170   } else
                0171     ++adc16ibuf ;
                0172 }
                0173 
                0174 void popComplex16(cdcmplx *x) {
                0175   if (adc16ibuf<=0) {
                0176     popNArray((char *)adc16buf, C16BUFSIZE*16, 1) ;
                0177     adc16ibuf = C16BUFSIZE-1 ;
                0178   } else
                0179     --adc16ibuf ;
                0180   *x = adc16buf[adc16ibuf] ;
                0181 }
                0182 
                0183 /************************** character ************************/
                0184 // The buffer array for characters. Suggested size 512
                0185 #define CHARBUFSIZE 512
                0186 static char ads1buf[CHARBUFSIZE] ;
                0187 static int ads1ibuf = 0 ;
                0188 
                0189 void pushCharacter(char x) {
                0190   addBufferTraffic(1) ;
                0191   ads1buf[ads1ibuf] = x ;
                0192   if (ads1ibuf>=CHARBUFSIZE-1) {
                0193     pushNArray((char *)ads1buf, CHARBUFSIZE, 1) ;
                0194     addBufferTraffic(-CHARBUFSIZE) ;
                0195     ads1ibuf = 0 ;
                0196   } else
                0197     ++ads1ibuf ;
                0198 }
                0199 
                0200 void popCharacter(char *x) {
                0201   if (ads1ibuf<=0) {
                0202     popNArray((char *)ads1buf, CHARBUFSIZE, 1) ;
                0203     ads1ibuf = CHARBUFSIZE-1 ;
                0204   } else
                0205     --ads1ibuf ;
                0206   *x = ads1buf[ads1ibuf] ;
                0207 }
                0208 
                0209 /******************* bit (hidden primitives) ***************/
                0210 static unsigned int adbitbuf = 0 ;
                0211 static int adbitibuf = 0 ;
                0212 
                0213 void pushBit(int x) {
                0214   adbitbuf<<=1 ;
                0215   if (x) ++adbitbuf ;
                0216   if (adbitibuf>=31) {
                0217     pushNArray((char *)&adbitbuf, 4, 1) ;
                0218     adbitbuf = 0 ;
                0219     adbitibuf = 0 ;
                0220   } else
                0221     ++adbitibuf ;
                0222 }
                0223 
                0224 int popBit() {
                0225   if (adbitibuf<=0) {
                0226     popNArray((char *)&adbitbuf, 4, 1) ;
                0227     adbitibuf = 31 ;
                0228   } else
                0229     --adbitibuf ;
                0230   int result = adbitbuf%2 ;
                0231   adbitbuf>>=1 ;
                0232   return result ;
                0233 }
                0234 
                0235 /*************************** boolean *************************/
                0236 
                0237 void pushBoolean(int x) {
                0238   pushBit(x) ;
                0239 }
                0240 
                0241 void popBoolean(int *x) {
                0242   *x = popBit() ;
                0243 }
                0244 
                0245 /************************* control ***********************/
                0246 
                0247 void pushControl1b(int cc) {
                0248   pushBit(cc) ;
                0249 }
                0250 
                0251 void popControl1b(int *cc) {
                0252   *cc = popBit() ;
                0253 }
                0254 
                0255 void pushControl2b(int cc) {
                0256   pushBit(cc%2) ;
                0257   cc>>=1 ;
                0258   pushBit(cc) ;
                0259 }
                0260 
                0261 void popControl2b(int *cc) {
                0262   *cc = (popBit()?2:0) ;
                0263   if (popBit()) (*cc)++ ;
                0264 }
                0265 
                0266 void pushControl3b(int cc) {
                0267   pushBit(cc%2) ;
                0268   cc>>=1 ;
                0269   pushBit(cc%2) ;
                0270   cc>>=1 ;
                0271   pushBit(cc) ;
                0272 }
                0273 
                0274 void popControl3b(int *cc) {
                0275   *cc = (popBit()?2:0) ;
                0276   if (popBit()) (*cc)++ ;
                0277   (*cc) <<= 1 ;
                0278   if (popBit()) (*cc)++ ;
                0279 }
                0280 
                0281 void pushControl4b(int cc) {
                0282   pushBit(cc%2) ;
                0283   cc>>=1 ;
                0284   pushBit(cc%2) ;
                0285   cc>>=1 ;
                0286   pushBit(cc%2) ;
                0287   cc>>=1 ;
                0288   pushBit(cc) ;
                0289 }
                0290 
                0291 void popControl4b(int *cc) {
                0292   *cc = (popBit()?2:0) ;
                0293   if (popBit()) (*cc)++ ;
                0294   (*cc) <<= 1 ;
                0295   if (popBit()) (*cc)++ ;
                0296   (*cc) <<= 1 ;
                0297   if (popBit()) (*cc)++ ;
                0298 }
                0299 
                0300 void pushControl5b(int cc) {
                0301   pushBit(cc%2) ;
                0302   cc>>=1 ;
                0303   pushBit(cc%2) ;
                0304   cc>>=1 ;
                0305   pushBit(cc%2) ;
                0306   cc>>=1 ;
                0307   pushBit(cc%2) ;
                0308   cc>>=1 ;
                0309   pushBit(cc) ;
                0310 }
                0311 
                0312 void popControl5b(int *cc) {
                0313   *cc = (popBit()?2:0) ;
                0314   if (popBit()) (*cc)++ ;
                0315   (*cc) <<= 1 ;
                0316   if (popBit()) (*cc)++ ;
                0317   (*cc) <<= 1 ;
                0318   if (popBit()) (*cc)++ ;
                0319   (*cc) <<= 1 ;
                0320   if (popBit()) (*cc)++ ;
                0321 }
                0322 
                0323 void pushControl6b(int cc) {
                0324   pushBit(cc%2) ;
                0325   cc>>=1 ;
                0326   pushBit(cc%2) ;
                0327   cc>>=1 ;
                0328   pushBit(cc%2) ;
                0329   cc>>=1 ;
                0330   pushBit(cc%2) ;
                0331   cc>>=1 ;
                0332   pushBit(cc%2) ;
                0333   cc>>=1 ;
                0334   pushBit(cc) ;
                0335 }
                0336 
                0337 void popControl6b(int *cc) {
                0338   *cc = (popBit()?2:0) ;
                0339   if (popBit()) (*cc)++ ;
                0340   (*cc) <<= 1 ;
                0341   if (popBit()) (*cc)++ ;
                0342   (*cc) <<= 1 ;
                0343   if (popBit()) (*cc)++ ;
                0344   (*cc) <<= 1 ;
                0345   if (popBit()) (*cc)++ ;
                0346   (*cc) <<= 1 ;
                0347   if (popBit()) (*cc)++ ;
                0348 }
                0349 
                0350 void pushControl7b(int cc) {
                0351   pushBit(cc%2) ;
                0352   cc>>=1 ;
                0353   pushBit(cc%2) ;
                0354   cc>>=1 ;
                0355   pushBit(cc%2) ;
                0356   cc>>=1 ;
                0357   pushBit(cc%2) ;
                0358   cc>>=1 ;
                0359   pushBit(cc%2) ;
                0360   cc>>=1 ;
                0361   pushBit(cc%2) ;
                0362   cc>>=1 ;
                0363   pushBit(cc) ;
                0364 }
                0365 
                0366 void popControl7b(int *cc) {
                0367   *cc = (popBit()?2:0) ;
                0368   if (popBit()) (*cc)++ ;
                0369   (*cc) <<= 1 ;
                0370   if (popBit()) (*cc)++ ;
                0371   (*cc) <<= 1 ;
                0372   if (popBit()) (*cc)++ ;
                0373   (*cc) <<= 1 ;
                0374   if (popBit()) (*cc)++ ;
                0375   (*cc) <<= 1 ;
                0376   if (popBit()) (*cc)++ ;
                0377   (*cc) <<= 1 ;
                0378   if (popBit()) (*cc)++ ;
                0379 }
                0380 
                0381 void pushControl8b(int cc) {
                0382   pushBit(cc%2) ;
                0383   cc>>=1 ;
                0384   pushBit(cc%2) ;
                0385   cc>>=1 ;
                0386   pushBit(cc%2) ;
                0387   cc>>=1 ;
                0388   pushBit(cc%2) ;
                0389   cc>>=1 ;
                0390   pushBit(cc%2) ;
                0391   cc>>=1 ;
                0392   pushBit(cc%2) ;
                0393   cc>>=1 ;
                0394   pushBit(cc%2) ;
                0395   cc>>=1 ;
                0396   pushBit(cc) ;
                0397 }
                0398 
                0399 void popControl8b(int *cc) {
                0400   *cc = (popBit()?2:0) ;
                0401   if (popBit()) (*cc)++ ;
                0402   (*cc) <<= 1 ;
                0403   if (popBit()) (*cc)++ ;
                0404   (*cc) <<= 1 ;
                0405   if (popBit()) (*cc)++ ;
                0406   (*cc) <<= 1 ;
                0407   if (popBit()) (*cc)++ ;
                0408   (*cc) <<= 1 ;
                0409   if (popBit()) (*cc)++ ;
                0410   (*cc) <<= 1 ;
                0411   if (popBit()) (*cc)++ ;
                0412   (*cc) <<= 1 ;
                0413   if (popBit()) (*cc)++ ;
                0414 }
                0415 
                0416 /************************* pointer ************************/
                0417 // The buffer array for pointers. Suggested size PTRBUFSIZE 512
                0418 // Depending on the system, these use 4 or 8 bytes,
                0419 // but they are all 4 or all 8, never a mixture of both.
                0420 #define PTRBUFSIZE 512
                0421 static void * adptrbuf[PTRBUFSIZE] ;
                0422 static int adptribuf = 0 ;
                0423 
                0424 void pushPointer4(void *x) {
                0425   addBufferTraffic(4) ;
                0426   adptrbuf[adptribuf] = x ;
                0427   if (adptribuf>=PTRBUFSIZE-1) {
                0428     pushNArray((char *)adptrbuf, PTRBUFSIZE*4, 1) ;
                0429     addBufferTraffic(-PTRBUFSIZE*4) ;
                0430     adptribuf = 0 ;
                0431   } else
                0432     ++adptribuf ;
                0433 }
                0434 
                0435 void popPointer4(void **x) {
                0436   if (adptribuf<=0) {
                0437     popNArray((char *)adptrbuf, PTRBUFSIZE*4, 1) ;
                0438     adptribuf = PTRBUFSIZE-1 ;
                0439   } else
                0440     --adptribuf ;
                0441   *x = adptrbuf[adptribuf] ;
                0442 }
                0443 
                0444 void pushPointer8(void *x) {
                0445   addBufferTraffic(8) ;
                0446   adptrbuf[adptribuf] = x ;
                0447   if (adptribuf>=PTRBUFSIZE-1) {
                0448     pushNArray((char *)adptrbuf, PTRBUFSIZE*8, 1) ;
                0449     addBufferTraffic(-PTRBUFSIZE*8) ;
                0450     adptribuf = 0 ;
                0451   } else
                0452     ++adptribuf ;
                0453 }
                0454 
                0455 void popPointer8(void **x) {
                0456   if (adptribuf<=0) {
                0457     popNArray((char *)adptrbuf, PTRBUFSIZE*8, 1) ;
                0458     adptribuf = PTRBUFSIZE-1 ;
                0459   } else
                0460     --adptribuf ;
                0461   *x = adptrbuf[adptribuf] ;
                0462 }
                0463 
                0464 /**********************************************************
                0465  *        HOW TO CREATE PUSH* POP* SUBROUTINES
                0466  *             YET FOR OTHER DATA TYPES
                0467  * Duplicate and uncomment the commented code below.
                0468  * In the duplicated and uncommented code, replace:
                0469  *   ctct -> C type name (e.g. float double, int...)
                0470  *   tttt -> BASIC TAPENADE TYPE NAME
                0471  *     (in character, boolean, integer, real, complex, pointer,...)
                0472  *   z7   -> LETTERSIZE FOR TYPE
                0473  *     (LETTER in s, b, i, r, c, p, ...) (SIZE is type size in bytes)
                0474  *   7    -> TYPE SIZE IN BYTES
                0475  **********************************************************/
                0476 
                0477 /************************** tttt*7 ************************/
                0478 /*
                0479 // The buffer array for Z7. Suggested size 512
                0480 #define Z7BUFSIZE 512
                0481 static ctct adz7buf[Z7BUFSIZE] ;
                0482 static ctct adz7ibuf = 0 ;
                0483 
                0484 void pushTttt7(ctct x) {
                0485   addBufferTraffic(7) ;
                0486   adz7buf[adz7ibuf] = x ;
                0487   if (adz7ibuf>=Z7BUFSIZE-1) {
                0488     pushNArray((char *)adz7buf, Z7BUFSIZE*7, 1) ;
                0489     addBufferTraffic(-Z7BUFSIZE*7) ;
                0490     adz7ibuf = 0 ;
                0491   } else
                0492     ++adz7ibuf ;
                0493 }
                0494 
                0495 void popTttt7(ctct *x) {
                0496   if (adz7ibuf <= 0) {
                0497     popNArray((char *)adz7buf, Z7BUFSIZE*7, 1) ;
                0498     adz7ibuf = Z7BUFSIZE-1 ;
                0499   } else
                0500     --adz7ibuf ;
                0501   *x = adz7buf[adz7ibuf] ;
                0502 }
                0503 
                0504 void pushTttt7Array(ctct *x, int n) {
                0505   pushNArray((char *)x,(unsigned int)(n*7), 1) ;
                0506 }
                0507 
                0508 void popTttt7Array(ctct *x, int n) {
                0509   popNArray((char *)x,(unsigned int)(n*7), 1) ;
                0510 }
                0511 */
                0512 
                0513 /*************** REPEATED ACCESS MECHANISM *********************/
                0514 
                0515 typedef struct _BufferRepeatCell {
                0516   int indexi4 ;
                0517   int indexi8 ;
                0518   int indexr4 ;
                0519   int indexr8 ;
                0520   int indexc8 ;
                0521   int indexc16 ;
                0522   int indexs1 ;
                0523   int indexbit ;
                0524   int indexptr ;
                0525   struct _BufferRepeatCell *previous ;
                0526 } BufferRepeatCell ;
                0527 
                0528 BufferRepeatCell *bufferRepeatTop = NULL ;
                0529 
                0530 void adStack_startRepeat() {
                0531   // Create (push) a new "buffers" repeat level:
                0532   BufferRepeatCell *newRepeatCell = (BufferRepeatCell *)malloc(sizeof(BufferRepeatCell)) ;
                0533   newRepeatCell->previous = bufferRepeatTop ;
                0534   // Also create (push) a new repeat level for the main stack:
                0535   startStackRepeat1() ;
                0536   // Push all local buffers on the main stack
                0537   // 3rd arg is 0 to deactivate the check for stack read-only zone:
                0538   pushNArray((char *)adi4buf, adi4ibuf*4, 0) ;
                0539   pushNArray((char *)adi8buf, adi8ibuf*8, 0) ;
                0540   pushNArray((char *)adr4buf, adr4ibuf*4, 0) ;
                0541   pushNArray((char *)adr8buf, adr8ibuf*8, 0) ;
                0542   pushNArray((char *)adc8buf, adc8ibuf*sizeof(ccmplx), 0) ;
                0543   pushNArray((char *)adc16buf, adc16ibuf*sizeof(cdcmplx), 0) ;
                0544   pushNArray((char *)ads1buf, ads1ibuf, 0) ;
                0545   pushNArray((char *)&adbitbuf, 4, 0) ;
                0546   pushNArray((char *)adptrbuf, adptribuf*sizeof(void *), 0) ;
                0547   newRepeatCell->indexi4 = adi4ibuf ;
                0548   newRepeatCell->indexi8 = adi8ibuf ;
                0549   newRepeatCell->indexr4 = adr4ibuf ;
                0550   newRepeatCell->indexr8 = adr8ibuf ;
                0551   newRepeatCell->indexc8 = adc8ibuf ;
                0552   newRepeatCell->indexc16 = adc16ibuf ;
                0553   newRepeatCell->indexs1 = ads1ibuf ;
                0554   newRepeatCell->indexbit = adbitibuf ;
                0555   newRepeatCell->indexptr = adptribuf ;
                0556   // Store current location as repeat location of new repeat level.
                0557   // Note that this repeat location protects below as read-only.
                0558   // Make the new repeat level the current repeat level  for the main stack:
                0559   startStackRepeat2() ;
                0560   // Make this new repeat level the current repeat level:
                0561   bufferRepeatTop = newRepeatCell ;
                0562 }
                0563 
                0564 // Note: adStack_resetrepeat() forces exit from any internal
                0565 //  checkpointed sequence, i.e. all nested push'es are forced popped.
                0566 void adStack_resetRepeat() {
                0567   // First stage of reset repeat for the main stack:
                0568   resetStackRepeat1() ;
                0569   // Restore all local buffers:
                0570   adi4ibuf  = bufferRepeatTop->indexi4 ;
                0571   adi8ibuf  = bufferRepeatTop->indexi8 ;
                0572   adr4ibuf  = bufferRepeatTop->indexr4 ;
                0573   adr8ibuf  = bufferRepeatTop->indexr8 ;
                0574   adc8ibuf  = bufferRepeatTop->indexc8 ;
                0575   adc16ibuf = bufferRepeatTop->indexc16 ;
                0576   ads1ibuf  = bufferRepeatTop->indexs1 ;
                0577   adbitibuf = bufferRepeatTop->indexbit ;
                0578   adptribuf = bufferRepeatTop->indexptr ;
                0579   // 3rd arg is 0 to deactivate the check for stack read-only zone:
                0580   popNArray((char *)adptrbuf, adptribuf*sizeof(void *), 0) ;
                0581   popNArray((char *)&adbitbuf, 4, 0) ;
                0582   popNArray((char *)ads1buf,  ads1ibuf, 0) ;
                0583   popNArray((char *)adc16buf, adc16ibuf*sizeof(cdcmplx), 0) ;
                0584   popNArray((char *)adc8buf,  adc8ibuf*sizeof(ccmplx), 0) ;
                0585   popNArray((char *)adr8buf,  adr8ibuf*8, 0) ;
                0586   popNArray((char *)adr4buf,  adr4ibuf*4, 0) ;
                0587   popNArray((char *)adi8buf,  adi8ibuf*8, 0) ;
                0588   popNArray((char *)adi4buf,  adi4ibuf*4, 0) ;
                0589   // Second stage of reset repeat for the main stack:
                0590   resetStackRepeat2() ;
                0591 }
                0592 
                0593 // Note: adStack_endrepeat() forces exit from any internal
                0594 //  checkpointed sequence, i.e. all nested push'es are forced popped.
                0595 void adStack_endRepeat() {
                0596   // Remove (pop) top repeat level for the main stack:
                0597   endStackRepeat() ;
                0598   // Remove (pop) top "buffer" repeat level:
                0599   BufferRepeatCell *oldRepeatCell = bufferRepeatTop ;
                0600   bufferRepeatTop = bufferRepeatTop->previous ;
                0601   free(oldRepeatCell) ;
                0602 }
                0603 
                0604 void showBufferRepeatsRec(BufferRepeatCell *inRepeatStack, int type) {
                0605   if (inRepeatStack->previous) {showBufferRepeatsRec(inRepeatStack->previous, type) ; printf(" ; ") ;}
                0606   switch (type) {
                0607   case 1:
                0608     printf("%1i", inRepeatStack->indexi4) ;
                0609     break ;
                0610   case 2:
                0611     printf("%1i", inRepeatStack->indexi8) ;
                0612     break ;
                0613   case 3:
                0614     printf("%1i", inRepeatStack->indexr4) ;
                0615     break ;
                0616   case 4:
                0617     printf("%1i", inRepeatStack->indexr8) ;
                0618     break ;
                0619   case 5:
                0620     printf("%1i", inRepeatStack->indexc8) ;
                0621     break ;
                0622   case 6:
                0623     printf("%1i", inRepeatStack->indexc16) ;
                0624     break ;
                0625   case 7:
                0626     printf("%1i", inRepeatStack->indexs1) ;
                0627     break ;
                0628   case 8:
                0629     printf("%1i", inRepeatStack->indexbit) ;
                0630     break ;
                0631   case 9:
                0632     printf("%1i", inRepeatStack->indexptr) ;
                0633     break ;
                0634   }
                0635 }
                0636 
                0637 void showBufferRepeats(BufferRepeatCell *inRepeatStack, int type) {
                0638   printf("        REPEATS:") ;
                0639   if (inRepeatStack)
                0640     showBufferRepeatsRec(inRepeatStack, type) ;
                0641   else
                0642     printf(" none!") ;
                0643 }
                0644 
                0645 void showStackAndBuffers(char *locationName) {
                0646   int i ;
                0647   printf("%6s: ", locationName) ;
                0648   showStack() ;
                0649   printf("        I4:") ;
                0650   for (i=0 ; i<I4BUFSIZE ; ++i) {
                0651     if (i==adi4ibuf) printf(" | ") ;
                0652     printf(" %11i",adi4buf[i]) ;
                0653   }
                0654   showBufferRepeats(bufferRepeatTop, 1) ;
                0655   printf("\n") ;
                0656   printf("        I8:") ;
                0657   for (i=0 ; i<I8BUFSIZE ; ++i) {
                0658     if (i==adi8ibuf) printf(" | ") ;
                0659     printf(" %11i",adi8buf[i]) ;
                0660   }
                0661   showBufferRepeats(bufferRepeatTop, 2) ;
                0662   printf("\n") ;
                0663   printf("        R4:") ;
                0664   for (i=0 ; i<R4BUFSIZE ; ++i) {
                0665     if (i==adr4ibuf) printf(" | ") ;
                0666     printf(" %f",adr4buf[i]) ;
                0667   }
                0668   showBufferRepeats(bufferRepeatTop, 3) ;
                0669   printf("\n") ;
                0670   printf("        R8:") ;
                0671   for (i=0 ; i<R8BUFSIZE ; ++i) {
                0672     if (i==adr8ibuf) printf(" | ") ;
                0673     printf(" %f",adr8buf[i]) ;
                0674   }
                0675   showBufferRepeats(bufferRepeatTop, 4) ;
                0676   printf("\n") ;
                0677   printf("        C8:") ;
                0678   for (i=0 ; i<C8BUFSIZE ; ++i) {
                0679     if (i==adc8ibuf) printf(" | ") ;
                0680     printf(" %f",adc8buf[i]) ;
                0681   }
                0682   showBufferRepeats(bufferRepeatTop, 5) ;
                0683   printf("\n") ;
                0684   printf("        C16:") ;
                0685   for (i=0 ; i<C16BUFSIZE ; ++i) {
                0686     if (i==adc16ibuf) printf(" | ") ;
                0687     printf(" %f",adc16buf[i]) ;
                0688   }
                0689   showBufferRepeats(bufferRepeatTop, 6) ;
                0690   printf("\n") ;
                0691   printf("        STR:") ;
                0692   for (i=0 ; i<CHARBUFSIZE ; ++i) {
                0693     if (i==ads1ibuf) printf(" | ") ;
                0694     printf(" %c",ads1buf[i]) ;
                0695   }
                0696   showBufferRepeats(bufferRepeatTop, 7) ;
                0697   printf("\n") ;
                0698   printf("        BITS:%1i in %08x", adbitibuf, adbitbuf) ;
                0699   showBufferRepeats(bufferRepeatTop, 8) ;
                0700   printf("\n") ;
                0701   printf("        PTR:") ;
                0702   for (i=0 ; i<PTRBUFSIZE ; ++i) {
                0703     if (i==adptribuf) printf(" | ") ;
                0704     printf(" %x",adptrbuf[i]) ;
                0705   }
                0706   showBufferRepeats(bufferRepeatTop, 9) ;
                0707   printf("\n") ;
                0708 }
                0709 
                0710 void showStackAndBuffersSize(int pos) {
                0711   showStackSize(adi4ibuf,adi8ibuf,adr4ibuf,adr8ibuf,adc8ibuf,adc16ibuf,ads1ibuf,adbitibuf,adptribuf,pos) ;
                0712 }