anchor.diff:  `endif
      endrule
   
  -   
  +   rule checkInvariant;
  +      if (lastPassReg != ((gatherCnt+1) == fromInteger(valueOf(gatherSz)))) begin
  +	 $display("last_pass invariant failure: last_pass=%d %d gatherCnt=%d gatherSz=%d",
  +		  lastPassReg, ((gatherCnt+1) == fromInteger(valueOf(gatherSz))), gatherCnt, fromInteger(valueOf(gatherSz)));
  +	 $finish();
  +      end
  +      dynamicAssert(lastPassReg == (gatherCnt+1 == fromInteger(valueOf(gatherSz))), "gatherCnt invariant");
  +   endrule
  +
      (* fire_when_enabled *)
      rule gather if (gather_phase);
         incrementRowReg;
         lastGather <= cycles;
         let row = rowReg;
         let last_row = lastRowReg;
  -      let last_pass = gatherCnt+1 == fromInteger(valueOf(gatherSz));
  +      let last_pass = lastPassReg; // invariant: lastPassReg == (gatherCnt+1 == fromInteger(valueOf(gatherSz));)
         if (verbose)
   	 $display("%08d gather: gather=%d row=%d last_pass=%d last_row=%d, gReg=%d", 
   		  cycles-lastGather, gatherCnt, row, last_pass, last_row, gReg);
         let x <- toGet(adder_buffer).get;
         if (!last_pass) begin
   	 if (last_row) begin
  -	    if (gReg) gatherCnt <= gatherCnt+1;
  +	    if (gReg) begin
  +	       gatherCnt <= gatherCnt+1;
  +	       lastPassReg <= ((gatherCnt+2) == fromInteger(valueOf(gatherSz)));
  +	    end
   	    gReg <= !gReg;
   	 end
   	 if(gReg) begin
  
positive.code: `endif      
  	 if (last_row) begin
  	    gatherCnt <= 0;
  	    lastCnt <= 0;
  	    firstCnt <= 0;
  	    gather_phase <= False;
  
negative.code:    Reg#(Bit#(16))gatherCnt <- mkReg(0);
     Reg#(Bool) gather_phase <- mkReg(False);
     //invariant: gather_phase = lastCnt == fromInteger(kk);
     Reg#(Bool) lastPassReg <- mkReg((0+1) == fromInteger(valueOf(gatherSz)));
  
     FIFOF#(Tuple2#(Bool,Bool))    flFifo <- mkSizedFIFOF(ub_MulLat);
     Vector#(k,FIFOF#(MmToken))    dotfifos <- replicateM(mkFIFOF1);
  