anchor.diff:   end;
   end;
   
  -constructor TFLREThreadLocalStorageInstance.Create(AInstance:TFLRE);
  -var Index,SubIndex:longint;
  -    FLREDFAStateCreateTempDFAState:TFLREDFAState;
  -    DFAState:PFLREDFAState;
  +constructor TFLREParallelNFA.Create(const AThreadLocalStorageInstance:TFLREThreadLocalStorageInstance);
  +var Index:longint;
   begin
    inherited Create;
   
  - AllNext:=nil;
  - FreeNext:=nil;
  -
  - Instance:=AInstance;
  -
  - Input:=nil;
  - InputLength:=0;
  -
  - SearchLongest:=rfLONGEST in Instance.Flags;
  - ManyMatch:=false;
  -
  - ParallelNFAGeneration:=0;
  -
  - ParallelNFAInstructionGenerations:=nil;
  - SetLength(ParallelNFAInstructionGenerations,AInstance.CountForwardInstructions);
  - for Index:=0 to length(ParallelNFAInstructionGenerations)-1 do begin
  -  ParallelNFAInstructionGenerations[Index]:=-1;
  + ThreadLocalStorageInstance:=AThreadLocalStorageInstance;
  +
  + Instance:=ThreadLocalStorageInstance.Instance;
  +
  + SearchLongest:=ThreadLocalStorageInstance.SearchLongest;
  +
  + Generation:=0;
  +
  + InstructionGenerations:=nil;
  + SetLength(InstructionGenerations,Instance.CountForwardInstructions);
  + for Index:=0 to length(InstructionGenerations)-1 do begin
  +  InstructionGenerations[Index]:=-1;
    end;
   
    ParallelNFAThreadLists[0].Threads:=nil;
    ParallelNFAThreadLists[1].Threads:=nil;
  - SetLength(ParallelNFAThreadLists[0].Threads,AInstance.CountForwardInstructions*2);
  - SetLength(ParallelNFAThreadLists[1].Threads,AInstance.CountForwardInstructions*2);
  + SetLength(ParallelNFAThreadLists[0].Threads,Instance.CountForwardInstructions*2);
  + SetLength(ParallelNFAThreadLists[1].Threads,Instance.CountForwardInstructions*2);
   
    ParallelNFAStack:=nil;
  - SetLength(ParallelNFAStack,AInstance.CountForwardInstructions*2);
  -
  - FreeParallelNFAStates:=nil;
  - AllParallelNFAStates:=TList.Create;
  -
  - OnePassNFAWorkSubMatches:=nil;
  - OnePassNFAMatchSubMatches:=nil;
  -
  - if Instance.OnePassNFAReady then begin
  -  SetLength(OnePassNFAWorkSubMatches,Instance.CountSubMatches);
  -  SetLength(OnePassNFAMatchSubMatches,Instance.CountSubMatches);
  - end;
  -
  - BitStateNFACountVisited:=0;
  - BitStateNFAJobs:=nil;
  - BitStateNFACountJobs:=0;
  - BitStateNFAMaxJob:=0;
  - BitStateNFAWorkSubMatches:=nil;
  - BitStateNFAMatchSubMatches:=nil;
  -
  - if Instance.BitStateNFAReady then begin
  -  SetLength(BitStateNFAWorkSubMatches,Instance.CountSubMatches);
  -  SetLength(BitStateNFAMatchSubMatches,Instance.CountSubMatches);
  - end;
  -
  - DFAStackInstructions:=nil;
  - DFAStateCache:=TFLREDFAStateHashMap.Create;
  - DFANextStatesSize:=0;
  - DFAStateSize:=0;
  - DFAStatePoolUsed:=nil;
  - DFAStatePoolFree:=nil;
  - DFAStatePoolSize:=0;
  - DFAStatePoolSizePowerOfTwo:=0;
  - FillChar(DFAStates,SizeOf(DFAStates),AnsiChar(#0));
  -
  - begin
  -  DFACountStatesCached:=0;
  -
  -  DFAStackInstructions:=nil;
  -  SetLength(DFAStackInstructions,Max(AInstance.CountForwardInstructions,AInstance.CountBackwardInstructions) shl 1);
  -
  -  DFAStatePoolUsed:=nil;
  -  DFAStatePoolFree:=nil;
  -
  -  DFANextStatesSize:=AInstance.ByteMapCount*sizeof(PFLREDFAState);
  -  DFAStateSize:=ptrint(ptruint(pointer(@FLREDFAStateCreateTempDFAState.NextStates))-ptruint(pointer(@FLREDFAStateCreateTempDFAState)))+DFANextStatesSize;
  -
  -  DFAStatePoolSize:=(65536 div DFAStateSize)*DFAStateSize;
  -  if DFAStatePoolSize=0 then begin
  -   DFAStatePoolSize:=DFAStateSize*64;
  -  end;
  -
  -  DFAStatePoolSizePowerOfTwo:=RoundUpToPowerOfTwo(DFAStatePoolSize);
  -
  -  DFAAllocateNewStatePool;
  -
  -  FillChar(DFATemporaryState,SizeOf(TFLREDFAState),AnsiChar(#0));
  -  FillChar(DFANewState,SizeOf(TFLREDFAState),AnsiChar(#0));
  -
  -  DFAInstructionGenerations:=nil;
  -  SetLength(DFAInstructionGenerations,Max(AInstance.CountForwardInstructions,AInstance.CountBackwardInstructions));
  -  for Index:=0 to length(DFAInstructionGenerations)-1 do begin
  -   DFAInstructionGenerations[Index]:=-1;
  -  end;
  -
  -  if Instance.DFAFast then begin
  -
  -   inc(DFAGeneration);
  -   GetMem(DFAState,DFAStateSize);
  -   FillChar(DFAState^,DFAStateSize,AnsiChar(#0));
  -   DFAFastAddInstructionThread(DFAState,Instance.AnchoredStartInstruction);
  -   DFAState^.Flags:=DFAState^.Flags or sfDFAStart;
  -   DFAStateCache.Add(DFAState);
  -   inc(DFACountStatesCached);
  -   DFAStates[skFast+skAnchored]:=DFAState;
  -
  -   inc(DFAGeneration);
  -   GetMem(DFAState,DFAStateSize);
  -   FillChar(DFAState^,DFAStateSize,AnsiChar(#0));
  -   DFAFastAddInstructionThread(DFAState,Instance.UnanchoredStartInstruction);
  -   DFAState^.Flags:=DFAState^.Flags or sfDFAStart;
  -   DFAStateCache.Add(DFAState);
  -   inc(DFACountStatesCached);
  -   DFAStates[skFast+skUnanchored]:=DFAState;
  -
  -   inc(DFAGeneration);
  -   GetMem(DFAState,DFAStateSize);
  -   FillChar(DFAState^,DFAStateSize,AnsiChar(#0));
  -   DFAFastAddInstructionThread(DFAState,Instance.ReversedStartInstruction);
  -   DFAState^.Flags:=DFAState^.Flags or sfDFAStart;
  -   DFAStateCache.Add(DFAState);
  -   inc(DFACountStatesCached);
  -   DFAStates[skFast+skReversed]:=DFAState;
  -
  -  end;
  -
  -  inc(DFAGeneration);
  -  GetMem(DFAState,DFAStateSize);
  -  FillChar(DFAState^,DFAStateSize,AnsiChar(#0));
  -  DFAFastAddInstructionThread(DFAState,Instance.AnchoredStartInstruction);
  -  DFAState^.Flags:=DFAState^.Flags or sfDFADead;
  -  DFAStateCache.Add(DFAState);
  -  inc(DFACountStatesCached);
  -  DFAStates[skDead]:=DFAState;
  -
  - end;
  -
  -end;
  -
  -destructor TFLREThreadLocalStorageInstance.Destroy;
  -var Index,SubIndex:longint;
  -    State:PFLREParallelNFAState;
  -begin
  -
  - while assigned(FreeParallelNFAStates) do begin
  -  State:=FreeParallelNFAStates;
  -  FreeParallelNFAStates:=FreeParallelNFAStates^.Next;
  + SetLength(ParallelNFAStack,Instance.CountForwardInstructions*2);
  +
  + FreeStates:=nil;
  + AllStates:=TList.Create;
  +
  +end;
  +
  +destructor TFLREParallelNFA.Destroy;
  +var State:PFLREParallelNFAState;
  +begin
  +
  + while assigned(FreeStates) do begin
  +  State:=FreeStates;
  +  FreeStates:=FreeStates^.Next;
     SetLength(State^.SubMatches,0);
     Finalize(State^);
     FreeMem(State);
    end;
  - FreeParallelNFAStates:=nil;
  -
  - FreeAndNil(AllParallelNFAStates);
  -
  - SetLength(OnePassNFAWorkSubMatches,0);
  - SetLength(OnePassNFAMatchSubMatches,0);
  -
  - SetLength(BitStateNFAJobs,0);
  - SetLength(BitStateNFAWorkSubMatches,0);
  - SetLength(BitStateNFAMatchSubMatches,0);
  -
  - DFADestroyStatePool(DFAStatePoolUsed);
  - DFADestroyStatePool(DFAStatePoolFree);
  - DFAStatePoolUsed:=nil;
  - DFAStatePoolFree:=nil;
  - DFAFreeState(@DFATemporaryState);
  - DFAFreeState(@DFANewState);
  - for Index:=0 to length(DFAStates)-1 do begin
  -  if assigned(DFAStates[Index]) then begin
  -   DFAFreeState(DFAStates[Index]);
  -   FreeMem(DFAStates[Index]);
  -  end;
  - end;
  - FreeAndNil(DFAStateCache);
  - SetLength(DFAStackInstructions,0);
  - SetLength(DFAInstructionGenerations,0);
  -
  - SetLength(ParallelNFAInstructionGenerations,0);
  + FreeStates:=nil;
  +
  + FreeAndNil(AllStates);
  +
  + SetLength(InstructionGenerations,0);
   
    SetLength(ParallelNFAThreadLists[0].Threads,0);
    SetLength(ParallelNFAThreadLists[1].Threads,0);
  
positive.code:        SearchLongest:longbool;
         ManyMatch:longbool;
  
         ParallelNFAThreadLists:TFLREParallelNFAThreadLists;
  
         ParallelNFAStack:TFLREParallelNFAStack;
  
         ParallelNFAGeneration:int64;
         ParallelNFAInstructionGenerations:TFLREInstructionGenerations;
  
         FreeParallelNFAStates:PFLREParallelNFAState;
         AllParallelNFAStates:TList;
  
         ParallelNFASatisfyFlags:longword;
  
         OnePassNFAWorkSubMatches:TFLREOnePassNFASubMatches;
         OnePassNFAMatchSubMatches:TFLREOnePassNFASubMatches;
  
negative.code:  inherited Destroy;
  end;
  
  function TFLREParallelNFA.StateAllocate(const Count:longint;const SubMatchesBitmap:longword):PFLREParallelNFAState; {$ifdef caninline}inline;{$endif}
  begin
   if assigned(FreeStates) then begin
    result:=FreeStates;
    FreeStates:=result^.Next;
   end else begin
    GetMem(result,SizeOf(TFLREParallelNFAState));
    FillChar(result^,SizeOf(TFLREParallelNFAState),#0);
    SetLength(result^.SubMatches,Instance.CountSubMatches);
    AllStates.Add(result);
   end;
   result^.ReferenceCounter:=1;
   result^.Count:=Count;
   result^.SubMatchesBitmap:=SubMatchesBitmap;
  end;
  
  function TFLREParallelNFA.StateAcquire(const State:PFLREParallelNFAState):PFLREParallelNFAState; {$ifdef caninline}inline;{$endif}
  begin
   inc(State^.ReferenceCounter);
   result:=State;
  end;
  
  procedure TFLREParallelNFA.StateRelease(const State:PFLREParallelNFAState); {$ifdef caninline}inline;{$endif}
  begin
   dec(State^.ReferenceCounter);
   if State^.ReferenceCounter=0 then begin
    State^.Next:=FreeStates;
    FreeStates:=State;
   end;
  end;
  
  function TFLREParallelNFA.StateUpdate(const State:PFLREParallelNFAState;const Index,Position:longint):PFLREParallelNFAState; {$ifdef caninline}inline;{$endif}
  var Counter:longint;
      SubMatchesBitmap:longword;
  begin
   result:=State;
   if result^.ReferenceCounter>1 then begin
    result:=StateAllocate(State^.Count,State^.SubMatchesBitmap);
  {$ifdef cpu386}
    asm
     push ebx
  