update sv to implement over speculation in SV

--- src/optsimd.c
+++ src/optsimd.c
@@ -711,14 +711,21 @@
 }

 short InsertNewLocal(char *name, int type )
+/*
+ * add new local var in symbol table. We should always use this function
+ * to insert any var for compiler's internal purpose.
+ */
 {
-   short k;
+   short k, j;
 /*
  * NOTE: name string is copied and stored in Symbol Table
  * So, free the string from the caller function
+ * FIXED: SToff is a global pointer and it can be updated from AddDerefEntry()
+ * so, splited the statement.
  */
    k = STdef(name, type | LOCAL_BIT, 0);
-   SToff[k-1].sa[2] = AddDerefEntry(-REG_SP, k, -k, 0, k);
+   j =  AddDerefEntry(-REG_SP, k, -k, 0, k);
+   SToff[k-1].sa[2] = j;
    return k;
 }

@@ -2715,7 +2722,10 @@

 int SpeculativeVectorAnalysis()
 /*
- * Duplicated the optloop blks, do analysis with this.
+ * Duplicated the optloop blks, do analysis with this.
+ * NOTE: Assuming the number of branches inside loop is few. finding all loop
+ * paths is costly, but not worried with that now. possible to  implement
+ * incremental algorithm without explicitly figuring out all the paths
  */
 {
    int i, j, n, k, N;
@@ -2903,131 +2913,17 @@
    }
 }

-int SpeculativeVecTransform(LOOPQ *lp)
-/*
- * transform Vector in single path which is saved globaly as vect path. Must
- * call before scalar Restart. Scalar Restart will messed the optloop up.
- * assume analysis updated the optloop according to the vect path only
- *
- * NOTE: This vector transform should work for Redundant Vector operation also
- * as we have done if-conversion before this. We don't have normal FCMP and
- * branches after that. So, it can be done trivially.
- *
- *
- */
+void AddVectorInitReduction(LOOPQ *lp)
 {
-   short *sp;
-   BLIST *bl, *scope;
-   static enum inst
-      sfinsts[]= {FLD,  FST,  FMUL, FDIV,  FMAC, FADD,  FSUB,  FABS,  FMOV,
-                  FZERO, FNEG},
-      vfinsts[]= {VFLD, VFST, VFMUL, VFDIV, VFMAC, VFADD, VFSUB, VFABS, VFMOV,
-                  VFZERO, VFNEG},
-      sdinsts[]= {FLDD, FSTD, FMULD, FDIVD, FMACD, FADDD, FSUBD, FABSD, FMOVD,
-                  FZEROD, FNEGD},
-      vdinsts[]= {VDLD, VDST, VDMUL, VDDIV, VDMAC, VDADD, VDSUB, VDABS, VDMOV,
-                  VDZERO, VDNEG};
-/*****************************************************************************/
-/*
- * Generalization of Vector Compare for SSV.
- *
- * Case-1: (Any condition, fall through vector path )
- * -------------------------------------------------
- * if_condition -> true -> scalar_path
- * scalar: if (condition) GOTO SCALAR_PATH
- * vector: if (condition_any_vector_element) GOTO SCALAR_PATH
- * Comment: "if condition is true (to goto scalar path) for any of the vector
- * element, goto scalar_path."
- *
- * Implementation:
- *
- * V_CMP__W ... ... ...
- * V_SBTI $ireg, ...
- * CMP $ireg, $0,
- * JNE ...
- *
- * Case-2: (All Condition, fall through scalar path)
- * if_condition -> true -> vector_path
- * scalar: if (condition) GOTO VECTOR_PATH
- * vector: if (condition_all_vector_element) GOTO VECTOR_PATH
- * comment: "jump to vector path only if all the elements follow the condition."
- *
- * Implementation:
- *
- * V_CMP__W ... ... ...
- * V_SBTI $ireg, ...
- * CMP $ireg, $0x0F  # for avx and double
- * JEQ ...
- *
- * NOTE: only case-1 is implemented right now.
- */
-/*****************************************************************************/
-#if 0
-static enum inst
-      brinsts[] = {JEQ, JNE, JLT, JLE, JGT, JGE},
-      #if defined(AVX)
-         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWGT,
-                         VFCMPWGE},
-         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWGT,
-                         VDCMPWGE};
-      #else
-/*
- *    SSE supports : EQ, NE, LT, LE, NLT, NLE
- *    not supports : GT, GE, NGT, NGE
- *    So, we need to replace GT and GE with NLE and NLT
- */
-         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWNLE,
-                         VFCMPWNLT},
-         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWNLE,
-                         VDCMPWNLT};
-      #endif
-#endif
-/*
- * NOTE: We have 6 conditional branches. So, we only need to keep 6 VCMPWXX inst
- * for SSE, GT and GE are replaced with the NLE and NLT inside the l2a while
- * converting lil to assembly
- */
-   static enum inst
-      brinsts[] = {JEQ, JNE, JLT, JLE, JGT, JGE},
-         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWGT,
-                         VFCMPWGE},
-         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWGT,
-                         VDCMPWGE};
-   const int nbr = 6;
-
-   const int nvinst = 11;
-   enum inst sld, vld, sst, vst, smul, vmul, sdiv, vdiv, smac, vmac, sadd, vadd,
-             ssub, vsub, sabs, vabs, smov, vmov, szero, vzero, inst, binst,
-             mskinst;
-   short r0, r1, op, ir, vrd;
-   enum inst *sinst, *vinst, *vcmpinst;
-   int i, j, n, k, m, mskval, nfr=0;
-   char ln[512];
-   struct ptrinfo *pi0, *pi;
-   INSTQ *ip, *ippu, *iph, *iptp, *iptn;
-   short vlen;
-   enum inst vsld, vsst, vshuf;
-   short sregs[TNFR], vregs[TNFR];
-
-/*
- * Need at least one path to vectorize
- */
-   assert(VPATH!=-1);
-   scope = PATHS[VPATH]->blocks;
-
+   int i, j, k, n;
+   INSTQ *iph, *iptp, *iptn;
+   short r0, r1;
+   enum inst vld, vsld, vst, vsst, vshuf;
 /*
  * Figure out what type of insts to translate
  */
    if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
    {
-      sinst = sfinsts;
-      vinst = vfinsts;
-      vcmpinst = vfcmpinsts;
-      #if defined(X86) && defined(AVX)
-         vlen = 8;
-      #else
-         vlen = 4;
-      #endif
       vsld = VFLDS;
       vsst = VFSTS;
       vshuf = VFSHUF;
@@ -3039,40 +2935,12 @@
       vsld = VDLDS;
       vsst = VDSTS;
       vshuf = VDSHUF;
-      sinst = sdinsts;
-      vinst = vdinsts;
-      vcmpinst = vdcmpinsts;
       vld = VDLD;
-      #if defined(X86) && defined(AVX)
-         vlen = 4;
-      #else
-         vlen = 2;
-      #endif
       vst = VDST;
    }
+
    r0 = GetReg(FLAG2TYPE(lp->vflag));
    r1 = GetReg(FLAG2TYPE(lp->vflag));
-
-/*
- * If Loop control is already not killed, kill all controls in optloop
- * We will put back the appropriate loop control at the end of the function.
- */
-   KillLoopControl(lp);
-#if 0
-/*
- * Generate scalar cleanup loop before simdifying loop
- */
-   GenCleanupLoop(lp);
-#endif
-
-/*
- * Find all pointer updates, and remove them from vector path (leaving only
- * vectorized instructions for analysis); will put them back in loop after
- * vectorization is done.
- */
-
-   pi0 = FindMovingPointers(scope);
-   ippu = KillPointerUpdates(pi0, vlen);
 /*
  * Find inst in preheader to insert scalar init before; want it inserted last
  * unless last instruction is a jump, in which case put it before the jump.
@@ -3211,12 +3079,123 @@
    GetReg(-1);
    iptp = InsNewInst(lp->posttails->blk, iptp, NULL, CMPFLAG, CF_VRED_END,
                      0, 0);
+}
+
+void AddVectorBackup(LOOPQ *lp)
+{
+   int i, j, N;
+   BBLOCK *bp;
+   INSTQ *ip;
+   short vreg;
+   enum inst vld, vst;
+
+/*
+ * no var to backup, return.
+ * NOTE: Scalar Restart is called before the VecXform. So, bvvscal is already
+ * populated, if any
+ */
+   if (!lp->bvvscal) return;
+
+   if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
+   {
+      vld = VFLD;
+      vst = VFST;
+   }
+   else
+   {
+      vld = VDLD;
+      vst = VDST;
+   }
+
+   bp = lp->header;
+   assert(bp->ainst1->inst[0] == LABEL); /* 1st inst should be LABEL*/
+   ip = bp->ainst1;
+   ip = InsNewInst(bp, ip, NULL, CMPFLAG, CF_SSV_VBACKUP, 0, 0);
+   for (N=lp->bvvscal[0], i=1; i <= N; i++)
+   {
+      if (lp->bvvscal[i])
+      {
+         vreg = GetReg(FLAG2TYPE(lp->vflag));
+         ip = PrintComment(bp, ip, NULL, "Backing up vector %s to %s",
+                           STname[lp->vvscal[i]-1], STname[lp->bvvscal[i]-1]);
+         ip = InsNewInst(bp, ip, NULL, vld, -vreg,
+                           SToff[lp->vvscal[i]-1].sa[2], 0);
+         ip = InsNewInst(bp, ip, NULL, vst, SToff[lp->bvvscal[i]-1].sa[2],
+                           -vreg, 0);
+      }
+   }
+
+   ip = InsNewInst(bp, ip, NULL, CMPFLAG, CF_SSV_VBACKUP_END, 0, 0);
+
+}
+void SpecVecPathXform(BLIST *scope, LOOPQ *lp)
+{
+   int i, j, n, k, m, mskval, nfr;
+   INSTQ *ip;
+   BLIST *bl;
+   static enum inst
+      sfinsts[]= {FLD,  FST,  FMUL, FDIV,  FMAC, FADD,  FSUB,  FABS,  FMOV,
+                  FZERO, FNEG},
+      vfinsts[]= {VFLD, VFST, VFMUL, VFDIV, VFMAC, VFADD, VFSUB, VFABS, VFMOV,
+                  VFZERO, VFNEG},
+      sdinsts[]= {FLDD, FSTD, FMULD, FDIVD, FMACD, FADDD, FSUBD, FABSD, FMOVD,
+                  FZEROD, FNEGD},
+      vdinsts[]= {VDLD, VDST, VDMUL, VDDIV, VDMAC, VDADD, VDSUB, VDABS, VDMOV,
+                  VDZERO, VDNEG};
+/*
+ * NOTE: We have 6 conditional branches. So, we only need to keep 6 VCMPWXX inst
+ * for SSE, GT and GE are replaced with the NLE and NLT inside the l2a while
+ * converting lil to assembly
+ */
+   static enum inst
+      brinsts[] = {JEQ, JNE, JLT, JLE, JGT, JGE},
+         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWGT,
+                         VFCMPWGE},
+         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWGT,
+                         VDCMPWGE};
+   enum inst inst, binst, mskinst;
+   short sregs[TNFR], vregs[TNFR];
+   short op, ir, vrd;
+   enum inst *sinst, *vinst, *vcmpinst;
+   const int nbr = 6;
+   const int nvinst = 11;
+
+   nfr = 0;
+/*
+ * Figure out what type of insts to translate
+ */
+   if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
+   {
+      sinst = sfinsts;
+      vinst = vfinsts;
+      vcmpinst = vfcmpinsts;
+   }
+   else
+   {
+      sinst = sdinsts;
+      vinst = vdinsts;
+      vcmpinst = vdcmpinsts;
+   }
 /*
  * Translate body of loop
  */
    for (bl=scope; bl; bl = bl->next)
    {
-      for (ip=bl->blk->ainst1; ip; ip = ip->next)
+/*
+ *    skip the code of vector backup, if exists
+ */
+      if (bl->blk == lp->header)
+      {
+         ip = FindCompilerFlag(bl->blk, CF_SSV_VBACKUP_END);
+         if (ip)
+            ip = ip->next;
+         else ip = bl->blk->ainst1;
+      }
+      else ip = bl->blk->ainst1;
+/*
+ *    transform the rest of the code
+ */
+      for ( ; ip; ip = ip->next)
       {
          inst = GET_INST(ip->inst[0]);
          if (ACTIVE_INST(inst))
@@ -3330,56 +3309,17 @@
 /*
  *             it's time to add other instruction like mask and test
  *             ireg is set, so, get a new ireg
+ *             NOTE: in vector path, no integer is used. So, we can safely
+ *             use a int reg.
  */
                ir = GetReg(T_INT);
                ip = InsNewInst(bl->blk, ip, NULL, mskinst, -ir, -vrd, 0);
-/*
- *             add test the iregs with const val populated by vec len
- */
-/*============================================================================
- *             Under Construction !!!!!
- *             Just for tesing ... .... ....
- *============================================================================*/
-#if 0
-/*
- *             NOTE: consider the 'path =1' is case for vector fall thru.
- *             Later, we will need a tester to test it !!!!
- */
-               extern int path;
-
-               if (path==1 && VPATH==0)
-               {
-/*
- *                vector path is the fall thru
- */
-                  mskval = 0;
-                  ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
-                                  STiconstlookup(mskval)) ;
-/*                ip = InsNewInst(bl->blk, ip, NULL, CMPAND, -ir, -ir,
-                                  STiconstLoopup(mskval)) ; */
-                  ip->next->inst[0] = JNE;
-               }
-               else
-               {
-/*
- *                if the scalar is the fall thru
- */
-                  fprintf(stderr, "SCALAR FALL-TRU SELECTED!\n\n");
-
-                  mskval = 1;
-                  for (i = 1; i < vlen; i++)
-                     mskval = (mskval << 1) | 1;
-                  ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
-                                  STiconstlookup(mskval)) ;
-                  ip->next->inst[0] = JEQ;
-               }
-
-#else          /* consider vcmp_any case.. only fall through vector path */
 /*
  *             NOTE:
  *             By default, we always vectorize the fall-thru case, our
  *             intension is to get the maxium perf. So, making the scalar
- *             path as fall-thru is meaningless!!
+ *             path as fall-thru is meaningless!! Still, you can see the
+ *             code in the old implementation.
  */
                mskval = 0;
                ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
@@ -3387,13 +3327,10 @@
 /*             ip = InsNewInst(bl->blk, ip, NULL, CMPAND, -ir, -ir,
                                STiconstLoopup(mskval)) ; */
                ip->next->inst[0] = JNE;
-#endif
 /*
  *             Majedul: NOTE: here ends a block. Shouldn't we re-initialize
  *             the reg with GetReg(-1). !!!!!
- *             FIXME:
- */
-/*=========================================================================*/
+ */
             }
             else /* changing other scalar inst to vector inst */
             {
@@ -3457,6 +3394,925 @@
       }
    }
    GetReg(-1);
+}
+
+INSTQ *DupVecPathInst(BLIST *scope, BBLOCK *bp0, LOOPQ *lp)
+{
+   BLIST *bl;
+   INSTQ *ip, *ipN, *ip0;
+
+/*
+ * NOTE: can be set with a CMPFLAG
+ */
+   ip0 = ipN = PrintComment(bp0, NULL, NULL, "Duplicable Instructions begin!!!");
+
+   for (bl=scope; bl; bl=bl->next)
+   {
+/*
+ *    skip the code of vector backup, if exists
+ */
+      if (bl->blk == lp->header)
+      {
+         ip = FindCompilerFlag(bl->blk, CF_SSV_VBACKUP_END);
+         if (ip)
+            ip = ip->next;
+         else ip = bl->blk->ainst1;
+      }
+      else ip = bl->blk->ainst1;
+
+      for ( ; ip; ip=ip->next)
+      {
+/*
+ *       skip all LABEL and FLAG
+ */
+         if (ip->inst[0] == LABEL || ip->inst[0] == CMPFLAG) continue;
+/*
+ *       Copy the remaining instruction.
+ */
+         ip0 = InsNewInst(bp0, ip0, NULL, ip->inst[0], ip->inst[1], ip->inst[2],
+                          ip->inst[3]);
+      }
+   }
+   return ipN;
+}
+
+BLIST *UnrollLargerBet(BBLOCK *bp0, LOOPQ *lp, struct ptrinfo *pi,  int unroll)
+{
+   int i, j;
+   short imask;
+   short r0, r1;
+   INSTQ *ip, *ip1, *ipCB, *ipnext;
+   BBLOCK *bp;
+   BLIST *bl, *dupblks;
+
+   dupblks = NULL;
+/*
+ * NOTE:
+ * Assumption: only one conditional branch to handle, no more than 2 paths.
+ * Note about the duplication:
+ * 1. vector path can be xformed as a single basic block after unrolling.
+ * 2. As it will be a single block, all labels can be deleted.
+ * 3. like the normal unrolling, ptr lds need to be updated
+ * 4. unlike the normal unrolling, no need to consider index var update;
+ *    vector path ensure that there would be no integer vars used/set here.
+ * 5. issue:
+ *    need extra int reg to preserve the mask val:
+ *    - can be kept an int reg live on through the whole unrolled blk
+ *    - can be used an int ver to store the mask val and use ld/st format.
+ *    NOTE: choose 2nd option now.
+ */
+   assert(NPATH==2); /* morethan 2 paths are not consider right now */
+
+   if (unroll < 2) return(NULL); /* no need to duplicate */
+   if (!bp0) return(NULL);       /* nothing to duplicate */
+/*
+ *    update the integer mask and remove the conditional branch.
+ */
+   imask = InsertNewLocal("_imask", T_INT);
+
+   for (i=1; i < unroll; i++)
+   {
+      bp = NewBasicBlock(NULL, NULL);
+      bl = NULL;
+      bl = AddBlockToList(bl, bp);
+      ip1 = PrintComment(bp, NULL, NULL, "Dup-%d begins!!!", i);
+/*
+ *    copy all instructions
+ */
+      for (ip=bp0->inst1; ip; ip=ip->next)
+      {
+         ip1 = InsNewInst(bp, ip1, NULL, ip->inst[0], ip->inst[1], ip->inst[2],
+                          ip->inst[3]);
+/*
+ *       save branch inst to use later
+ */
+         if (IS_COND_BRANCH(ip->inst[0]))
+            ipCB = ip;
+      }
+/*
+ *    update the ptr lds. Assumption: ptr updated already being killed at SV
+ *    HERE HERE ptr is already deleted from this path!!! how can we figure out
+ *    the moving ptr now!!! Must be passed from outside!!!
+ */
+      if (pi)
+         UpdatePointerLoads(bl, pi, i*Type2Vlen(FLAG2TYPE(lp->vflag)));
+/*
+ *    chnage the mask inst and deleted the branch
+ */
+      for (ip=bp->ainst1; ip; ip=ip->next)
+      {
+         if (IS_CMPW(ip->inst[0]) &&
+             (ip->next->inst[0]==VFSBTI || ip->next->inst[0] == VDSBTI))
+         {
+            r0 = GetReg(T_INT);
+            r1 = GetReg(T_INT);
+            InsNewInst(bp, NULL, ip, LD, -r0, SToff[imask-1].sa[2], 0);
+            ip = ip->next; /* mask inst */
+/*
+ *          update the mask inst with new int reg and insert a store in imask
+ */
+            ip->inst[1] = -r1;
+            ip = InsNewInst(bp, ip, NULL, OR, -r0, -r0, -r1);
+            ip = InsNewInst(bp, ip, NULL, ST, SToff[imask-1].sa[2],-r0, 0);
+            ip = ip->next;
+            assert(IS_CMP(ip->inst[0]) && IS_COND_BRANCH(ip->next->inst[0]));
+            ipnext = ip->next;  /* save the next inst*/
+            DelInst(ip);
+            DelInst(ip->next);
+            GetReg(-1);
+         }
+      }
+/*
+ *    Insert branch at the end of the for last duplication
+ */
+      if (i == (unroll-1) )
+      {
+         r0 = GetReg(T_INT);
+         ip = bp->ainstN;
+         ip = InsNewInst(bp, ip, NULL, LD, -r0, SToff[imask-1].sa[2], 0);
+         ip = InsNewInst(bp, ip, NULL, CMP, -ICC0, -r0, STiconstlookup(0));
+         ip = InsNewInst(bp, ip, NULL, ipCB->inst[0], ipCB->inst[1],
+                         ipCB->inst[2], ipCB->inst[3]);
+         GetReg(-1);
+      }
+#if 0
+      fprintf(stderr, "Dup #%d: \n", i);
+      fprintf(stderr, "================\n");
+      PrintThisBlockInst(stderr, bp);
+#endif
+/*
+ *    add blks in list
+ */
+      dupblks = AddBlockToList(dupblks, bp);
+      //KillBlockList(bl);
+      //KillAllInst(bp);
+      //KillAllBasicBlocks(bp);
+   }
+/*
+ * update the main loop blk
+ */
+   for (ip=bp0->ainst1; ip; ip=ip->next)
+   {
+      if (IS_CMPW(ip->inst[0]) &&
+         (ip->next->inst[0]==VFSBTI || ip->next->inst[0] == VDSBTI))
+      {
+         r0 = GetReg(T_INT);
+         ip = ip->next; /* mask inst */
+/*
+ *       update the mask inst with new int reg and insert a store in imask
+ */
+         ip->inst[1] = -r0;
+         ip = InsNewInst(bp, ip, NULL, ST, SToff[imask-1].sa[2], -r0, 0);
+         ip = ip->next;
+         assert(IS_CMP(ip->inst[0]) && IS_COND_BRANCH(ip->next->inst[0]));
+         ipnext = ip->next;  /* save the next inst*/
+         DelInst(ip);
+         DelInst(ip->next);
+         GetReg(-1);
+      }
+   }
+/*
+ * reverse the list to maintain the sequence, add the original blk
+ */
+   dupblks = ReverseBlockList(dupblks);
+   dupblks = AddBlockToList(dupblks, bp0);
+#if 0
+   for (bl=dupblks; bl; bl=bl->next)
+   {
+      PrintThisBlockInst(stderr, bl->blk);
+   }
+#endif
+
+   return(dupblks);
+}
+
+void InsUnrolledCodeToVpath(LOOPQ *lp, BLIST *scope, BLIST *dupblks)
+{
+   BLIST *bl;
+   BBLOCK *bp;
+   INSTQ *ip, *ip0, *ipn;
+
+   if (!dupblks) return;
+/*
+ * delete all inst after backup to tails (upto the label before CF_LOOP_TEST)
+ * Assumption: always jumpback from scalar_resatrt to label before CF_LOOP_TEST
+ * which follows the current implementation.
+ */
+   for (bl=scope; bl; bl=bl->next)
+   {
+/*
+ *    skip the code of vector backup, if exists
+ */
+      if (bl->blk == lp->header)
+      {
+         ip = FindCompilerFlag(bl->blk, CF_SSV_VBACKUP_END);
+         if (ip)
+            ip = ip->next;
+         else
+         {
+            assert(bl->blk->ainst1->inst[0] == LABEL); /* atleast has a label*/
+            ip = bl->blk->ainst1->next;
+         }
+      }
+      else ip = bl->blk->inst1;
+/*
+ *    If it is tail blk, delete inst upto the LABEL inserted by Scalar Restart
+ */
+      if (FindBlockInList(lp->tails, bl->blk))
+      {
+         for ( ; ip; ip=ipn)
+         {
+/*
+ *          HERE HERE, need to identify the LABEL which is inserted by the
+ *          Scalar Resart.
+ *          NOTE: kept all labels. So, now just need to check whether The
+ *          CMPFLAG is one them which are used to update loopcontrol
+ */
+            if (ip->inst[0] == CMPFLAG &&
+                (ip->inst[1] == CF_LOOP_PTRUPDATE
+                 || ip->inst[1] == CF_LOOP_UPDATE))
+               break;
+            else
+            {
+               if (ip->inst[0] == LABEL || ip->inst[0] == CMPFLAG)
+                  ipn = ip->next;
+               else
+                  ipn = DelInst(ip);
+            }
+         }
+      }
+/*
+ *    for other blks, delete all instructions
+ */
+      else
+      {
+         while (ip)
+            ip = DelInst(ip);
+      }
+   }
+
+/*
+ * Now, add instructions from duplicated blks at the header of lp
+ */
+   bp = lp->header;
+   ip0 = FindCompilerFlag(bp, CF_SSV_VBACKUP_END);
+   if (!ip0)
+   {
+      ip0=bp->ainst1;
+      assert(ip0->inst[0] == LABEL);
+   }
+   for (bl=dupblks; bl; bl=bl->next)
+   {
+      for (ip=bl->blk->inst1; ip; ip=ip->next)
+      {
+         ip0 = InsNewInst(bp, ip0, NULL, ip->inst[0], ip->inst[1], ip->inst[2],
+                          ip->inst[3]);
+      }
+   }
+/*
+ * delete all temporary blks and inst
+ */
+   for (bl=dupblks; bl; bl=bl->next)
+      KillAllBasicBlocks(bl->blk);
+   KillBlockList(bl);
+
+#if 0
+   fprintf(stdout, "Final SV with Unroll\n");
+   PrintInst(stdout, bbbase);
+   exit(0);
+#endif
+}
+
+
+int SpecVecXform(LOOPQ *lp, int unroll)
+/*
+ * supports larger bet for unrolling of speculative vectorization
+ */
+{
+   BBLOCK *bp;
+   BLIST *scope, *dupblks;
+   INSTQ *ippu, *ip0, *ip;
+   struct ptrinfo *pi0, *pi;
+   short vlen, URbase;
+
+/*
+ * Need at least one path to vectorize
+ */
+   assert(VPATH!=-1);
+   scope = PATHS[VPATH]->blocks;
+
+   vlen = Type2Vlen(lp->vflag);
+   URbase = unroll? vlen*unroll: unroll;
+
+/*
+ * If Loop control is already not killed, kill all controls in optloop
+ * We will put back the appropriate loop control at the end of the function.
+ */
+   KillLoopControl(lp);
+
+/*
+ * Find all pointer updates, and remove them from vector path (leaving only
+ * vectorized instructions for analysis); will put them back in loop after
+ * vectorization is done.
+ */
+   pi0 = FindMovingPointers(scope);
+   ippu = KillPointerUpdates(pi0, URbase);
+/*
+ * It's time to generate the vector initialization and vector reduction
+ */
+   AddVectorInitReduction(lp);
+/*
+ * add vector backup there based on lp->bvvscal. Recovery code is inserted in
+ * Scalar Restart.
+ */
+   AddVectorBackup(lp);
+/*
+ * Transform the vector path
+ */
+   SpecVecPathXform(scope, lp);
+/*
+ * Now, we need to duplicate the vector path
+ * ***********************************************************
+ */
+   bp = NewBasicBlock(NULL, NULL);
+   ip0 = DupVecPathInst(scope, bp, lp);
+   dupblks = UnrollLargerBet(bp, lp, pi0,  unroll);
+
+   KillAllPtrinfo(pi0); /* pi0 is needed in unroll. So, kill after that */
+
+#if 0
+   PrintThisInstQ(stderr, ip0);
+   PrintThisBlockInst(stderr, bp);
+#endif
+/*
+ * Put back loop control and pointer updates
+ */
+   OptimizeLoopControl(lp, URbase, 0, ippu);
+/*
+ * Now, we can update with the duplicated blks, deleting the previous insts
+ */
+   if (dupblks)
+      InsUnrolledCodeToVpath(lp, scope, dupblks);
+
+   CFU2D = CFDOMU2D = CFUSETU2D = INUSETU2D = INDEADU2D = CFLOOP = 0;
+
+   return(0);
+}
+
+int SpeculativeVecTransform(LOOPQ *lp)
+/*
+ * transform Vector in single path which is saved globaly as vect path. Must
+ * call before scalar Restart. Scalar Restart will messed the optloop up.
+ * assume analysis updated the optloop according to the vect path only
+ *
+ * NOTE: This vector transform should work for Redundant Vector operation also
+ * as we have done if-conversion before this. We don't have normal FCMP and
+ * branches after that. So, it can be done trivially.
+ *
+ *
+ */
+{
+   short *sp;
+   BLIST *bl, *scope;
+   static enum inst
+      sfinsts[]= {FLD,  FST,  FMUL, FDIV,  FMAC, FADD,  FSUB,  FABS,  FMOV,
+                  FZERO, FNEG},
+      vfinsts[]= {VFLD, VFST, VFMUL, VFDIV, VFMAC, VFADD, VFSUB, VFABS, VFMOV,
+                  VFZERO, VFNEG},
+      sdinsts[]= {FLDD, FSTD, FMULD, FDIVD, FMACD, FADDD, FSUBD, FABSD, FMOVD,
+                  FZEROD, FNEGD},
+      vdinsts[]= {VDLD, VDST, VDMUL, VDDIV, VDMAC, VDADD, VDSUB, VDABS, VDMOV,
+                  VDZERO, VDNEG};
+/*****************************************************************************/
+/*
+ * Generalization of Vector Compare for SSV.
+ *
+ * Case-1: (Any condition, fall through vector path )
+ * -------------------------------------------------
+ * if_condition -> true -> scalar_path
+ * scalar: if (condition) GOTO SCALAR_PATH
+ * vector: if (condition_any_vector_element) GOTO SCALAR_PATH
+ * Comment: "if condition is true (to goto scalar path) for any of the vector
+ * element, goto scalar_path."
+ *
+ * Implementation:
+ *
+ * V_CMP__W ... ... ...
+ * V_SBTI $ireg, ...
+ * CMP $ireg, $0,
+ * JNE ...
+ *
+ * Case-2: (All Condition, fall through scalar path)
+ * if_condition -> true -> vector_path
+ * scalar: if (condition) GOTO VECTOR_PATH
+ * vector: if (condition_all_vector_element) GOTO VECTOR_PATH
+ * comment: "jump to vector path only if all the elements follow the condition."
+ *
+ * Implementation:
+ *
+ * V_CMP__W ... ... ...
+ * V_SBTI $ireg, ...
+ * CMP $ireg, $0x0F  # for avx and double
+ * JEQ ...
+ *
+ * NOTE: only case-1 is implemented right now.
+ */
+/*****************************************************************************/
+#if 0
+static enum inst
+      brinsts[] = {JEQ, JNE, JLT, JLE, JGT, JGE},
+      #if defined(AVX)
+         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWGT,
+                         VFCMPWGE},
+         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWGT,
+                         VDCMPWGE};
+      #else
+/*
+ *    SSE supports : EQ, NE, LT, LE, NLT, NLE
+ *    not supports : GT, GE, NGT, NGE
+ *    So, we need to replace GT and GE with NLE and NLT
+ */
+         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWNLE,
+                         VFCMPWNLT},
+         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWNLE,
+                         VDCMPWNLT};
+      #endif
+#endif
+/*
+ * NOTE: We have 6 conditional branches. So, we only need to keep 6 VCMPWXX inst
+ * for SSE, GT and GE are replaced with the NLE and NLT inside the l2a while
+ * converting lil to assembly
+ */
+   static enum inst
+      brinsts[] = {JEQ, JNE, JLT, JLE, JGT, JGE},
+         vfcmpinsts[] = {VFCMPWEQ, VFCMPWNE, VFCMPWLT, VFCMPWLE, VFCMPWGT,
+                         VFCMPWGE},
+         vdcmpinsts[] = {VDCMPWEQ, VDCMPWNE, VDCMPWLT, VDCMPWLE, VDCMPWGT,
+                         VDCMPWGE};
+   const int nbr = 6;
+
+   const int nvinst = 11;
+   enum inst sld, vld, sst, vst, smul, vmul, sdiv, vdiv, smac, vmac, sadd, vadd,
+             ssub, vsub, sabs, vabs, smov, vmov, szero, vzero, inst, binst,
+             mskinst;
+   short r0, r1, op, ir, vrd;
+   enum inst *sinst, *vinst, *vcmpinst;
+   int i, j, n, k, m, mskval, nfr=0;
+   char ln[512];
+   struct ptrinfo *pi0, *pi;
+   INSTQ *ip, *ippu, *iph, *iptp, *iptn;
+   short vlen;
+   enum inst vsld, vsst, vshuf;
+   short sregs[TNFR], vregs[TNFR];
+
+/*
+ * Need at least one path to vectorize
+ */
+   assert(VPATH!=-1);
+   scope = PATHS[VPATH]->blocks;
+
+/*
+ * Figure out what type of insts to translate
+ */
+   if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
+   {
+      sinst = sfinsts;
+      vinst = vfinsts;
+      vcmpinst = vfcmpinsts;
+      #if defined(X86) && defined(AVX)
+         vlen = 8;
+      #else
+         vlen = 4;
+      #endif
+      vsld = VFLDS;
+      vsst = VFSTS;
+      vshuf = VFSHUF;
+      vld = VFLD;
+      vst = VFST;
+   }
+   else
+   {
+      vsld = VDLDS;
+      vsst = VDSTS;
+      vshuf = VDSHUF;
+      sinst = sdinsts;
+      vinst = vdinsts;
+      vcmpinst = vdcmpinsts;
+      vld = VDLD;
+      #if defined(X86) && defined(AVX)
+         vlen = 4;
+      #else
+         vlen = 2;
+      #endif
+      vst = VDST;
+   }
+   r0 = GetReg(FLAG2TYPE(lp->vflag));
+   r1 = GetReg(FLAG2TYPE(lp->vflag));
+
+/*
+ * If Loop control is already not killed, kill all controls in optloop
+ * We will put back the appropriate loop control at the end of the function.
+ */
+   KillLoopControl(lp);
+#if 0
+/*
+ * Generate scalar cleanup loop before simdifying loop
+ */
+   GenCleanupLoop(lp);
+#endif
+
+/*
+ * Find all pointer updates, and remove them from vector path (leaving only
+ * vectorized instructions for analysis); will put them back in loop after
+ * vectorization is done.
+ */
+
+   pi0 = FindMovingPointers(scope); /* mem leak, need to kill */
+   ippu = KillPointerUpdates(pi0, vlen);
+/*
+ * Find inst in preheader to insert scalar init before; want it inserted last
+ * unless last instruction is a jump, in which case put it before the jump.
+ * As long as loads don't reset condition codes, this should be safe
+ * (otherwise, need to move before compare as well as jump)
+ */
+   iph = lp->preheader->ainstN;
+   if (iph && IS_BRANCH(iph->inst[0]))
+      iph = iph->prev;
+   else
+      iph = NULL;
+/*
+ * Find inst in posttail to insert reductions before; if 1st active inst
+ * is not a label, insert at beginning of block, else insert after label
+ */
+   if (lp->posttails->blk->ilab)
+   {
+      iptp = lp->posttails->blk->ainst1;
+      iptn = NULL;
+   }
+   else
+   {
+      iptp = NULL;
+      iptn = lp->posttails->blk->ainst1;
+      if (!iptn)
+         iptn = lp->posttails->blk->inst1;
+   }
+
+/*
+ * Insert scalar-to-vector initialization in preheader for vars live on entry
+ * and vector-to-scalar reduction in post-tail for vars live on exit
+ */
+   j = 0;
+   k = STiconstlookup(0);
+   for (n=lp->vscal[0],i=0; i < n; i++)
+   {
+      if (VS_LIVEIN & lp->vsflag[i+1])
+      {
+/*
+ *       ADD-updated vars set v[0] = scalar, v[1:N] = 0
+ */
+         if (VS_ACC & lp->vsflag[i+1])
+            PrintComment(lp->preheader, NULL, iph,
+               "Init accumulator vector for %s", STname[lp->vscal[i+1]-1]);
+         else
+            PrintComment(lp->preheader, NULL, iph,
+               "Init vector equiv of %s", STname[lp->vscal[i+1]-1]);
+         InsNewInst(lp->preheader, NULL, iph, vsld, -r0,
+                    SToff[lp->vscal[i+1]-1].sa[2], 0);
+         if (!(VS_ACC & lp->vsflag[i+1]))
+            InsNewInst(lp->preheader, NULL, iph, vshuf, -r0, -r0, k);
+         InsNewInst(lp->preheader, NULL, iph, vst,
+                    SToff[lp->vvscal[i+1]-1].sa[2], -r0, 0);
+      }
+/*
+ *    Output vars are known to be updated only by ADD
+ *    Majedul: output var doesn't have to be accumulator. We will
+ *    Handle var after checking the VS_ACC flag
+ *
+ */
+      if (VS_LIVEOUT & lp->vsflag[i+1])
+      {
+         j++;
+         /*assert((lp->vsoflag[i+1] & (VS_MUL | VS_EQ | VS_ABS)) == 0);*/
+         if (lp->vsoflag[i+1] & VS_ACC)
+         {
+
+            iptp = PrintComment(lp->posttails->blk, iptp, iptn,
+                  "Reduce accumulator vector for %s", STname[lp->vscal[i+1]-1]);
+            iptp = InsNewInst(lp->posttails->blk, iptp, NULL, vld, -r0,
+                              SToff[lp->vvscal[i+1]-1].sa[2], 0);
+            if (vld == VDLD)
+            {
+            #if defined(X86) && defined(AVX)
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VDSHUF, -r1,
+                                 -r0, STiconstlookup(0x3276));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VDADD,-r0,-r0,
+                                 -r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VDSHUF, -r1,
+                                 -r0, STiconstlookup(0x3715));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VDADD,-r0,-r0,
+                                 -r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VDSTS,
+                                 SToff[lp->vscal[i+1]-1].sa[2], -r0, 0);
+            #else
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VDSHUF, -r1,
+                                 -r0, STiconstlookup(0x33));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VDADD,-r0,-r0,
+                                 -r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VDSTS,
+                                 SToff[lp->vscal[i+1]-1].sa[2], -r0, 0);
+            #endif
+            }
+            else
+            {
+            #if defined(X86) && defined(AVX)
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSHUF,
+                                 -r1, -r0, STiconstlookup(0x7654FEDC));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VFADD,
+                                 -r0,-r0,-r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSHUF,
+                                 -r1, -r0, STiconstlookup(0x765432BA));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VFADD,
+                                 -r0,-r0,-r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSHUF,
+                                 -r1, -r0, STiconstlookup(0x76CD3289));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VFADD,
+                                 -r0,-r0,-r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSTS,
+                                 SToff[lp->vscal[i+1]-1].sa[2], -r0, 0);
+            #else
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSHUF,
+                                 -r1, -r0, STiconstlookup(0x3276));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VFADD,
+                                 -r0,-r0,-r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSHUF,
+                                 -r1, -r0, STiconstlookup(0x5555));
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL,VFADD,
+                                 -r0,-r0,-r1);
+               iptp = InsNewInst(lp->posttails->blk, iptp, NULL, VFSTS,
+                                 SToff[lp->vscal[i+1]-1].sa[2], -r0, 0);
+            #endif
+            }
+         }
+         else /* VS_MUL/ VS_DIV*/
+         {
+            iptp = PrintComment(lp->posttails->blk, iptp, iptn,
+                  "Reduce vector for %s", STname[lp->vscal[i+1]-1]);
+            iptp = InsNewInst(lp->posttails->blk, iptp, NULL, vld, -r0,
+                              SToff[lp->vvscal[i+1]-1].sa[2], 0);
+            iptp = InsNewInst(lp->posttails->blk, iptp, NULL, vsst,
+                              SToff[lp->vscal[i+1]-1].sa[2], -r0, 0);
+         }
+      }
+   }
+   GetReg(-1);
+   iptp = InsNewInst(lp->posttails->blk, iptp, NULL, CMPFLAG, CF_VRED_END,
+                     0, 0);
+/*
+ * Translate body of loop
+ */
+   for (bl=scope; bl; bl = bl->next)
+   {
+      for (ip=bl->blk->ainst1; ip; ip = ip->next)
+      {
+         inst = GET_INST(ip->inst[0]);
+         if (ACTIVE_INST(inst))
+         {
+/*
+ *          check for FCMP/FCMPD instruction so that we can replace it
+ *          with vector cmp.
+ */
+            if (inst == FCMP || inst == FCMPD)
+            {
+/*
+ *             Select appropriate vector cmp inst
+ */
+               if (inst == FCMP)
+               {
+                  vcmpinst = vfcmpinsts;
+                  mskinst = VFSBTI;
+               }
+               else
+               {
+                  vcmpinst = vdcmpinsts;
+                  mskinst = VDSBTI;
+               }
+/*
+ *             check for the next inst. Right now assume the next instruction
+ *             would always be one of the conditional branch
+ */
+               binst = ip->next->inst[0]; /* assume next ainst alwasy branch*/
+/*
+ *             find index of appropriate branch and VCMP
+ */
+               for (m = 0; m < nbr; m++)
+               {
+                  if (brinsts[m] == binst)
+                     break;
+               }
+               assert(m!=nbr); /* there must be a branch */
+/*
+ *             insert new instructions replacing old FCMP and BR insts.
+ *             NOTE: Those two old instructions use two fregs/dregs (fcc, icc
+ *             and pc), but new insts would use 3 vfregs/vdregs and 1 iregs (icc
+ *             and pc) where 1 vfreg/vdreg and ireg would be overwritten.
+ *
+ *             NOTE: We reserve  new ireg and vreg here, these regs are only
+ *             used as destination. So, we can reuse later. Need to free those.
+ *             I avoid that here right now. We consider this later.
+ */
+               ip->inst[0] = vcmpinst[m];
+/*
+ *             Find appropriate vector source regs for VCMP, here assume all the
+ *             regs are of same type set by vflag, later relax this assumption
+ */
+               for (j = 2; j < 4; j++)
+               {
+                  op = ip->inst[j];
+                  assert(op);
+                  if ( op < 0)
+                  {
+                     op = -op;
+                     k = FindInShortList(nfr,sregs, op);
+                     if (!k)
+                     {
+                        nfr = AddToShortList(nfr, sregs, op);
+                        k = FindInShortList(nfr, sregs, op);
+                        vregs[k-1] = GetReg(FLAG2TYPE(lp->vflag));
+                     }
+                     ip->inst[j] = -vregs[k-1];
+                  }
+                  else
+                  {
+                     if (IS_DEREF(STflag[op-1]))
+                     {
+                        k = STpts2[op-1];
+                        if (!FindInShortList(lp->varrs[0],lp->varrs+1,k))
+                        {
+                           k = FindInShortList(lp->vscal[0],lp->vscal+1,k);
+                           assert(k);
+                           ip->inst[j] = SToff[lp->vvscal[k]-1].sa[2];
+                           assert(ip->inst[j] > 0);
+                        }
+                     }
+                     else if (!FindInShortList(lp->varrs[0],lp->varrs+1,op))
+                     {
+                        k = FindInShortList(lp->vscal[0], lp->vscal+1, op);
+                        assert(k);
+                        ip->inst[j] = lp->vvscal[k];
+                     }
+                  }
+               }
+#ifdef AVX
+/*
+ *             get new vregs for the destination, no vld as it is not uses but
+ *             sets
+ */
+               vrd = GetReg(FLAG2TYPE(lp->vflag));
+               ip->inst[1] = -vrd;
+#else
+/*
+ *             NOTE: for SSE, vcmpwXX has 3 operand, des and src1 is aliased
+ */
+               op = ip->inst[2];
+               if (op < 0 )
+               {
+                  vrd = -op;
+                  ip->inst[1] = op;
+               }
+               else
+                  assert(0); /* src1 is deref: will consider this case later */
+
+#endif
+/*
+ *             it's time to add other instruction like mask and test
+ *             ireg is set, so, get a new ireg
+ */
+               ir = GetReg(T_INT);
+               ip = InsNewInst(bl->blk, ip, NULL, mskinst, -ir, -vrd, 0);
+/*
+ *             add test the iregs with const val populated by vec len
+ */
+/*============================================================================
+ *             Under Construction !!!!!
+ *             Just for tesing ... .... ....
+ *============================================================================*/
+#if 0
+/*
+ *             NOTE: consider the 'path =1' is case for vector fall thru.
+ *             Later, we will need a tester to test it !!!!
+ */
+               extern int path;
+
+               if (path==1 && VPATH==0)
+               {
+/*
+ *                vector path is the fall thru
+ */
+                  mskval = 0;
+                  ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
+                                  STiconstlookup(mskval)) ;
+/*                ip = InsNewInst(bl->blk, ip, NULL, CMPAND, -ir, -ir,
+                                  STiconstLoopup(mskval)) ; */
+                  ip->next->inst[0] = JNE;
+               }
+               else
+               {
+/*
+ *                if the scalar is the fall thru
+ */
+                  fprintf(stderr, "SCALAR FALL-TRU SELECTED!\n\n");
+
+                  mskval = 1;
+                  for (i = 1; i < vlen; i++)
+                     mskval = (mskval << 1) | 1;
+                  ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
+                                  STiconstlookup(mskval)) ;
+                  ip->next->inst[0] = JEQ;
+               }
+
+#else          /* consider vcmp_any case.. only fall through vector path */
+/*
+ *             NOTE:
+ *             By default, we always vectorize the fall-thru case, our
+ *             intension is to get the maxium perf. So, making the scalar
+ *             path as fall-thru is meaningless!!
+ */
+               mskval = 0;
+               ip = InsNewInst(bl->blk, ip, NULL, CMP, -ICC0, -ir,
+                               STiconstlookup(mskval)) ;
+/*             ip = InsNewInst(bl->blk, ip, NULL, CMPAND, -ir, -ir,
+                               STiconstLoopup(mskval)) ; */
+               ip->next->inst[0] = JNE;
+#endif
+/*
+ *             Majedul: NOTE: here ends a block. Shouldn't we re-initialize
+ *             the reg with GetReg(-1). !!!!!
+ *             FIXME:
+ */
+/*=========================================================================*/
+            }
+            else /* changing other scalar inst to vector inst */
+            {
+               for (i=0; i < nvinst; i++)
+               {
+/*
+ *                If the inst is scalar fp, translate to vector fp, and insist
+ *                all fp ops become vector ops
+ */
+                  if (sinst[i] == inst)
+                  {
+                     ip->inst[0] = vinst[i];
+/*
+ *                   Change scalar ops to vector ops
+ */
+                     for (j=1; j < 4; j++)
+                     {
+                        op = ip->inst[j];
+                        if (!op) continue;
+                        else if (op < 0)
+                        {
+                           op = -op;
+                           k = FindInShortList(nfr, sregs, op);
+                           if (!k)
+                           {
+                              nfr = AddToShortList(nfr, sregs, op);
+                              k = FindInShortList(nfr, sregs, op);
+                              vregs[k-1] = GetReg(FLAG2TYPE(lp->vflag));
+                           }
+                          ip->inst[j] = -vregs[k-1];
+                        }
+                        else
+                        {
+                           if (IS_DEREF(STflag[op-1]))
+                           {
+                              k = STpts2[op-1];
+                              if (!FindInShortList(lp->varrs[0],lp->varrs+1,k))
+                              {
+                                 k = FindInShortList(lp->vscal[0],lp->vscal+1,
+                                                     k);
+                                 assert(k);
+                                 ip->inst[j] = SToff[lp->vvscal[k]-1].sa[2];
+                                 assert(ip->inst[j] > 0);
+                              }
+                           }
+                           else if (!FindInShortList(lp->varrs[0],lp->varrs+1,
+                                    op))
+                           {
+                              k = FindInShortList(lp->vscal[0], lp->vscal+1,
+                                                  op);
+                              assert(k);
+                              ip->inst[j] = lp->vvscal[k];
+                           }
+                        }
+                     }
+                     break;
+                  }
+               }
+            }
+         }
+      }
+   }
+   GetReg(-1);
 /*
  * Put back loop control and pointer updates
  */
@@ -4028,21 +4884,206 @@
       {

       }
-   }
+   }
+}
+
+int IsBackupCandidate(short var, short vpflag, int chcom)
+/*
+ * check whether this var is a candidate for back and recovery,
+ * when chcom is set, check only the common blks upto cond branch
+ * vpflag represent the flag got from vector path
+ */
+{
+   int i, j, check;
+   BLIST *bl, *scope;
+   BBLOCK *bp;
+   INSTQ *ip;
+/*
+ * this logic of this function is true only if there is 2 paths.
+ * if there are morethan 2 paths, we need to extend the logic
+ */
+   assert(NPATH==2);
+/*
+ * private var need no backup/recovery
+ */
+   if (vpflag & SC_PRIVATE) return(0);
+   if (vpflag & SC_SET)
+   {
+/*
+ * if chcom is set, only the common blks before 1st conditional branch is
+ * checked.
+ */
+      if (chcom)
+      {
+         scope = PATHS[VPATH]->blocks;
+/*
+ *       assuming blks are consequtive in path, FindLoopPath algo suggests
+ *       that
+ */
+         for (bl=scope; bl; bl=bl->next)
+         {
+            for (ip = bl->blk->inst1; ip; ip=ip->next)
+            {
+/*
+ *             can be checked whether a var is set using bitvec, but
+ *             I use here directly the inst format as it maintain the ld
+ *             st syntax yet.
+ */
+               if (IS_COND_BRANCH(ip->inst[0]))
+               {
+                  return(0);
+               }
+               /*else if (IS_STORE(ip->inst[0]) && ip->inst[1] == var)*/
+               else if(ip->inst[1] == var)
+               {
+                  return(1);
+               }
+            }
+         }
+         return(0);
+      }
+      else
+         return(1);
+   }
+   else return(0); /* if not set in vpath, no need to backup it */
+}
+
+void AddVectorRecover(LOOPQ *lp, BBLOCK *bp0, int spath, int chcom)
+/*
+ * adds backup in vector path and recovery at the first of scalar path
+ * if chcom (check common) is set, check only common path before the conditional
+ * branch.
+ */
+{
+   int i, j, N, n, k;
+   short *sc, *vvsc, *sf, *bvvscal;
+   BLIST *scope;
+   INSTQ *ip;
+   enum inst vld, vst;
+   short vreg;
+   char ln[512];
+/*
+ * temporary for backup variables
+ */
+   n = 0;
+   bvvscal = calloc(lp->vvscal[0]+1, sizeof(short));
+   assert(bvvscal);
+/*
+ * we need to check only the vector path for vector backup and recovery
+ * NOTE: What happens for Memory write!!! There is no recopvery machanism.
+ * FIXME: right now, we don't consider memory write in speculation. we
+ * should add an assert to exit if there is a memory write in our scope.
+ */
+   vvsc = lp->vvscal;
+/*
+ * NOTE: in vpath, scal and vscal represent the same. There should not be any
+ * scal in vector path which is not vectorizatable. So, in vector path, I use
+ * scal and vscal interchangeably. But for scalar path, it would not be the
+ * case. vscal should be NULL.
+ * HERE HERE, but sflag and vsflag can't be used interchangeably.
+ * FIXME: Then why both scal and vscal are used in optloop !!!
+ */
+   sc = PATHS[VPATH]->vscal; /* check only the scalar of vpath */
+   sf = PATHS[VPATH]->sflag;
+
+   for (i=1, N=sc[0]; i <= N; i++) /* */
+   {
+      if (IsBackupCandidate(sc[i], sf[i], chcom))
+      {
+/*
+ *       accroding to current implementation of PathFlowVectorAnalysis,
+ *       scal, vscal are same. inserted a assert about the assumption.
+ */
+         assert(lp->vscal[i] == PATHS[VPATH]->vscal[i]
+                && lp->vscal[i] == PATHS[VPATH]->scal[i]) ;
+/*
+ *       create new vector var for backup ... ... ...
+ */
+         sprintf(ln, "_B%s", STname[vvsc[i]-1]);
+         k = bvvscal[i] = STdef(ln, LOCAL_BIT | FLAG2TYPE(lp->vflag), 0);
+         j = AddDerefEntry(-REG_SP, k, -k, 0, k);
+         SToff[k-1].sa[2] = j; /* AddDerefEntry may change the SToff itself */
+         n++;
+#if 0
+         fprintf(stderr, "%s: %s(%s) needs backup!\n", STname[bvvscal[i]-1],
+                 STname[vvsc[i]-1], STname[sc[i]-1]);
+#endif
+      }
+   }
+/*
+ * has backup var? update optloop
+ */
+   if (n)
+   {
+      bvvscal[0] = N;
+      lp->bvvscal = bvvscal;
+/*
+ *    Add code to restore the original vector from the backup at the begining of
+ *    scalar restart. This func is call right after the creation of the scalar
+ *    restart blk. so, add inst at the end to keep the necessary labels intack.
+ *    HERE HERE, backup of this variable should be at the beginning of vector
+ *    path.
+ */
+/*
+ *    set appropriate inst
+ */
+      if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
+      {
+         vld = VFLD;
+         vst = VFST;
+      }
+      else
+      {
+         vld = VDLD;
+         vst = VDST;
+      }
+
+      ip = bp0->instN;
+      ip = InsNewInst(bp0, ip, NULL, CMPFLAG, CF_SSV_VRECOVERY, 0, 0);
+      for (N=lp->bvvscal[0], i=1; i <= N; i++)
+      {
+        if(lp->bvvscal[i])
+        {
+           vreg = GetReg(FLAG2TYPE(lp->vflag));
+           ip = PrintComment(bp0, ip, NULL, "Restoring vector %s form %s",
+                             STname[lp->vvscal[i]-1], STname[lp->bvvscal[i]-1]);
+           ip = InsNewInst(bp0, ip, NULL, vld, -vreg,
+                           SToff[lp->bvvscal[i]-1].sa[2], 0);
+           ip = InsNewInst(bp0, ip, NULL, vst, SToff[lp->vvscal[i]-1].sa[2],
+                           -vreg, 0);
+           GetReg(-1);
+        }
+      }
+   }
+   else
+   {
+      lp->bvvscal = NULL;
+      free(bvvscal);
+   }
+
+#if 0
+   fprintf(stderr, "\n Vaiable set in vector path\n");
+   fprintf(stderr, "================================\n");
+
+    //fprintf(stderr, "Control Flag: %d\n", PATHS[i]->lpflag);
+   fprintf(stderr, "SET: ");
+   sc = PATHS[VPATH]->scal;
+   sf = PATHS[VPATH]->sflag;
+   for (j=1, N=sc[0]; j <= N; j++ )
+   {
+      if (sf[j] & SC_PRIVATE) continue;
+      if (sf[j] & SC_SET)
+         fprintf(stderr,"%s(%d) ",STname[sc[j]-1], sf[j]);
+   }
+   fprintf(stderr,"\n");
+#endif

 }

-void AddBackupRecover(LOOPQ *lp, BBLOCK *bp0, int spath)
-/*
- * adds back in vector path and recovery at the first of scalar path
- */
-{
-
-}
-
 void AddScalarUpdate(LOOPQ *lp, BBLOCK *bp0, int spath)
 /*
  * Vector-to-scalar reduction to operate on scalar in Scalar Restart
+ * inst is added at the end of the block bp0
  */
 {
    int i, j, k, N;
@@ -4066,7 +5107,7 @@
    for (i=1, N=vp->vscal[0]; i <= N; i++)
    {
       vscal = vp->vscal[i];
-      vpsflag = vp->sflag[i]; /* flags for the vars */
+      vpsflag = vp->sflag[i]; /* SC flags for the vars */
 /*
  *    if it is private vector variable, nothing to do.
  */
@@ -4094,7 +5135,7 @@
  */
            if (IS_FLOAT(lp->vflag) || IS_VFLOAT(lp->vflag))
            {
-              ip = PrintComment(bp0, ip, NULL, "Reduce accumulator vector for%s"
+              ip = PrintComment(bp0, ip, NULL,"Reduce accumulator vector for %s"
                                 ,STname[vscal-1]);
               ip = InsNewInst(bp0, ip, NULL, VFLD, -r0,
                               SToff[lp->vvscal[i]-1].sa[2], 0);
@@ -4375,7 +5416,7 @@
 }

 void DupBlkPathWithOpt(LOOPQ *lp, BLIST **dupblks, int islpopt, int UsesIndex,
-                       int UsesPtrs, int path)
+                       int UsesPtrs, int path, int dups)
 /*
  * duplicates loop blks vector lenth's time with loop index and ptr update
  * optimization if valid
@@ -4391,13 +5432,16 @@
    struct ptrinfo *pi;
    extern int FKO_BVTMP;
    static int fid = 1;
-
+#if 0
    vlen = Type2Vlen(lp->vflag);
    URbase = (lp->flag & L_FORWARDLC_BIT) ? 0 :vlen-1;
+#else
+   URbase = (lp->flag & L_FORWARDLC_BIT) ? 0 :dups-1;
+#endif
    iv = FKO_BVTMP;
    SetVecAll(iv, 0);

-   for ( i=0; i < vlen; i++)
+   for ( i=0; i < dups; i++)
    {
       SetVecBit(lp->blkvec, lp->header->bnum-1, 0);
       FKO_BVTMP = iv = BitVecCopy(FKO_BVTMP, lp->blkvec);
@@ -4493,7 +5537,7 @@

 }

-BBLOCK *GenScalarRestartPathCode(LOOPQ *lp, int path, int vlen,BLIST *ftheads,
+BBLOCK *GenScalarRestartPathCode(LOOPQ *lp, int path, int vlen, BLIST *ftheads,
                                  int ivtails)
 {
    int i, j;
@@ -4516,7 +5560,7 @@
 /*
  * dublicates blocks with required optimization
  */
-   DupBlkPathWithOpt(lp, dupblks, islpopt, UsesIndex, UsesPtrs, path);
+   DupBlkPathWithOpt(lp, dupblks, islpopt, UsesIndex, UsesPtrs, path, vlen);

 /*
  * create a new BBLOCK structure for the scalar restart of this path
@@ -4527,9 +5571,17 @@
    InsNewInst(bp0, NULL,NULL,LABEL,cflag,0,0);
 /*
  * Here starts the backup recovery operation.
- * Right now, it is dummy function.
- */
-   AddBackupRecover(lp, bp0, path);
+ * Right now, it is dummy function.
+ * NOTE: We will need to check the whole vector path for backup/recovery
+ * if we want to unroll it, otherwise we need to check only the blks upto
+ * the conditional branch to scalar_restart
+ */
+/*
+ * HERE HERE, why dasum (with if clause) with vector backup/recovery
+ * provides better performance!!!
+ */
+  AddVectorRecover(lp, bp0, path, vlen > Type2Vlen(lp->vflag)? 0 : 1);
+  //AddVectorRecover(lp, bp0, path, 0); /* for testing */
 /*
  * Here, we start vector to scalar update
  */
@@ -4711,8 +5763,9 @@
    return bp;
 }

-void ScalarRestart(LOOPQ *lp)
-/*
+void ScalarRestart(LOOPQ *lp, int dups)
+/*
+ * NOTE: added a new parameter to control the num of dups
  * In new Imp: 1st generate the whole code structure for each path
  * which can be explored by down/up pointer, then update the original code
  * NOTE: scalar restart is tested with 2 paths. I'm not sure how to place
@@ -4732,7 +5785,11 @@

    assert(VPATH!=-1);
    bpaths = malloc(sizeof(BBLOCK*)*NPATH);
+#if 0
    vlen = Type2Vlen(lp->vflag);
+#else
+   vlen = dups;
+#endif
 /*
  * Find the header of loop in the bbbase
  * NOTE: after cleanup, blocks have duplicate names. don't check anything
@@ -5329,8 +6386,9 @@
 }

-int SpecSIMDLoop(void)
+int SpecSIMDLoop(int SB_UR)
 {
+   int unroll;    /* stronger bet unroll */
    LOOPQ *lp;
    INSTQ *ippu;
    struct ptrinfo *pi0;
@@ -5338,6 +6396,8 @@
    lp = optloop;

    KillLoopControl(lp);
+
+   unroll = (SB_UR < 2)? 1: SB_UR;
 /*
  * NOTE: Loop peeling must be called before cleanup, as it may chnage the loop
  * control structure of main loop, hence the cleanup loop.
@@ -5399,18 +6459,24 @@
    PrintInst(stdout, bbbase);
    exit(0);
 #endif
-   ScalarRestart(lp);
+
+   ScalarRestart(lp, Type2Vlen(lp->vflag)*unroll);
+
 /*
  * Consider only vector path now. Need to add some analysis for various vars
- * to implement backup stages.
+ * to implemnt backup stages.
  */
 #if 0
    fprintf(stdout, " LIL AFTER SCALAR RESTART LOOP \n");
    PrintInst(stdout, bbbase);
    exit(0);
 #endif
+
+#if 0
    SpeculativeVecTransform(lp);
-
+#else
+   SpecVecXform(lp, unroll);
+#endif
 #if 0
    fprintf(stdout, " LIL AFTER SSV LOOP \n");
    PrintInst(stdout, bbbase);


Update documentation

Update documentation

--- DKScrollingTabController/DKScrollingTabController.h
+++ DKScrollingTabController/DKScrollingTabController.h
@@ -8,6 +8,8 @@

 @class DKScrollingTabController;
+
+/** DKScrollingTabController delegate. */
 @protocol DKScrollingTabControllerDelegate <NSObject>

 /**
@@ -21,6 +23,7 @@
 @end

+/** A scrolling tab controller alternative to UISegmentedControl. */
 @interface DKScrollingTabController : UIViewController

 /**


Remove unintended semi-colon in os-hpux.c fun definition

Probably a copy/paste error... This showed up on ia64-hpux.

--- src/os-hpux.c
+++ src/os-hpux.c
@@ -36,7 +36,7 @@
 HIDDEN int
 tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
 		    unsigned long *segbase, unsigned long *mapoff,
-		    char *path, size_t pathlen);
+		    char *path, size_t pathlen)
 {
   struct load_module_desc lmd;
   const char *path2;


fix for uidinsignature with groups mirror 3.6.7

--- src/pgsql_drv.c
+++ src/pgsql_drv.c
@@ -1,4 +1,4 @@
-/* $Id: pgsql_drv.c,v 1.58 2006/05/30 15:49:54 jonz Exp $ */
+/* $Id: pgsql_drv.c,v 1.59 2006/06/03 03:11:36 jonz Exp $ */

 /*
  DSPAM
@@ -1074,9 +1074,9 @@
   pid = getpid ();
   if (_ds_match_attribute(CTX->config->attributes, "PgSQLUIDInSignature", "on"))
   {
-    p = _pgsql_drv_getpwnam (CTX, CTX->username);
+    p = _pgsql_drv_getpwnam (CTX, (CTX->group) ? CTX->group : CTX->username);
     if (!p) {
-      LOG(LOG_ERR, "Unable to determine UID for %s", CTX->username);
+      LOG(LOG_ERR, "Unable to determine UID for %s", (CTX->group) ? CTX->group : CTX->username);
       return EINVAL;
     }


osd: add a message_from_mon function

osd: add a message_from_mon function

--- src/osd/OSD.h
+++ src/osd/OSD.h
@@ -195,6 +195,14 @@
   };

 private:
+  inline bool message_from_mon(Message *m) {
+    Session *session = (Session *)m->get_connection()->get_priv();
+    if (!session) return true; //this must be an outgoing connection we opened
+    bool ret = session->caps.is_mon();
+    session->put();
+    return ret;
+  }
+
   // -- heartbeat --
   Mutex heartbeat_lock;
   Cond heartbeat_cond;


Remove blank line

Remove blank line

git-svn-id: 3d54f09c3274966c78a0b0842e411ae2b9b02a46@429 5b3c568a-86f9-4a59-a47a-7be284f604b4

--- src/ows/ows.c
+++ src/ows/ows.c
@@ -291,7 +291,6 @@
         /* WFS 1.1.0 mandatory */
         if (     !strcmp(getenv("CONTENT_TYPE"), "application/x-www-form-urlencoded"))
             o->request->method = OWS_METHOD_KVP;
-
         else if (!strcmp(getenv("CONTENT_TYPE"), "text/xml"))
             o->request->method = OWS_METHOD_XML;


Fix (hopefully) the bug that makes the shipgate go berserk every few months.

That code was... very wrong. Not sure why I had it correct in ship_server, but so wrong in shipgate still.

--- src/packets.c
+++ src/packets.c
@@ -40,11 +40,13 @@
         while(total < len) {
             rv = ship_send(c, sendbuf + total, len - total);

-            if(rv == -1 && errno != EAGAIN) {
-                return -1;
-            }
-            else if(rv == -1) {
-                break;
+            /* Did the data send? */
+            if(rv < 0) {
+                /* Is it an error code that might be correctable? */
+                if(rv == GNUTLS_E_AGAIN || rv == GNUTLS_E_INTERRUPTED)
+                    continue;
+                else
+                    return -1;
             }

             total += rv;
@@ -290,7 +292,7 @@
     pkt->guildcard = htonl(gc);
     pkt->slot = htonl(slot);
     pkt->block = block;
-    memcpy(pkt->data, cdata, sz);
+    memcpy(pkt->data, cdata, sz);

     /* Send it away. */
     return send_crypt(c, sizeof(shipgate_char_data_pkt) + sz);


Some palette importer fixes

Some palette importer fixes

--- src/palette.c
+++ src/palette.c
@@ -1,5 +1,6 @@
 #include <stdint.h>
 #include <string.h>
+#include <stdio.h>
 #include "shadowdive/error.h"
 #include "shadowdive/palette.h"

@@ -64,12 +65,14 @@
     if(!sd_match(rd, "GIMP Palette\n", 13)) {
         return SD_FILE_INVALID_TYPE;
     }
-    sd_read_scan(rd, "Name: %s\n", tmp);
-    sd_read_scan(rd, "#\n", tmp);
+    sd_read_line(rd, tmp, 128); // Read name (we don't care about the value)
+    sd_read_line(rd, tmp, 128); // Read the # field

     // Read data
+    tmp[4] = 0;
     for(i = 0; i < 255; i++) {
-        sd_read_scan(rd, "%3u %3u %3u\n", &r, &g, &b);
+        sd_read_line(rd, tmp, 128);
+        sscanf(tmp, "%3hhu %3hhu %3hhu", &r, &g, &b);
         palette->data[i][0] = r;
         palette->data[i][1] = g;
         palette->data[i][2] = b;


Fix snd_pcm_open_noupdate() to refer alias

Fixed snd_pcm_open_noupdate() to refer alias.  This fixes the call like

	% aplay -Dplug:bah

where bah is an alias of a certain definition.

--- src/pcm/pcm.c
+++ src/pcm/pcm.c
@@ -2138,13 +2138,20 @@
 {
 	int err;
 	snd_config_t *pcm_conf;
+	const char *str;
+
 	err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
 	if (err < 0) {
 		SNDERR("Unknown PCM %s", name);
 		return err;
 	}
-	snd_config_set_hop(pcm_conf, hop);
-	err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
+	if (snd_config_get_string(pcm_conf, &str) >= 0)
+		err = snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
+					    hop + 1);
+	else {
+		snd_config_set_hop(pcm_conf, hop);
+		err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
+	}
 	snd_config_delete(pcm_conf);
 	return err;
 }


[AdgLDim] Using CpmlPair instead of AdgPair

This does not change anything at a logical level, but the use of a single
data type for pairs improves data consistency.

--- adg/adg-ldim-private.h
+++ adg/adg-ldim-private.h
@@ -71,7 +71,7 @@

     struct {
         gboolean         is_arranged;
-        CpmlPair         from, base, to;
+        AdgPair          from, base, to;
     }                    shift;

     struct {


change dconf-set to use GVariant text format

--- bin/dconf-set.c
+++ bin/dconf-set.c
@@ -20,14 +20,17 @@
   gboolean success;
   GVariant *value;
   gchar *event_id;
+  gchar *string;

-  if (argc != 3 || !dconf_is_key (argv[1]))
+  if (argc < 3 || !dconf_is_key (argv[1]))
     {
-      fprintf (stderr, "usage: dconf-set /dconf/key '<gvariant-markup/>'\n");
+      fprintf (stderr, "usage: dconf-set /dconf/key value...'\n");
       return 1;
     }

-  value = g_variant_markup_parse (argv[2], -1, NULL, &error);
+  string = g_strjoinv (" ", argv + 2);
+  value = g_variant_parse (string, -1, NULL, &error);
+  g_free (string);

   if (value == NULL)
     {


Justin pointed out that the .readline() method of the headers bucket would
not advance the read pointer forward. This was fixed by factoring out some
logic from the read method to consume the current chunk of header data.

* buckets/headers_buckets.c:
  (consume_chunk): logic factored out of the read() method to consume the
    current data chunk of the header. it also computes an appropriate
    return status code based on whether further data is available.
  (serf_headers_read): factor out the chunk consumption logic into
    consume_chunk().
  (serf_headers_readline): use the new consume_chunk() function.

git-svn-id: 683495cb1553624b05a54e2ba9533425f69cf277@192 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845

--- buckets/headers_buckets.c
+++ buckets/headers_buckets.c
@@ -198,6 +198,30 @@
     *len = l - ctx->amt_read;
 }

+/* the current data chunk has been read/consumed. move our internal state. */
+static apr_status_t consume_chunk(headers_context_t *ctx)
+{
+    /* move to the next state, resetting the amount read. */
+    ++ctx->state;
+    ctx->amt_read = 0;
+
+    /* end of this header. move to the next one. */
+    if (ctx->state == READ_DONE) {
+        ctx->cur_read = ctx->cur_read->next;
+        if (ctx->cur_read == NULL) {
+            /* there is no more data. leave us at READ_DONE and signal
+               completion to the caller. */
+            return APR_EOF;
+        }
+
+        /* there _is_ another header, so reset the read state */
+        ctx->state = READ_HEADER;
+    }
+
+    /* there is more data which can be read immediately. */
+    return APR_SUCCESS;
+}
+
 static apr_status_t serf_headers_peek(serf_bucket_t *bucket,
                                       const char **data,
                                       apr_size_t *len)
@@ -234,32 +258,18 @@
     select_value(ctx, data, &avail);

     if (requested >= avail) {
+        /* return everything from this chunk */
         *len = avail;
-
+
         /* we consumed this chunk. advance the state. */
-        ++ctx->state;
-        ctx->amt_read = 0;
-
-        /* end of this header. move to the next one. */
-        if (ctx->state == READ_DONE) {
-            ctx->cur_read = ctx->cur_read->next;
-            if (ctx->cur_read != NULL) {
-                /* there _is_ a next one, so reset the read state */
-                ctx->state = READ_HEADER;
-            }
-            else {
-                /* nothing more. signal that. */
-                return APR_EOF;
-            }
-        }
-    }
-    else {
-        /* return just the amount requested, and advance our pointer */
-        *len = requested;
-        ctx->amt_read += requested;
-    }
-
-    /* there is more to read */
+        return consume_chunk(ctx);
+    }
+
+    /* return just the amount requested, and advance our pointer */
+    *len = requested;
+    ctx->amt_read += requested;
+
+    /* there is more that can be read immediately */
     return APR_SUCCESS;
 }

@@ -268,27 +278,27 @@
                                           const char **data, apr_size_t *len)
 {
     headers_context_t *ctx = bucket->data;
-
-    if (ctx->state == READ_DONE) {
-        *len = 0;
-        return APR_EOF;
-    }
-
-    /* note that select_value() will ensure ctx->cur_read is set for below */
-    select_value(ctx, data, len);
+    apr_status_t status;

     /* ### what behavior should we use here? abort() isn't very friendly */
     if ((acceptable & SERF_NEWLINE_CRLF) == 0)
         abort();

+    if (ctx->state == READ_DONE) {
+        *len = 0;
+        return APR_EOF;
+    }
+
+    /* get whatever is in this chunk */
+    select_value(ctx, data, len);
+
+    /* we consumed this chunk. advance the state. */
+    status = consume_chunk(ctx);
+
     /* the type of newline found is easy... */
     *found = ctx->state == READ_CRLF ? SERF_NEWLINE_CRLF : SERF_NEWLINE_NONE;

-    /* if we're on the last header, and the last part of it, then EOF */
-    if (ctx->cur_read->next == NULL && ctx->state == READ_CRLF)
-        return APR_EOF;
-
-    return APR_SUCCESS;
+    return status;
 }

 SERF_DECLARE_DATA const serf_bucket_type_t serf_bucket_type_headers = {


fix iconv_open checking natspec_convert returns dup of original string if converting is failed

--- lib/convert.c
+++ lib/convert.c
@@ -7,7 +7,7 @@
     Copyright (c) 2005 Etersoft
     Copyright (c) 2002, 2005 Vitaly Lipatov <lav@etersoft.ru>

-    $Id: convert.c,v 1.19 2007/07/31 21:06:33 vitlav Exp $
+    $Id: convert.c,v 1.20 2008/02/14 22:36:22 vitlav Exp $

     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -45,7 +45,7 @@
 	iconv_t it, ucs2;
 } ucs2table[MAX_UCS2];

-/*! Open iconv table */
+/*! Opens iconv table or returns -1 */
 iconv_t natspec_iconv_open(const char *tocode, const char *fromcode)
 {
 	int i;
@@ -55,15 +55,16 @@
 		fromcode = natspec_get_charset();
 	for (i=0; i < MAX_UCS2; i++)
 		if (!ucs2table[i].it) {
+			/* use i element if empty */
 			ucs2table[i].it = iconv_open(tocode, fromcode);
-			if (!ucs2table[i].it)
+			if (ucs2table[i].it == (iconv_t)-1)
 				break;
 			ucs2table[i].ucs2 = iconv_open("UCS2", fromcode);
-			if (ucs2table[i].ucs2)
+			if (ucs2table[i].ucs2 != (iconv_t)-1)
 				return ucs2table[i].it;
 			break;
 		}
-	return 0;
+	return (iconv_t)-1;
 }

 /*! For future compatibility */
@@ -116,6 +117,7 @@
 			return result;
 		if (!transliterate)
 			return result;
+		/* find corresport UCS2 table */
 		for (i=0; i < MAX_UCS2; i++)
 			if (ucs2table[i].it == cd) {
 				ucs2 = ucs2table[i].ucs2;
@@ -163,7 +165,7 @@
 	const char *tocode, const char *fromcode, int transliterate)
 {
 	size_t result;
-	iconv_t frt, ucs2;
+	iconv_t frt;
 	size_t lena = strlen(in_str)*6; /* FIXME see E2BIG for errno */
 	size_t lenb = strlen(in_str);
 	char *ansa = (char*)alloca(lena+1);
@@ -171,13 +173,15 @@
 	char *ansaptr = ansa;

 	frt = natspec_iconv_open(tocode, fromcode);
-	if (frt == (iconv_t) -1 || ucs2 == (iconv_t) -1)
+	if (frt == (iconv_t) -1)
 	{
-		char buf[100];
-		snprintf(buf,99,"Broken encoding: '%s' or '%s' (%d) or UCS2 (%d). May be you forget setlocale in main?\n",
-			tocode, fromcode, (int)frt, (int)ucs2);
+		char buf[200];
+		snprintf(buf,199,"Broken encoding: '%s' (to) or '%s' (from) or UCS2. May be you forget setlocale in main or gconv-modules is missed?\n",
+			tocode, fromcode);
 		perror(buf);
-		return NULL;
+		/* return dup of original string if converting is failed */
+		ansaptr = strdup(in_str);
+		return ansaptr;
 	}
 	result = natspec_iconv(frt, &ansbptr, &lenb, &ansaptr, &lena, transliterate);
 	natspec_iconv_close(frt);


check the current pcm status in snd_pcm_read/write_areas() if snd_pcm_wait() returns an error.  this will fix the bogus return code of snd_pcm_readi/writei().

--- src/pcm/pcm.c
+++ src/pcm/pcm.c
@@ -6110,9 +6110,15 @@
 			}

 			err = snd_pcm_wait(pcm, -1);
-			if (err < 0)
+			state = snd_pcm_state(pcm);
+			if (err < 0) {
+				/* check more precisely */
+				if (state == SND_PCM_STATE_XRUN)
+					err = -EPIPE;
+				else if (state == SND_PCM_STATE_SUSPENDED)
+					err = -ESTRPIPE;
 				break;
-			state = snd_pcm_state(pcm);
+			}
 			goto _again;

 		}
@@ -6183,9 +6189,15 @@
 			}

 			err = snd_pcm_wait(pcm, -1);
-			if (err < 0)
+			state = snd_pcm_state(pcm);
+			if (err < 0) {
+				/* check more precisely */
+				if (state == SND_PCM_STATE_XRUN)
+					err = -EPIPE;
+				else if (state == SND_PCM_STATE_SUSPENDED)
+					err = -ESTRPIPE;
 				break;
-			state = snd_pcm_state(pcm);
+			}
 			goto _again;

 		}


pcm: restore hw params on set latency failed

When method snd_pcm_set_params sets sample rate to 22050 and latency to 50000
to davinci soc driver method snd_pcm_hw_params_set_buffer_time_near fails
and variable params is already changed in the method so the next method
snd_pcm_hw_params_set_period_time_near fails also.

Signed-off-by: Martin Geier <26f482dd9ff66cbfedb9f1b2b0f3fafa17e247c5@streamunlimited.com>
Signed-off-by: Takashi Iwai <4596b3305151c7ee743192a95d394341e3d3b644@suse.de>

--- src/pcm/pcm.c
+++ src/pcm/pcm.c
@@ -8004,7 +8004,7 @@
                        int soft_resample,
                        unsigned int latency)
 {
-        snd_pcm_hw_params_t *params;
+        snd_pcm_hw_params_t *params, params_saved;
         snd_pcm_sw_params_t *swparams;
         const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
         snd_pcm_uframes_t buffer_size, period_size;
@@ -8057,9 +8057,11 @@
 		return -EINVAL;
 	}
 	/* set the buffer time */
+	params_saved = *params;
 	err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, &latency, NULL);
 	if (err < 0) {
 	        /* error path -> set period size as first */
+		*params = params_saved;
         	/* set the period time */
         	period_time = latency / 4;
         	err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL);


Restore subs.

Restore subs.

--- src/persist.c
+++ src/persist.c
@@ -342,8 +342,9 @@
 	uint32_t crc, db_version;
 	uint64_t i64temp;
 	uint32_t i32temp, length;
-	uint16_t i16temp, chunk;
-	uint8_t i8temp;
+	uint16_t i16temp, chunk, slen;
+	uint8_t i8temp, qos;
+	char *client_id, *topic;

 	assert(db);
 	assert(db->filepath);
@@ -373,6 +374,39 @@
 				db->last_db_id = be64toh(i64temp);
 				break;

+			case DB_CHUNK_MSG_STORE:
+				break;
+
+			case DB_CHUNK_CLIENT_MSG:
+				break;
+
+			case DB_CHUNK_RETAIN:
+				break;
+
+			case DB_CHUNK_SUB:
+				read_e(fd, &i16temp, sizeof(uint16_t));
+				slen = ntohs(i16temp);
+				client_id = _mosquitto_malloc(slen);
+				if(!client_id){
+					close(fd);
+					mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
+					return 1;
+				}
+				read_e(fd, &client_id, slen);
+				read_e(fd, &i16temp, sizeof(uint16_t));
+				slen = ntohs(i16temp);
+				topic = _mosquitto_malloc(slen);
+				if(!topic){
+					close(fd);
+					mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
+					return 1;
+				}
+				read_e(fd, &topic, slen);
+				read_e(fd, &qos, sizeof(uint8_t));
+				if(_db_restore_sub(db, client_id, topic, qos)){
+					return 1;
+				}
+				break;

 			default:
 				mqtt3_log_printf(MOSQ_LOG_WARNING, "Warning: Unsupported chunk \"%d\" in persistent database file. Ignoring.", chunk);


PCM API - handle EINTR from poll() in snd_pcm_wait() function

--- src/pcm/pcm.c
+++ src/pcm/pcm.c
@@ -2240,8 +2240,11 @@
 	}
 	do {
 		err_poll = poll(pfd, npfds, timeout);
-		if (err_poll < 0)
+		if (err_poll < 0) {
+		        if (errno == EINTR)
+		                continue;
 			return -errno;
+                }
 		if (! err_poll)
 			break;
 		err = snd_pcm_poll_descriptors_revents(pcm, pfd, npfds, revents);


Fix slice method

Fix slice method

--- src/piocore.c
+++ src/piocore.c
@@ -171,7 +171,7 @@
   new_data->mask = ((1u << (msb - lsb + 1)) - 1) << lsb;
   ++new_data->owner->refs;

-  return pio_wrap(mrb, mrb_class_ptr(self), new_data);
+  return pio_wrap(mrb, mrb_obj_class(mrb, self), new_data);
 }

 static mrb_value


Update ROASArdLib.h

Update ROASArdLib.h

--- ROAS-Ard-Lib/ROASArdLib.h
+++ ROAS-Ard-Lib/ROASArdLib.h
@@ -1,4 +1,17 @@
 #ifdef ROASARDLIB_h
 #define ROASARDLIB_h

+#include "Arduino.h"
+
+class _ROASClass
+{
+  void ROASBegin();
+  void beginsetup();
+  void endsetup();
+  void beginloop();
+  void loopsetup();
+  void endloop();
+  extern _ROASClass ROASArdLib;
+  extern _ROASClass ROASLib;
+}
 #endif


TODO - find a less hacky way of doing this

--- ocaml/xenguest/xenguest_stubs.c
+++ ocaml/xenguest/xenguest_stubs.c
@@ -809,7 +809,7 @@
 #ifdef XENGUEST_4_2
                           ,
                           Bool_val(no_incr_generationid),
-                          &c_vm_generationid_addr,
+                          0, &c_vm_generationid_addr,
                           NULL /* restore_callbacks */
 #elif defined(XC_HAS_4_1_NEW_GENERATION_ID_INTERFACE)
                           ,genid_callback, &genid_cb_data


Update on diagonal benchmark.

Update on diagonal benchmark.

Using standard IEEE math leads to significant performance differences in the
diagonal case for different values of gamma. This is presumably happening
because of underflow issues in the exponential decay function. The performance
differences disappear when compiled with "-ffast-math".

--- spammpack-C/LinearAlgebraLibrary/benchmarks/multiply.c
+++ spammpack-C/LinearAlgebraLibrary/benchmarks/multiply.c
@@ -2,10 +2,13 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <math.h>
+//#include <fenv.h>
 #include <sys/time.h>
 #include <sys/resource.h>

 #define THRESHOLD 1e-14
+
+//#pragma STDC FENV_ACCESS ON

 enum matrix_t
 {
@@ -30,9 +33,13 @@
   unsigned int N_block = 100;
   unsigned int K_block = 100;

+  unsigned int number_nonzeros;
+
   int print_matrix = 0;

   int use_kahan = 0;
+
+  //int fpe_raised;

   floating_point_t threshold = 0.0;
   floating_point_t gamma = 0.46;
@@ -189,6 +196,9 @@
     LOG2_INFO("using Kahan summation algorithm\n");
   }

+  /* Clear floating point exceptions. */
+  //feclearexcept(FE_ALL_EXCEPT);
+
   switch (matrix_type)
   {
     case dense:
@@ -253,6 +263,9 @@
         A_dense[spamm_dense_index(i, i, N, N)] = rand()/(floating_point_t) RAND_MAX + threshold;
         B_dense[spamm_dense_index(i, i, N, N)] = rand()/(floating_point_t) RAND_MAX + threshold;
         C_dense[spamm_dense_index(i, i, N, N)] = rand()/(floating_point_t) RAND_MAX + threshold;
+        //A_dense[spamm_dense_index(i, i, N, N)] = 0.1;
+        //B_dense[spamm_dense_index(i, i, N, N)] = 0.1;
+        //C_dense[spamm_dense_index(i, i, N, N)] = 0.1;
       }

       for (i = 0; i < N; i++) {
@@ -263,6 +276,12 @@
             A_dense[spamm_dense_index(i, j, N, N)] = exp(-gamma*fabs((int) i - (int) j))*A_dense[spamm_dense_index(i, i, N, N)]*A_dense[spamm_dense_index(j, j, N, N)];
             B_dense[spamm_dense_index(i, j, N, N)] = exp(-gamma*fabs((int) i - (int) j))*B_dense[spamm_dense_index(i, i, N, N)]*B_dense[spamm_dense_index(j, j, N, N)];
             C_dense[spamm_dense_index(i, j, N, N)] = exp(-gamma*fabs((int) i - (int) j))*C_dense[spamm_dense_index(i, i, N, N)]*C_dense[spamm_dense_index(j, j, N, N)];
+            //if (fabs((int) i - (int) j) < gamma)
+            //{
+            //  A_dense[spamm_dense_index(i, j, N, N)] = 0.1;
+            //  B_dense[spamm_dense_index(i, j, N, N)] = 0.1;
+            //  C_dense[spamm_dense_index(i, j, N, N)] = 0.1;
+            //}
           }
         }
       }
@@ -325,6 +344,36 @@
     printf("C (dense):\n");
     spamm_print_dense(M, N, C_dense);
   }
+
+  number_nonzeros = 0;
+  for (i = 0; i < M; i++) {
+    for (j = 0; j < K; j++)
+    {
+      if (A_dense[spamm_dense_index(i, j, M, K)] != 0.0) { number_nonzeros++; }
+    }
+  }
+  LOG_INFO("A has %u nonzeros, avg. of %1.2f nonzeros per row, %1.2f%% sparsity:\n",
+      number_nonzeros, number_nonzeros/(double) M, (1-number_nonzeros/(double) (M*K))*100);
+
+  number_nonzeros = 0;
+  for (i = 0; i < K; i++) {
+    for (j = 0; j < N; j++)
+    {
+      if (B_dense[spamm_dense_index(i, j, K, N)] != 0.0) { number_nonzeros++; }
+    }
+  }
+  LOG_INFO("B has %u nonzeros, avg. of %1.2f nonzeros per row, %1.2f%% sparsity:\n",
+      number_nonzeros, number_nonzeros/(double) K, (1-number_nonzeros/(double) (K*N))*100);
+
+  number_nonzeros = 0;
+  for (i = 0; i < M; i++) {
+    for (j = 0; j < N; j++)
+    {
+      if (C_dense[spamm_dense_index(i, j, M, N)] != 0.0) { number_nonzeros++; }
+    }
+  }
+  LOG_INFO("C has %u nonzeros, avg. of %1.2f nonzeros per row, %1.2f%% sparsity:\n",
+      number_nonzeros, number_nonzeros/(double) M, (1-number_nonzeros/(double) (M*N))*100);

   /* Convert to SpAMM. */
   spamm_new(M, K, M_block, K_block, 2, 2, 0.0, &A);
@@ -369,6 +418,17 @@
   usertime_blas = (rusage_stop.ru_utime.tv_sec-rusage_start.ru_utime.tv_sec)+(rusage_stop.ru_utime.tv_usec-rusage_start.ru_utime.tv_usec)/(double) 1e6;
   printf("walltime: %f s, user time: %f s\n", walltime_blas, usertime_blas);
 #else
+  /* Clear floating point exceptions. */
+  //fpe_raised = fetestexcept(FE_ALL_EXCEPT);
+  //LOG_INFO("fp exceptions raised: %u = ", fpe_raised);
+  //if (FE_DIVBYZERO | fpe_raised) { printf("DIVBYZERO "); }
+  //if (FE_INEXACT | fpe_raised) { printf("INEXACT "); }
+  //if (FE_INVALID | fpe_raised) { printf("INVALID "); }
+  //if (FE_OVERFLOW | fpe_raised) { printf("OVERFLOW "); }
+  //if (FE_UNDERFLOW | fpe_raised) { printf("UNDERFLOW "); }
+  //printf("\n");
+  //feclearexcept(FE_ALL_EXCEPT);
+
   LOG2_INFO("multiplying matrix directly to get reference product... ");
   gettimeofday(&start, NULL);
   getrusage(RUSAGE_SELF, &rusage_start);
@@ -393,6 +453,9 @@
           error_compensation = (Kahan_t - sum) - Kahan_y;
           if (fabs(error_compensation) > fabs(error_compensation_max)) { error_compensation_max = error_compensation; }
           sum = Kahan_t;
+
+          /* Check for floating point exceptions. */
+          //feclearexcept(FE_ALL_EXCEPT);
         }

         else


fix macOS's windowWillClose bug

fix macOS's windowWillClose bug

--- src/phi/app.c
+++ src/phi/app.c
@@ -7,28 +7,26 @@
 PhiBuffer *buffer_list; // opened buffers' list

 void window_close_callback(PtkEvent event) {
+  if (window_list == NULL) return;
+
   PtkWindow *ptk_widget = (PtkWindow *) event.target;

   // detect which window has been closed
   PhiWindow *prev = NULL;
   PhiWindow *window = window_list;
-
+
   do {
     if (window->ptk_widget == ptk_widget) {
       if (prev == NULL) {
         window_list = window->next;
-        printf("window_list = window->next;\n");
       } else {
         prev->next = window->next;
-        printf("prev->next = window->next;\n");
       }
-      printf("phi_window_destroy(window);\n");
       phi_window_destroy(window);
       --windowCount;
       break;
     } else {
       prev = window;
-      printf("prev = window;\n");
     }
   } while ((window = window->next));


git-svn-id: http://svn.seqan.de/seqan/trunk@8390 e6417c60-b987-48fd-844e-b20f0fcc1017

--- seqan/projects/library/seqan/sequence/std_vector.h
+++ seqan/projects/library/seqan/sequence/std_vector.h
@@ -542,10 +542,8 @@
 			copy(source.begin(),source.begin()+target_size,target.begin()+pos_begin);
 			target.insert(target.begin()+pos_end,source.begin()+target_size,source.end());
 		}
-	//target.replace(target.begin() + pos_begin, target.begin() + pos_end, begin(source, Standard()), end(source, Standard()));
-}
-
-/*
+}
+
 template <typename TChar, typename TAlloc, typename TSource>
 inline void
 replace(::std::vector<TChar, TAlloc> & target,
@@ -562,18 +560,19 @@
 	}
 	else
 	{
-		typename Iterator<TSource const, Standard>::Type source_begin = begin(source, Standard());
 		typename Size<TSource const>::Type source_length = length(source);
 		typename Size< ::std::vector<TChar, TAlloc> >::Type pos_mid = pos_begin + source_length;
+		typename Size< ::std::vector<TChar, TAlloc> >::Type pos_limit(limit);
 		if (pos_mid > limit)
 		{
-			target.replace(target.begin() + pos_begin, target.begin() + limit, source_begin, source_begin + limit - pos_begin);
+			target.resize(limit);
+			replace(target,pos_begin,pos_limit,source);
 			target.resize(limit);
 		}
 		else
 		{
-			target.replace(target.begin() + pos_begin, target.begin() + pos_end, source_begin, end(source, Standard()));
-			if (target.length() > limit)
+			replace(target,pos_begin,pos_end,source);
+			if (target.size() > limit)
 			{
 				target.resize(limit);
 			}
@@ -591,7 +590,7 @@
 		Limit)
 {
     SEQAN_CHECKPOINT;
-//	replace(target, pos_begin, pos_end, source, target.capacity(), Generous());
+	replace(target, pos_begin, pos_end, source, target.capacity(), Generous());
 }

 template <typename TChar, typename TAlloc, typename TSource>
@@ -608,36 +607,36 @@
 	{
 		limit = target.capacity();
 	}
-
-//	replace(target, pos_begin, pos_end, source, limit, Generous());
-}
+	replace(target, pos_begin, pos_end, source, limit, Generous());
+}
+

 //////////////////////////////////////////////////////////////////////////////
 // handling of iterators as begin and end

 template<typename TChar, typename TCharTraits, typename TAlloc, typename TSource, typename TExpand>
 inline void
-replace(::std::vector<TChar, TCharTraits, TAlloc> & target,
-		typename Iterator< ::std::vector<TChar, TCharTraits, TAlloc>, Rooted>::Type pos_begin,
-		typename Iterator< ::std::vector<TChar, TCharTraits, TAlloc>, Rooted>::Type pos_end,
+replace(::std::vector<TChar, TAlloc> & target,
+		typename Iterator< ::std::vector<TChar, TAlloc>, Rooted>::Type pos_begin,
+		typename Iterator< ::std::vector<TChar, TAlloc>, Rooted>::Type pos_end,
 		TSource & source,
 		Tag<TExpand> const tag)
 {
 	replace(target, position(pos_begin), position(pos_end), source, tag);
 }

-template<typename TChar, typename TCharTraits, typename TAlloc, typename TSource, typename TExpand>
-inline void
-replace(::std::vector<TChar, TCharTraits, TAlloc> & target,
-		typename Iterator< ::std::vector<TChar, TCharTraits, TAlloc>, Rooted>::Type pos_begin,
-		typename Iterator< ::std::vector<TChar, TCharTraits, TAlloc>, Rooted>::Type pos_end,
+template<typename TChar, typename TAlloc, typename TSource, typename TExpand>
+inline void
+replace(::std::vector<TChar, TAlloc> & target,
+		typename Iterator< ::std::vector<TChar, TAlloc>, Rooted>::Type pos_begin,
+		typename Iterator< ::std::vector<TChar, TAlloc>, Rooted>::Type pos_end,
 		TSource & source,
-		typename Size< ::std::vector<TChar, TCharTraits, TAlloc> >::Type limit,
+		typename Size< ::std::vector<TChar, TAlloc> >::Type limit,
 		Tag<TExpand> const tag)
 {
 	replace(target,  position(pos_begin),  position(pos_end), source, tag);
 }
-*/
+

 ///.Function.reserve.param.object.type:Adaption.std::vector
 ///.Function.reserve.remarks:For @Adaption.std::vector|STL Adaptions@, $reserve$ is only guaranteed to have the specified behaviour with $Insist$ and $Generous$.


Move calling break-hook outside the locked area.

--- src/pl-comp.c
+++ src/pl-comp.c
@@ -6044,7 +6044,7 @@
     *PC = encode(D_BREAK);
     set(clause, HAS_BREAKPOINTS);

-    return callEventHook(PLEV_BREAK, clause, offset);
+    return TRUE;
   } else
   { return not_breakable(ATOM_set, clause, offset);
   }
@@ -6077,7 +6077,7 @@
   freeHeap(bp, sizeof(*bp));
   deleteSymbolHTable(breakTable, s);

-  return callEventHook(PLEV_NOBREAK, clause, offset);
+  return TRUE;
 }

@@ -6138,6 +6138,9 @@
   else
     rc = clearBreak(clause, offset);
   PL_UNLOCK(L_BREAK);
+
+  if ( rc )
+    return callEventHook(doit ? PLEV_BREAK : PLEV_NOBREAK, clause, offset);

   return rc;
 }


whitespace and comment fixes

whitespace and comment fixes

git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@11746 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/pic_jit.c
+++ src/pic_jit.c
@@ -8,13 +8,20 @@

 =head1 DESCRIPTION

-Some statically known and simple subroutines are replace by
+Some statically known and simple subroutines are replaced by
 their JITted variants, if

   - JIT is supported and can JIT subroutines
   - arguments passing is simple
   - the code is fully JITtable
   - and more such checks
+
+TODO:
+
+  - save jit_info in sub
+  - check for multiple calls to the same sub
+    either reuse code or create new
+  - handle void calls/returns

 =head2 Functions

@@ -332,15 +339,7 @@
 #endif
 }

-
-
-
-
-
-
-
-
-#else
+#else   /* HAS_JIT */

 int
 parrot_pic_is_safe_to_jit(Interp *interpreter, PMC *sub,


fixed typo

fixed typo

--- lang/cem/libcc/stdio/termcap.c
+++ lang/cem/libcc/stdio/termcap.c
@@ -120,7 +120,7 @@
 	while (*q && *q != ':') q++;
 	*q = 0;
 	if (tgetent(buf, terminalname) != 1) {
-		---count;
+		--count;
 		return(0);
 	}
 	--count;


Add PrintASTObject to print the obj contained by AstNode

--- src/astnode.h
+++ src/astnode.h
@@ -229,5 +229,15 @@
   }
 }

+static void PrintASTObject(std::shared_ptr<AstNode> node,
+                         int tab = 0) {
+  while (tab--)
+    printf("  ");
+  if (!node.get() || !node->obj_.get()) {
+    printf("Undefined");
+  }
+  else
+    printf("%s", node->obj_->ToString().c_str());
+}

 #endif // ASTNODE_H_


Update to use new xQueueSendFromISR() and xSemaphoreGiveFromISR() function semantics.

--- Demo/CORTEX_LM3Sxxxx_Eclipse/RTOSDemo/webserver/emac.c
+++ Demo/CORTEX_LM3Sxxxx_Eclipse/RTOSDemo/webserver/emac.c
@@ -197,7 +197,7 @@

 void vEMAC_ISR( void )
 {
-portBASE_TYPE xSwitchRequired = pdFALSE;
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
 unsigned portLONG ulTemp;

 	/* Clear the interrupt. */
@@ -207,13 +207,12 @@
 	/* Was it an Rx interrupt? */
 	if( ulTemp & ETH_INT_RX )
 	{
-		xSwitchRequired = pdTRUE;
-		xSemaphoreGiveFromISR( xMACInterruptSemaphore, pdFALSE );
+		xSemaphoreGiveFromISR( xMACInterruptSemaphore, &xHigherPriorityTaskWoken );
 		EthernetIntDisable( ETH_BASE, ETH_INT_RX );
 	}

     /* Switch to the uIP task. */
-	portEND_SWITCHING_ISR( xSwitchRequired );
+	portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
 }
 /*-----------------------------------------------------------*/


PORT: Avoid undefined shift of negative integer.

--- src/pl-incl.h
+++ src/pl-incl.h
@@ -474,8 +474,8 @@
 #define PLMINTAGGEDINT32	(-(intptr_t)((word)1<<(32-LMASK_BITS-1)))
 #define PLMAXTAGGEDINT32	(-PLMINTAGGEDINT32 - 1)
 #define inTaggedNumRange(n)	(valInt(consInt(n)) == (n))
-#define PLMININT		(((int64_t)-1<<(INT64BITSIZE-1)))
-#define PLMAXINT		(-(PLMININT+1))
+#define PLMININT		(-PLMAXINT - 1)
+#define PLMAXINT		((int64_t)(((uint64_t)1<<(INT64BITSIZE-1)) - 1))
 #if SIZEOF_WCHAR_T == 2
 #define PLMAXWCHAR		(0xffff)
 #else


Fuck.

Fuck.

--- src/popmcmc.c
+++ src/popmcmc.c
@@ -307,7 +307,7 @@
                                   &size)) != 0) {
       free(params);
       free(log_prior);
-      if (error > 0)    // fatal error
+      if (error < 0)    // fatal error
         GMCMC_ERROR("Error evaluating likelihood", error);
       return 0;         // non-fatal error (reject sample)
     }


Change plimage() to support pldifilt() rotation/translation/clipping.
Correct bug that prevented the last row/column of the image matrix to be plotted.

svn path=/trunk/; revision=3422

--- src/plimage.c
+++ src/plimage.c
@@ -52,40 +52,31 @@

 void
 plimageslow(PLFLT *data, PLINT nx, PLINT ny,
-	    PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
-	    PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
+	    PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
 	    PLFLT zmin, PLFLT zmax)
 {

-  PLINT  ix, iy;
-  int    i;
-  PLFLT  dx, dy;
-  PLFLT x[8], y[8];
+  PLINT ix, iy, i;
+  PLFLT x[4], y[4];
   PLFLT xm, ym;
-
-  dx = (xmax - xmin) / (nx - 1);
-  dy = (ymax - ymin) / (ny - 1);

-  for (ix = 0; ix < nx - 1; ix++) {
-    for (iy = 0; iy < ny - 1; iy++) {
+  for (ix = 0; ix < nx ; ix++) {
+    for (iy = 0; iy < ny ; iy++) {

       plcol1((data[ix*ny+iy]-zmin) / (zmax-zmin));

       xm = xmin + ix*dx;
       ym = ymin + iy*dy;

-      if( Dxmin <= xm && Dxmax >= xm && Dymin <= ym && Dymax >= ym) {
-
-	x[0] = x[1] = ix;
-	x[2] = x[3] = ix+1;
-	y[0] = y[3] = iy;
-	y[1] = y[2] = iy+1;
-	for (i = 0; i < 4; i++) {
-	  x[i] = xmin + x[i]*dx - dx*0.5;
-	  y[i] = ymin + y[i]*dy - dy*0.5;
-	}
-	plfill(4, x, y);
+      x[0] = x[1] = ix;
+      x[2] = x[3] = ix+1;
+      y[0] = y[3] = iy;
+      y[1] = y[2] = iy+1;
+      for (i = 0; i < 4; i++) {
+	x[i] = xmin + x[i]*dx;
+	y[i] = ymin + y[i]*dy;
       }
+      plfill(4, x, y);
     }
   }
 }
@@ -108,13 +99,12 @@
  *
  * arguments are
  *   data: array containing image data
- *   nx: dimension on the X axis.
- *   ny: dimension of the Y axis
- *   The array data is indexed like data[ix*ny+iy]
+ *   nx: dimension of the array in the X axis.
+ *   ny: dimension of the  array in the Y axis
+ *   The array data is indexed like data[ix][iy]
  *
  *   xmin, xmax, ymin, ymax:
  *       data[0][0] corresponds to (xmin,ymin)
- *       data[0][ny-1] to (xmin,ymax)
  *       data[nx-1][ny-1] to (xmax,ymax)
  *
  *   Dxmin, Dxmax, Dymin, Dymax:
@@ -128,11 +118,10 @@
 	PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
 	PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
 {
-  PLINT  ix, iy;
-  PLFLT  dx, dy;
-  PLFLT zmin, zmax;
+  PLINT nnx, nny, ix, iy, j;
+  PLFLT dx, dy, xm, ym;
   PLINT *Xf, *Yf;
-  PLFLT *Zf, *data;
+  PLFLT *Zf, *data, zmin, zmax;

   if (plsc->level < 3) {
     plabort("plimage: window must be set up first");
@@ -145,44 +134,58 @@
   }

   plMinMax2dGrid(idata, nx, ny, &zmax, &zmin);
+  dx = (xmax - xmin) / (nx - 1);
+  dy = (ymax - ymin) / (ny - 1);
+  nnx = (Dxmax-Dxmin)/dx + 1;
+  nny = (Dymax-Dymin)/dy + 1;

-  data = (PLFLT *) malloc(ny*nx*sizeof(PLFLT));
+  data = (PLFLT *) malloc(nny*nnx*sizeof(PLFLT));

+  j=0;
   for (ix=0; ix<nx; ix++)
-    for (iy=0; iy<ny; iy++)
-      data[ix*ny+iy] = idata[ix][iy];
+    for (iy=0; iy<ny; iy++) {
+      xm = xmin + ix*dx;
+      ym = ymin + iy*dy;
+      if( Dxmin <= xm && Dxmax >= xm && Dymin <= ym && Dymax >= ym)
+	data[j++] = idata[ix][iy];
+    }
+
+  xmin = Dxmin;  xmax = Dxmax;
+  ymin = Dymin;  ymax = Dymax;
+
+  /* adjust the step for the X/Y arrays */
+  dx = dx*(nx-1)/nx;
+  dy = dy*(ny-1)/ny;

   if( plsc->dev_fastimg == 0) {
-    plimageslow( data, nx,  ny,
-		 xmin, xmax, ymin, ymax,
-		 Dxmin, Dxmax, Dymin, Dymax,
+    plimageslow( data, nnx,  nny,
+		 xmin, ymin, dx, dy,
 		 zmin, zmax);
+    free(data);
     return ;
   }

-  /* compose the array to pass to plP_image */
+  /* compose the arrays to pass to plP_image */

-  Xf = (PLINT *) malloc(ny*nx*sizeof(PLINT));
-  Yf = (PLINT *) malloc(ny*nx*sizeof(PLINT));
-  Zf = (PLFLT *) malloc(ny*nx*sizeof(PLFLT));
-
-  dx = (xmax - xmin) / (nx - 1);
-  dy = (ymax - ymin) / (ny - 1);
-
-  for (ix = 0; ix < nx; ix++) {
-    for (iy = 0; iy < ny; iy++) {
-      Zf[ix*ny+iy] =  (data[ix*ny+iy]-zmin) / (zmax-zmin) ;
-      Xf[ix*ny+iy] =  plP_wcpcx(xmin + ix*dx);
-      Yf[ix*ny+iy] =  plP_wcpcy(ymin + iy*dy);
+  /* the Z array has size (nnx-1)*(nny-1) */
+
+  Zf = (PLFLT *) malloc(nny*nnx*sizeof(PLFLT));
+  for (ix = 0; ix < nnx; ix++)
+    for (iy = 0; iy < nny; iy++)
+      Zf[ix*nny+iy] =  (data[ix*nny+iy]-zmin) / (zmax-zmin) ;
+
+  /* while the X and Y arrays has size nnx*nny */
+  nnx++; nny++;
+  Xf = (PLINT *) malloc(nny*nnx*sizeof(PLINT));
+  Yf = (PLINT *) malloc(nny*nnx*sizeof(PLINT));
+
+  for (ix = 0; ix < nnx; ix++)
+    for (iy = 0; iy < nny; iy++) {
+      Xf[ix*nny+iy] =  plP_wcpcx(xmin + ix*dx);
+      Yf[ix*nny+iy] =  plP_wcpcy(ymin + iy*dy);
     }
-  }

-  plsc->Dxmin = plP_wcpcx(Dxmin);
-  plsc->Dxmax = plP_wcpcx(Dxmax);
-  plsc->Dymin = plP_wcpcy(Dymin);
-  plsc->Dymax = plP_wcpcy(Dymax);
-
-  plP_image(Xf, Yf, Zf, nx, ny);
+  plP_image(Xf, Yf, Zf, nnx, nny);

   free(Xf);
   free(Yf);


Add C11 _Noreturn modifier checking for P_NO_RETURN

--- src/pmacros.h
+++ src/pmacros.h
@@ -475,7 +475,9 @@
  * @def P_NO_RETURN
  * @brief Notifies compiler that function will never return a value (e.g. abort ())
  */
-#if defined(P_CC_MSVC) || (defined(P_CC_BORLAND) && __BORLANDC__ >= 0x0550)
+#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#  define P_NO_RETURN _Noreturn
+#elif defined(P_CC_MSVC) || (defined(P_CC_BORLAND) && __BORLANDC__ >= 0x0550)
 #  define P_NO_RETURN __declspec(noreturn)
 #elif __has_attribute(noreturn) || \
       defined(P_CC_GNU) || \


Resize with relative coordinates by default

Fixes #784.

--- src/pointer.c
+++ src/pointer.c
@@ -282,7 +282,11 @@
 			if (pac == ACTION_MOVE) {
 				move_client(&loc, dx, dy);
 			} else {
-				resize_client(&loc, rh, e->root_x, e->root_y, false);
+				if (honor_size_hints) {
+					resize_client(&loc, rh, e->root_x, e->root_y, false);
+				} else {
+					resize_client(&loc, rh, dx, dy, true);
+				}
 			}
 			last_motion_x = e->root_x;
 			last_motion_y = e->root_y;


canonicalize the root directory

canonicalize the root directory

--- lib/depends.c
+++ lib/depends.c
@@ -196,6 +196,7 @@

 rpmTransactionSet rpmtransCreateSet(rpmdb db, char * root) {
     rpmTransactionSet rpmdep;
+    int rootLength;

     rpmdep = malloc(sizeof(*rpmdep));
     rpmdep->db = db;
@@ -203,6 +204,19 @@
     rpmdep->allocedRemovedPackages = 5;
     rpmdep->removedPackages = malloc(sizeof(int) *
 				     rpmdep->allocedRemovedPackages);
+
+    /* This canonicalizes the root */
+    rootLength = strlen(root);
+    if (root && root[rootLength] == '/') {
+	char * newRootdir;
+
+	newRootdir = alloca(rootLength + 2);
+	strcpy(newRootdir, root);
+	newRootdir[rootLength++] = '/';
+	newRootdir[rootLength] = '\0';
+	root = newRootdir;
+    }
+
     rpmdep->root = strdup(root);

     alCreate(&rpmdep->addedPackages);


Use workspace instead of stack in bcv_svd_update_resid

--- src/bcv-svd.c
+++ src/bcv-svd.c
@@ -362,8 +362,7 @@
      * space has room for at least M doubles.
      */
     bcv_index_t m2 = bcv->x21->m;
-    double work[m2];
-    bcv_vector_t u = { m2, work, 1 };
+    bcv_vector_t u = { m2, bcv->work, 1 };
     _bcv_blas_dgemv (BCV_MATRIX_NOTRANS, 1.0, bcv->x21, &p1, 0.0, &u);

     /* x12 stores Q1^T Q^T x12


Remove code duplication for dict_search().

Use tree_search() in pr_tree_search().

--HG--
extra : rebase_source : 29adcc36c5d0ddf4abf5ad65f070c6cb4416fb51

--- src/pr_tree.c
+++ src/pr_tree.c
@@ -139,20 +139,7 @@
 void*
 pr_tree_search(pr_tree* tree, const void* key)
 {
-    ASSERT(tree != NULL);
-
-    pr_node* node = tree->root;
-    while (node) {
-	int cmp = tree->cmp_func(key, node->key);
-	if (cmp < 0)
-	    node = node->llink;
-	else if (cmp)
-	    node = node->rlink;
-	else
-	    return node->datum;
-    }
-
-    return NULL;
+    return tree_search(tree, key);
 }

 static unsigned


Add white space to COUNT_COMPETING_LOCKS sql.

Pointed out by schmiddy.

--- bin/pg_repack.c
+++ bin/pg_repack.c
@@ -154,8 +154,8 @@

 #define COUNT_COMPETING_LOCKS \
 	"SELECT pid FROM pg_locks WHERE locktype = 'relation'" \
-	"AND granted = false AND relation = %u" \
-	"AND mode = 'AccessExclusiveLock' AND pid <> pg_backend_pid()"
+	" AND granted = false AND relation = %u" \
+	" AND mode = 'AccessExclusiveLock' AND pid <> pg_backend_pid()"

 /* Will be used as a unique prefix for advisory locks. */
 #define REPACK_LOCK_PREFIX_STR "16185446"


Typo.

Typo.

--- src/print/c.c
+++ src/print/c.c
@@ -29,13 +29,13 @@
 	case '\\': return fputs("\\\\", f);
 	case '\'': return fputs("\\\'", f);

-	case '\a': return fputs("\\\a", f);
-	case '\b': return fputs("\\\b", f);
-	case '\f': return fputs("\\\f", f);
-	case '\n': return fputs("\\\n", f);
-	case '\r': return fputs("\\\r", f);
-	case '\t': return fputs("\\\t", f);
-	case '\v': return fputs("\\\v", f);
+	case '\a': return fputs("\\a", f);
+	case '\b': return fputs("\\b", f);
+	case '\f': return fputs("\\f", f);
+	case '\n': return fputs("\\n", f);
+	case '\r': return fputs("\\r", f);
+	case '\t': return fputs("\\t", f);
+	case '\v': return fputs("\\v", f);

 	default:
 		break;
@@ -63,13 +63,13 @@
 	case '\\': return fputs("\\\\", f);
 	case '\"': return fputs("\\\"", f);

-	case '\a': return fputs("\\\a", f);
-	case '\b': return fputs("\\\b", f);
-	case '\f': return fputs("\\\f", f);
-	case '\n': return fputs("\\\n", f);
-	case '\r': return fputs("\\\r", f);
-	case '\t': return fputs("\\\t", f);
-	case '\v': return fputs("\\\v", f);
+	case '\a': return fputs("\\a", f);
+	case '\b': return fputs("\\b", f);
+	case '\f': return fputs("\\f", f);
+	case '\n': return fputs("\\n", f);
+	case '\r': return fputs("\\r", f);
+	case '\t': return fputs("\\t", f);
+	case '\v': return fputs("\\v", f);

 	default:
 		break;