Esempio n. 1
0
static void icp_reset_handler(void *dev)
{
    ICPState *icp = ICP(dev);

    icp->xirr = 0;
    icp->pending_priority = 0xff;
    icp->mfrr = 0xff;

    /* Make all outputs are deasserted */
    qemu_set_irq(icp->output, 0);

    if (kvm_irqchip_in_kernel()) {
        icp_set_kvm_state(ICP(dev));
    }
}
Esempio n. 2
0
static void icp_unrealize(DeviceState *dev, Error **errp)
{
    ICPState *icp = ICP(dev);

    vmstate_unregister(NULL, &vmstate_icp_server, icp);
    qemu_unregister_reset(icp_reset_handler, dev);
}
Esempio n. 3
0
static target_ulong h_xirr(PowerPCCPU *cpu, sPAPRMachineState *spapr,
                           target_ulong opcode, target_ulong *args)
{
    uint32_t xirr = icp_accept(ICP(cpu->intc));

    args[0] = xirr;
    return H_SUCCESS;
}
Esempio n. 4
0
static target_ulong h_cppr(PowerPCCPU *cpu, sPAPRMachineState *spapr,
                           target_ulong opcode, target_ulong *args)
{
    target_ulong cppr = args[0];

    icp_set_cppr(ICP(cpu->intc), cppr);
    return H_SUCCESS;
}
Esempio n. 5
0
static target_ulong h_eoi(PowerPCCPU *cpu, sPAPRMachineState *spapr,
                          target_ulong opcode, target_ulong *args)
{
    target_ulong xirr = args[0];

    icp_eoi(ICP(cpu->intc), xirr);
    return H_SUCCESS;
}
Esempio n. 6
0
static void icp_realize(DeviceState *dev, Error **errp)
{
    ICPState *icp = ICP(dev);
    PowerPCCPU *cpu;
    CPUPPCState *env;
    Object *obj;
    Error *err = NULL;

    obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err);
    if (!obj) {
        error_propagate_prepend(errp, err,
                                "required link '" ICP_PROP_XICS
                                "' not found: ");
        return;
    }

    icp->xics = XICS_FABRIC(obj);

    obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err);
    if (!obj) {
        error_propagate_prepend(errp, err,
                                "required link '" ICP_PROP_CPU
                                "' not found: ");
        return;
    }

    cpu = POWERPC_CPU(obj);
    icp->cs = CPU(obj);

    env = &cpu->env;
    switch (PPC_INPUT(env)) {
    case PPC_FLAGS_INPUT_POWER7:
        icp->output = env->irq_inputs[POWER7_INPUT_INT];
        break;
    case PPC_FLAGS_INPUT_POWER9: /* For SPAPR xics emulation */
        icp->output = env->irq_inputs[POWER9_INPUT_INT];
        break;

    case PPC_FLAGS_INPUT_970:
        icp->output = env->irq_inputs[PPC970_INPUT_INT];
        break;

    default:
        error_setg(errp, "XICS interrupt controller does not support this CPU bus model");
        return;
    }

    if (kvm_irqchip_in_kernel()) {
        icp_kvm_realize(dev, &err);
        if (err) {
            error_propagate(errp, err);
            return;
        }
    }

    qemu_register_reset(icp_reset_handler, dev);
    vmstate_register(NULL, icp->cs->cpu_index, &vmstate_icp_server, icp);
}
Esempio n. 7
0
File: spapr_irq.c Progetto: aik/qemu
static int spapr_irq_post_load_xics(sPAPRMachineState *spapr, int version_id)
{
    if (!object_dynamic_cast(OBJECT(spapr->ics), TYPE_ICS_KVM)) {
        CPUState *cs;
        CPU_FOREACH(cs) {
            PowerPCCPU *cpu = POWERPC_CPU(cs);
            icp_resend(ICP(cpu->intc));
        }
    }
inline bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<Alloc,Term,MaxTermDepth,MaxTermSize,MaxNumOfVariables>::compileQuery(const TermId& query)
{
 CALL("compileQuery(const TermId& query)");
 _queryTraversal.reset(query);
 _pathRelationRetrieval.reset(_trie);
 _intermediateQueryRepresentation.reset();
 ulong arity;
 check_state: 
  switch (_queryTraversal.state())
   {
    case TermTraversal::Func:
     arity = _queryTraversal.symbol().arity();
     if (arity) 
      {
       if (!_pathRelationRetrieval.nonconstFunc(_queryTraversal.symbol())) return false;
       _intermediateQueryRepresentation.compound(_queryTraversal.term(),arity,_pathRelationRetrieval.indObjAddr());
      }
     else // constant 
      {     
       if (!_pathRelationRetrieval.constant(_queryTraversal.symbol())) return false;
       _intermediateQueryRepresentation.constant(_queryTraversal.term(),_pathRelationRetrieval.constIndObjAddr());
      };
     _queryTraversal.next(); 
     goto check_state;

    case TermTraversal::Var:
     _intermediateQueryRepresentation.variable(_queryTraversal.symbol().var());
     _pathRelationRetrieval.after();
     _queryTraversal.next(); 
     goto check_state;

    case TermTraversal::End: 
     _intermediateQueryRepresentation.endOfQuery();
     _intermediateQueryRepresentation.generateCode();
     #ifdef INSTANCE_RETRIEVAL_INDEX_USE_WEIGHT_FILTERS
      _abstractMachine.queryWeight = Term::weight(query);
     #endif
     #ifdef INSTANCE_RETRIEVAL_INDEX_USE_SIGNATURE_FILTERS
      _abstractMachine.querySignatureFilter = Term::signatureFilter(query);
     #endif
     return true;

    #ifdef DEBUG_NAMESPACE 
     default: ICP("ICP0"); return false;
    #else
     #ifdef _SUPPRESS_WARNINGS_
      default: 
       BK::RuntimeError::report("Wrong term traversal state in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::compileQuery(..)");
       return false;
     #endif
    #endif    
  };
 
} // bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::compileQuery(const TermId& query)
Esempio n. 9
0
static void icp_reset(DeviceState *dev)
{
    ICPState *icp = ICP(dev);

    icp->xirr = 0;
    icp->pending_priority = 0xff;
    icp->mfrr = 0xff;

    /* Make all outputs are deasserted */
    qemu_set_irq(icp->output, 0);
}
Esempio n. 10
0
static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPRMachineState *spapr,
                            target_ulong opcode, target_ulong *args)
{
    uint32_t mfrr;
    uint32_t xirr = icp_ipoll(ICP(cpu->intc), &mfrr);

    args[0] = xirr;
    args[1] = mfrr;

    return H_SUCCESS;
}
Esempio n. 11
0
File: spapr_irq.c Progetto: aik/qemu
static void spapr_irq_print_info_xics(sPAPRMachineState *spapr, Monitor *mon)
{
    CPUState *cs;

    CPU_FOREACH(cs) {
        PowerPCCPU *cpu = POWERPC_CPU(cs);

        icp_pic_print_info(ICP(cpu->intc), mon);
    }

    ics_pic_print_info(spapr->ics, mon);
}
Esempio n. 12
0
inline Comparison inverse(const Comparison& cmp)
{
 CALL("(global) inverse(const Comparison& cmp)");
 switch (cmp)
  {
   case Less: return Greater;
   case Equal: return Equal;
   case Greater: return Less;
   case Incomparable: return Incomparable;  
   #ifdef DEBUG_NAMESPACE
    default: ICP("ICP0"); return Incomparable; 
   #elif defined _SUPPRESS_WARNINGS_
    default: return Incomparable; 
   #endif              
  };
 #ifdef DEBUG_NAMESPACE
  ICP("ICP1"); 
  return Incomparable;
 #elif defined _SUPPRESS_WARNINGS_
  return Incomparable; 
 #endif    
}; 
Esempio n. 13
0
static void icp_realize(DeviceState *dev, Error **errp)
{
    ICPState *icp = ICP(dev);
    Object *obj;
    Error *err = NULL;

    obj = object_property_get_link(OBJECT(dev), "xics", &err);
    if (!obj) {
        error_setg(errp, "%s: required link 'xics' not found: %s",
                   __func__, error_get_pretty(err));
        return;
    }

    icp->xics = XICS_FABRIC(obj);

    qemu_register_reset(icp_reset, dev);
}
inline bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<Alloc,Term,MaxTermDepth,MaxTermSize,MaxNumOfVariables>::integrate(const TermId& integratedTermId)
{
 CALL("integrate(const TermId& integratedTermId)");
 _integratedTermTraversal.reset(integratedTermId);
 _integrator.reset(_trie);
 ulong arity;
 check_state:
  switch (_integratedTermTraversal.state())
   { 
    case TermTraversal::Func:
     arity = _integratedTermTraversal.symbol().arity();
     if (arity)
      {
       _integrator.nonconstFunc(_integratedTermTraversal.symbol());
       if (!_integrator.indexedObj().insert(integratedTermId)) return false;      
      }
     else // constant
      {
       _integrator.constant(_integratedTermTraversal.symbol());
       if (!_integrator.constIndObj().insert(integratedTermId)) return false;
      };
     _integratedTermTraversal.next();
     goto check_state;
 
    case TermTraversal::Var:
     _integrator.variable();
     _integratedTermTraversal.next();
     goto check_state;
     
    case TermTraversal::End: 
     return true; 

    #ifdef DEBUG_NAMESPACE 
     default: ICP("ICP0"); return false;
    #else
     #ifdef _SUPPRESS_WARNINGS_
      default: 
       BK::RuntimeError::report("Wrong term traversal state in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::integrate(..)");
       return false;
     #endif
    #endif       
   };
} // bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::integrate(const TermId& integratedTermId)
Esempio n. 15
0
inline FunctionComparison inverse(const FunctionComparison& cmp)
{
  CALL("(global) inverse(const FunctionComparison& cmp)");
  switch (cmp)
    {
    case FailureToCompare: return FailureToCompare;
    case AlwaysLess: return AlwaysGreater;
    case AlwaysEqual: return AlwaysEqual;
    case AlwaysGreater: return AlwaysLess;
    case CanBeLessOrEqual: return CanBeGreaterOrEqual;
    case CanBeGreaterOrEqual: return CanBeLessOrEqual;
    case VolatileButNearlyAlwaysLess: return VolatileButNearlyAlwaysGreater;
    case VolatileButNearlyAlwaysGreater: return VolatileButNearlyAlwaysLess;
    case AbsolutelyVolatile: return AbsolutelyVolatile;
    };
  ICP("ICP0");
#if (defined _SUPPRESS_WARNINGS_) || (defined DEBUG_NAMESPACE)
  return FailureToCompare;
#endif 

}; // FunctionComparison inverse(const FunctionComparison& cmp)
Esempio n. 16
0
inline bool strict(const FunctionComparison& cmp)
{
  CALL("(global) strict(const FunctionComparison& cmp)");
  switch (cmp)
    {
    case FailureToCompare: 
    case AlwaysLess:
    case AlwaysEqual:
    case AlwaysGreater:
      return true;
    case CanBeLessOrEqual:
    case CanBeGreaterOrEqual:
    case VolatileButNearlyAlwaysLess:
    case VolatileButNearlyAlwaysGreater:
    case AbsolutelyVolatile:
      return false;
    };
  ICP("ICP0");
#if (defined _SUPPRESS_WARNINGS_) || (defined DEBUG_NAMESPACE)
  return false;
#endif
}; // bool strict(const FunctionComparison& cmp)
static int mrvl_usb_phy_28nm_init(u32 base)
{
	struct usb_file *file = (struct usb_file *)(uintptr_t)base;
	u32 tmp32;
	int ret;

	/*
	 * pll control 0:
	 * 0xd420_7000[6:0] = 0xd, b'000_1101	  --->  REFDIV
	 * 0xd420_7000[24:16] = 0xf0, b'1111_0000 --->  FBDIV
	 * 0xd420_7000[11:8] = 0x3, b'0011        --->  ICP
	 * 0xd420_7000[29:28] = 0x1,  b'01	  --->  SEL_LPFR
	 */
	tmp32 = readl(&file->pll_reg0);
	tmp32 &= ~(REFDIV_MASK | FB_DIV_MASK | ICP_MASK | SEL_LPFR_MASK);
	tmp32 |= REFDIV(0xd) | FB_DIV(0xf0) | ICP(0x3) | SEL_LPFR(0x1);
	writel(tmp32, &file->pll_reg0); /*
	 * pll control 1:
	 * 0xd420_7004[1:0] = 0x3, b'11	   ---> [PU_PLL_BY_REG:PU_PLL]
	 */
	tmp32 = readl(&file->pll_reg1);
	tmp32 &= ~(PLL_PU_MASK | PU_BY_MASK);
	tmp32 |= PLL_PU(0x1) | PU_BY(0x1);
	writel(tmp32, &file->pll_reg1);
	/*
	 * tx reg 0:
	 * 0xd420_700c[22:20] = 0x3, b'11  ---> AMP
	 */
	tmp32 = readl(&file->tx_reg0);
	tmp32 &= ~(AMP_MASK);
	tmp32 |= AMP(0x3);
	writel(tmp32, &file->tx_reg0);
	/*
	 * rx reg 0:
	 * 0xd420_7018[3:0] = 0xa, b'1010 ---> SQ_THRESH
	 */
	tmp32 = readl(&file->rx_reg0);
	tmp32 &= ~(SQ_THRESH_MASK);
	tmp32 |= SQ_THRESH(0xa);
	writel(tmp32, &file->rx_reg0);
	/*
	 * dig reg 0:
	 * 0xd420_701c[31] = 0, b'0 ---> BITSTAFFING_ERROR
	 * 0xd420_701c[30] = 0, b'0 ---> LOSS_OF_SYNC_ERROR
	 * 0xd420_701c[18:16] = 0x7, b'111 ---> SQ_FILT
	 * 0xd420_701c[14:12] = 0x4, b'100 ---> SQ_BLK
	 * 0xd420_701c[1:0] = 0x2, b'10 ---> SYNC_NUM
	 */
	tmp32 = readl(&file->dig_reg0);
	tmp32 &= ~(BITSTAFFING_ERR_MASK | SYNC_ERR_MASK | SQ_FILT_MASK | SQ_BLK_MASK | SYNC_NUM_MASK);
	tmp32 |= (SQ_FILT(0x0) | SQ_BLK(0x0) | SYNC_NUM(0x1));
	writel(tmp32, &file->dig_reg0);

	/*
	 * otg reg:
	 * 0xd420_7034[5:4] = 0x1,  b'01   ---> [OTG_CONTROL_BY_PIN:PU_OTG]
	 */
	tmp32 = readl(&file->otg_reg);
	tmp32 &= ~(OTG_CTRL_BY_MASK | PU_OTG_MASK);
	tmp32 |= OTG_CTRL_BY(0x0) | PU_OTG(0x1);
	writel(tmp32, &file->otg_reg);
	/*
	 * tx reg 0:
	 * 0xd420_700c[25:24] = 0x3, b'11  --->  [PU_ANA:PU_BY_REG]
	 */
	tmp32 = readl(&file->tx_reg0);
	tmp32 &= ~(ANA_PU_MASK | TX_PU_BY_MASK);
	tmp32 |= ANA_PU(0x1) | TX_PU_BY(0x1);
	writel(tmp32, &file->tx_reg0);

	udelay(400);
	ret = wait_for_phy_ready(file);
	if (ret < 0) {
		printf("initialize usb phy failed, dump usb registers:\n");
		dump_phy_regs(base);
	}

	printf("usb phy inited 0x%x!\n", readl(&file->usb_ctrl0));
	return 0;
}
inline void StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<Alloc,Term,MaxTermDepth,MaxTermSize,MaxNumOfVariables>::IntermediateQueryRepresentation::generateCode()
{
 CALL("generateCode()");

 ulong primaryCodeSize = _primaryNestSorting.size();
 AbstractMachine::Instruction* nextSecondaryInstr = _abstractMachine->code + primaryCodeSize;
 AbstractMachine::Instruction* primaryInstr;
 Position* pos;
 Position* argsCache = (Position*)0;
 NonmaxPathRelation::SurferWithMemory* nextNonmaxPathRelationSurfer; 
 MaxPathRelation::SurferWithMemory* nextMaxPathRelationSurfer;
 
 for (pos = _positions + 1; pos->tag != End; pos++)
  { 
   switch (pos->tag)
    { 
     case Compound:      

      // contribute to the primary code 
      if (pos->numOfVarArgs)
       {
	if (!pos->hasNonvarArg) // primary 
	 {    
          nextNonmaxPathRelationSurfer = _abstractMachine->nonmaxPathRelationSurfers + (pos - _positions);
          nextNonmaxPathRelationSurfer->reset(*(pos->nonmaxPathRelation));  
	  primaryInstr = _abstractMachine->code + (*(pos->numInSorting));
          primaryInstr->tag = AbstractMachine::NonmaxEqualiseTermId;
          primaryInstr->nonmaxPathRelationSurfer = nextNonmaxPathRelationSurfer;
         };
       }; 

      // contribute to the secondary code
      if (!pos->ground)
       {
	if (pos->nestPosition == _positions)
	 {
	  // load from termId
	  if (pos->numOfComplexNongroundArgs > 1) 
	   {
	    nextSecondaryInstr->tag = AbstractMachine::ArgsInitAndStore;
            nextSecondaryInstr->storedArguments = _abstractMachine->arguments + (pos - _positions); 
           }
          else
	   {
            nextSecondaryInstr->tag = AbstractMachine::ArgsInit;
           };
         }
        else // get arguments from cache or stored arguments
	 {
	  if (pos->nestPosition == argsCache)
	   {
	    // use cache
	    if (pos->numOfComplexNongroundArgs > 1) 
	     {
	      nextSecondaryInstr->tag = AbstractMachine::ArgsMoveAndStore;
              nextSecondaryInstr->storedArguments = _abstractMachine->arguments + (pos - _positions);
             }
            else
	     {
              nextSecondaryInstr->tag = AbstractMachine::ArgsMove;
             };          
            nextSecondaryInstr->argNum = pos->argNum; 
           }
          else // fetch stored arguments
	   { 
            if (pos->numOfComplexNongroundArgs > 1) 
	     {
              nextSecondaryInstr->tag = AbstractMachine::ArgsFetchAndStore; 
              nextSecondaryInstr->storedArguments = _abstractMachine->arguments + (pos - _positions);
             }
            else
	     {
              nextSecondaryInstr->tag = AbstractMachine::ArgsFetch; 
             };           
            nextSecondaryInstr->argumentsToFetch =  _abstractMachine->arguments + (pos->nestPosition - _positions);
            nextSecondaryInstr->argNum = pos->argNum;
           };
         };
 
        argsCache = pos;
        nextSecondaryInstr++;

        // compile variable arguments
        for (Position* varArg = pos->nextVarArg; varArg; varArg = varArg->nextVarArg)
	 { 
	  if (_substLoaded[varArg->variable])
	   {
	    nextSecondaryInstr->tag = AbstractMachine::ArgsCompare;
           }
          else
	   {
	    nextSecondaryInstr->tag = AbstractMachine::ArgsLoadSubst;
	    _substLoaded[varArg->variable] = true;
           };
          nextSecondaryInstr->argNum = varArg->argNum; 
          nextSecondaryInstr->subst = _abstractMachine->substitution + varArg->variable; 
          nextSecondaryInstr++;
         };
       };
      break;

     case Constant: 
      primaryInstr = _abstractMachine->code + (*(pos->numInSorting));
      primaryInstr->tag = AbstractMachine::MaxEqualiseTermId;
      nextMaxPathRelationSurfer = _abstractMachine->maxPathRelationSurfers + (pos - _positions);
      nextMaxPathRelationSurfer->reset(*(pos->maxPathRelation));
      primaryInstr->maxPathRelationSurfer = nextMaxPathRelationSurfer;
      break;

     case Variable:  
      break;

     #ifdef DEBUG_NAMESPACE 
      default: ICP("ICP0"); return;
     #else
      #ifdef _SUPPRESS_WARNINGS_
       default: 
        BK::RuntimeError::report("Wrong tag in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::IntermediateQueryRepresentation::generateCode()"); 
        return;
      #endif   
     #endif
    };
  };
 
 ASSERT(pos->tag == End);
 nextSecondaryInstr->tag = AbstractMachine::Success;
 _abstractMachine->firstRetrievalCall = true;

 //DF; _abstractMachine->outputCode(cout << "\n\n") << "\n";  

} // void StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::IntermediateQueryRepresentation::generateCode()
inline bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<Alloc,Term,MaxTermDepth,MaxTermSize,MaxNumOfVariables>::AbstractMachine::nextMatch(TermId& matchId)
{
 CALL("nextMatch(TermId& matchId)");

 Instruction* instr = code;
 TermId termId;
 TermArguments cachedArguments;

 // Initialise termId

 //DF; instr->output(cout << "IN ",code,substitution) << "\n"; 

 switch (instr->tag) 
  { 
   case NonmaxEqualiseTermId:

     //DF; cout << "InitId PrimVar " << firstRetrievalCall << "\n";

    if (firstRetrievalCall) 
     {
      firstRetrievalCall = false;
     }
    else  
     {
      if (!instr->nonmaxPathRelationSurfer->next()) return false;
     };
    ASSERT_IN(instr->nonmaxPathRelationSurfer->currNode(),"A100");  
    termId = instr->nonmaxPathRelationSurfer->currNode()->key();

    #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS
    

     while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
      {
       if (!instr->nonmaxPathRelationSurfer->next()) return false;
       termId = instr->nonmaxPathRelationSurfer->currNode()->key();
      };
    #endif
    break;    

   case MaxEqualiseTermId:

     //DF; cout << "InitId PrimConst " << firstRetrievalCall << "\n";

    if (firstRetrievalCall) 
     {
      firstRetrievalCall = false;
     }
    else  
     {
      if (!instr->maxPathRelationSurfer->next()) return false;
     };
    ASSERT(instr->maxPathRelationSurfer->currNode());
    termId = instr->maxPathRelationSurfer->currNode()->key();
    #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS

     while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
      {
       if (!instr->maxPathRelationSurfer->next()) return false;
       termId = instr->maxPathRelationSurfer->currNode()->key();
      };
    #endif
    break;

   #ifdef DEBUG_NAMESPACE 
    default: ICP("ICP0"); return false; 
   #else
    #ifdef _SUPPRESS_WARNINGS_
     default: 
      BK::RuntimeError::report("Wrong tag in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::AbstractMachine::nextMatch(TermId& matchId)"); 
      return false;
    #endif   
   #endif
  };
 
 next_instr:
  instr++;
  perform_instr:

  //DF; instr->output(cout << "FW ",code,substitution) << "\n"; 

   switch (instr->tag)
    {
     case Success:
      matchId = termId;     
      
      //DF; cout << "Success\n";

      return true;

     case NonmaxEqualiseTermId:
       
       //DF; cout << "Forward PrimVar\n";

      if (instr->nonmaxPathRelationSurfer->find(termId)) goto next_instr; 
      if (instr->nonmaxPathRelationSurfer->currNode())
       {
	termId = instr->nonmaxPathRelationSurfer->currNode()->key();
      
        #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS

        while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
         {
          if (!instr->nonmaxPathRelationSurfer->next()) return false;
          termId = instr->nonmaxPathRelationSurfer->currNode()->key();
         };
        #endif

        instr = code;
	
	//DF; cout << "NotFound\n";

        goto perform_instr;
       }
      else 
       {

	 //DF; cout << "Failure\n";     

        return false; 
       };   

     case MaxEqualiseTermId:

       //DF; cout << "Forward PrimConst\n";

      if (instr->maxPathRelationSurfer->find(termId)) goto next_instr; 
      if (instr->maxPathRelationSurfer->currNode())
       {
	termId = instr->maxPathRelationSurfer->currNode()->key();

        #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS

        while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
         {
          if (!instr->maxPathRelationSurfer->next()) return false;
          termId = instr->maxPathRelationSurfer->currNode()->key();
         };
        #endif

        instr = code;

	//DF; cout << "NotFound\n";

        goto perform_instr;
       }
      else 
       {

	 //DF; cout << "Failure\n";     

        return false;
       };


     case ArgsInit:

       //DF; cout << "CANDIDATE " << termId << "\n";

      cachedArguments.reset(termId);
      goto next_instr;

     case ArgsFetch:
      cachedArguments.reset(*(instr->argumentsToFetch->nth(instr->argNum)));
      goto next_instr;

     case ArgsMove:
      cachedArguments.reset(*(cachedArguments.nth(instr->argNum)));
      goto next_instr;    

     case ArgsLoadSubst:
      *(instr->subst) = *(cachedArguments.nth(instr->argNum));
      goto next_instr;    

     case ArgsCompare:
      if (*(instr->subst) != *(cachedArguments.nth(instr->argNum))) goto backtrack;
      goto next_instr; 

     case ArgsInitAndStore:

       //DF; cout << "CANDIDATE " << termId << "\n";

      cachedArguments.reset(termId);
      *(instr->storedArguments) = cachedArguments;
      goto next_instr;

     case ArgsFetchAndStore: 
      cachedArguments.reset(*(instr->argumentsToFetch->nth(instr->argNum)));
      *(instr->storedArguments) = cachedArguments;
      goto next_instr;
     
     case ArgsMoveAndStore: 
      cachedArguments.reset(*(cachedArguments.nth(instr->argNum))); 
      *(instr->storedArguments) = cachedArguments;
      goto next_instr;  

     #ifdef DEBUG_NAMESPACE 
      default: ICP("ICP1"); return false; 
     #else
      #ifdef _SUPPRESS_WARNINGS_
       default: 
        BK::RuntimeError::report("Wrong tag in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::AbstractMachine::nextMatch(TermId& matchId)"); 
        return false;
      #endif   
     #endif
    };

 ICP("ICP2");
 backtrack:
  instr = code;

  //DF; instr->output(cout << "BK ",code,substitution) << "\n"; 

  switch (instr->tag)
   {
    case NonmaxEqualiseTermId:

      //DF; cout << "Backtrack PrimVar\n";

     if (instr->nonmaxPathRelationSurfer->next()) 
      {
       ASSERT_IN(instr->nonmaxPathRelationSurfer->currNode(),"A200");
       termId = instr->nonmaxPathRelationSurfer->currNode()->key();
       #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS
        while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
         {
          if (!instr->nonmaxPathRelationSurfer->next()) return false;
          termId = instr->nonmaxPathRelationSurfer->currNode()->key();
         };
       #endif

       goto next_instr;
      }
     else 
      {

	//DF; cout << "Failure\n";     

       return false;
      };

    case MaxEqualiseTermId:

      //DF; cout << "Backtrack PrimConst\n";

     if (instr->maxPathRelationSurfer->next())
      {
       ASSERT(instr->maxPathRelationSurfer->currNode());
       termId = instr->maxPathRelationSurfer->currNode()->key();
       #ifdef INSTANCE_RETRIEVAL_INDEX_USE_FILTERS
        while (INSTANCE_RETRIEVAL_INDEX_FILTER_OUT(termId))
         {
          if (!instr->maxPathRelationSurfer->next()) return false;
          termId = instr->maxPathRelationSurfer->currNode()->key();
         };
       #endif



       goto next_instr;
      }
     else 
      {

	//DF; cout << "Failure\n";     

       return false;
      };

    #ifdef DEBUG_NAMESPACE 
     default: ICP("ICP3"); return false; 
    #else
     #ifdef _SUPPRESS_WARNINGS_
      default: 
       BK::RuntimeError::report("Wrong tag in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::AbstractMachine::nextMatch(TermId& matchId)"); 
       return false;
     #endif   
    #endif
   };
} // bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::AbstractMachine::nextMatch(TermId& matchId)
Esempio n. 20
0
int main(int argc, char** argv) {
	//int _X[22] = {7, 198, 37, 155, 76, 138, 126, 123, 177, 112, 229, 114, 277, 110, 363, 136, 399, 151, 433, 196, 439, 222,};
	//Mat X(11,2,CV_32SC1,_X);
	
//	int _X_bar[22] = {6, 125, 67, 130, 97, 92, 150, 99, 188, 68, 208, 89, 285, 78, 305, 105, 369, 100, 390, 137, 432, 150,};
//	//int _X_bar[22] = {38, 232, 20, 184, 28, 127, 53, 69, 92, 33, 154, 12, 200, 12, 270, 13, 318, 26, 357, 46, 386, 76,};
////	int _X_bar[22] = {5, 217, 22, 168, 68, 141, 111, 125, 158, 115, 202, 111, 235, 106, 283, 111, 366, 136, 395, 151, 432, 188,};
//	//Mat X_bar(11,2,CV_32SC1,_X_bar); Mat X_bar_32f; X_bar.convertTo(X_bar_32f,CV_32F);
	double theta = -0.01*CV_PI;
	float _RotM[4] = { cos(theta), -sin(theta), sin(theta), cos(theta) };

	//RNG rng;
	//Mat X32f; X.convertTo(X32f,CV_32F);
	//Mat n(X32f.size(),X32f.type()); rng.fill(n,RNG::UNIFORM,Scalar(-35),Scalar(35));

	//Mat X_bar_32f = (X32f);
	////X_bar_32f(Range(0,X32f.rows),Range(1,2)) -= 45;
	//X_bar_32f = X_bar_32f * Mat(2,2,CV_32FC1,_RotM) + n;

	//Mat destinations; X_bar_32f.convertTo(destinations,CV_32S);

	RNG rng;
	Mat X(10,2,CV_32SC1);
	for(int i=0;i<10;i++) {
		X.at<Point>(i,0) = Point(100+sin(((double)i/10.0)*CV_PI)*50.0,100+cos(((double)i/10.0)*CV_PI)*50.0);
	}
	Mat destinations(50,2,X.type()); 
	rng.fill(destinations,RNG::NORMAL,Scalar(150.0),Scalar(125.0,50.0));

	//Mat X_1ch = X.reshape(2,X.rows);
	//Mat X_bar_1ch = destinations.reshape(2,X_bar.rows);

	//findBestTransform(X_1ch,X_bar_1ch);

	//ICP(X,destinations);

	MyFeatureDetector detector = MyFeatureDetector(42, 65, 30);
	
	Mat img1 = imread("./data/img/0095.png", 0);

	detector.setDetectedMat(img1);
	detector.usingSTAR();

	vector<Point2f> features1;
	detector.getFeaturePoints(features1, 5);

	IplImage *object1 = &IplImage(img1);
	IplImage *object_color1 = cvCreateImage(cvGetSize(object1), 8, 3);
	//The resource matrix of this function must have a head of IplImage
	cvCvtColor(object1, object_color1, CV_GRAY2BGR);

	Mat showMat1 = Mat(object_color1);
	namedWindow("STARFeatures1", CV_WINDOW_AUTOSIZE);
	for(int i=0;i<features1.size();i++){
		circle(showMat1, features1[i], 2, Scalar(0,255,0,0), -1); 
	}
	imshow("STARFeatures1", showMat1);



	Mat img2 = imread("./data/img/0087.png", 0);

	detector.setDetectedMat(img2);
	detector.usingSTAR();

	vector<Point2f> features2;
	detector.getFeaturePoints(features2, 5);

	IplImage *object2 = &IplImage(img2);
	IplImage *object_color2 = cvCreateImage(cvGetSize(object2), 8, 3);
	//The resource matrix of this function must have a head of IplImage
	cvCvtColor(object2, object_color2, CV_GRAY2BGR);

	Mat showMat2 = Mat(object_color2);
	namedWindow("STARFeatures2", CV_WINDOW_AUTOSIZE);
	for(int i=0;i<features2.size();i++){
		circle(showMat2, features2[i], 2, Scalar(0,255,0,0), -1); 
	}
	imshow("STARFeatures2", showMat2);

	Mat X1 = Mat(features1);
	Mat X2 = Mat(features2);

	X1 = X1.reshape(1);
	X2 = X2.reshape(1);

	ICP(X1,X2);

	cvWaitKey(0);

	char a;
	cin>>a;
	return 0;
}
inline bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<Alloc,Term,MaxTermDepth,MaxTermSize,MaxNumOfVariables>::remove(const TermId& removedTermId)
{
 CALL("remove(const TermId& removedTermId)");
 _removedTermTraversal.reset(removedTermId);
 _removal.reset(_trie);

 bool somethingRemoved = false;
 ulong arity;

 check_state:
  switch (_removedTermTraversal.state())
   { 
    case TermTraversal::Func:
     arity = _removedTermTraversal.symbol().arity();
     if (arity)
      {
       if (_removal.nonconstFunc(_removedTermTraversal.symbol()))
	{
	 somethingRemoved = _removal.indexedObj().remove(removedTermId) || somethingRemoved;
         _removedTermTraversal.next();
        }
       else 
	{
	 _removal.after();
	 _removedTermTraversal.after();
        };
      }
     else // constant
      {
       if (_removal.constant(_removedTermTraversal.symbol()))
	{
         somethingRemoved = _removal.constIndObj().remove(removedTermId) || somethingRemoved;
        }
       else
	{
         _removal.after();
        };
       _removedTermTraversal.next();
      };
     goto check_state;
 
    case TermTraversal::Var:
     _removal.after();
     _removedTermTraversal.next();
     goto check_state;
     
    case TermTraversal::End: 
     _removal.recycleObsoleteNodes();     
     return somethingRemoved;

    #ifdef DEBUG_NAMESPACE 
     default: ICP("ICP0"); return false;
    #else
     #ifdef _SUPPRESS_WARNINGS_
      default: 
       BK::RuntimeError::report("Wrong term traversal state in StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::remove(..)");
       return false;
     #endif
    #endif       
   };

} // bool StandardPathIndexingWithCompiledCleanUpForInstanceRetrieval<..>::remove(const TermId& removedTermId)
Esempio n. 22
0
File: Database.cpp Progetto: wkcn/HR
Exp* Database::Build(const string filter){

	vector<string> vs;
	string buf;
	//分词

	static const int symsSize = 18;
	static string syms[symsSize] = {"(",")",">","<",">=","<=","==","=","!=","<>","+","-","*","/","+=","-=","*=","/="};
	static string checkstr = "()><=!+-*/";
	bool quote = false;

	for(size_t i = 0;i < filter.size(); ++i){
		if (filter[i] == ' '){
			if(!(buf.empty()))vs.push_back(buf);
			buf.clear();
		}else if (filter[i] == '\'' || filter[i] == '\"'){
			quote = true;
			char q = filter[i];
			if(!(buf.empty()))vs.push_back(buf);
			buf.clear();
			buf += q;
			++i;
			for(;i < filter.size(); ++i){
				if (filter[i] == q){
					buf += q;
					quote = false;
					break;
				}else{
					buf += filter[i];
				}
			}
			vs.push_back(buf);
			buf.clear();
		}else if (checkstr.find(filter[i]) != string::npos){
			if(!(buf.empty()))vs.push_back(buf);
			buf.clear();
			buf = filter[i];
			if (i+1 < filter.size()){
				string temp(buf);
				temp += filter[i + 1]; 
				bool ex = false;
				for (auto &s : syms){
					if (s == temp){
						ex = true;
						++i;
						break;
					}
				}
				if (ex)buf = temp;
			}
			vs.push_back(buf);
			buf.clear();	
		}else{
			buf += filter[i];
		}
	}

	if(quote)throw "引号不匹配";

	if(!buf.empty())vs.push_back(buf);

	stack<string> op;
	vector<string> bac;
	vector<bool> kinds;//0为一般表达式,1为逻辑符号
	for(size_t i = 0;i < vs.size(); ++i){
		//cout << vs[i] << endl;
		if (vs[i] == ")"){
			bool can = false;
			while (!op.empty()){
				string q = op.top();
				op.pop();
				if (q == "("){
					can = true;
					break;
				}else{
					bac.push_back(q);
					kinds.push_back(1);
				}
			}
			if (!can){
				throw "括号不匹配";
			}
		}else{
			if (checkstr.find(vs[i][0]) != string::npos || vs[i][0] == '(' || vs[i] == "and" || vs[i] == "or"){
				while (!op.empty() && ISP(op.top()) >= ICP(vs[i])){
					string q = op.top();
					op.pop();
					bac.push_back(q);
					//cout <<q<<endl;
					kinds.push_back(1);
				}
				op.push(vs[i]);
			}else{
				bac.push_back(vs[i]);
				kinds.push_back(0);
			}
		}
	}
	while (!op.empty()){
		string q = op.top();
		op.pop();
		bac.push_back(q);
		kinds.push_back(1);
	}
/*
	for(auto v:bac){
		cout << v <<endl;
	}
*/
	stack<Exp*> es;
	for (size_t i = 0; i < bac.size();++i){
		if (kinds[i]){
			//符号(这里都是二元操作符)
			Exp *t = new Exp();
			if(es.empty())throw "缺少右操作数";
			t -> rv = es.top();es.pop();
			if(es.empty())throw "缺少左操作数";
			t -> lv = es.top();es.pop();
			t -> name = bac[i];
			t -> kind = EXP_OP;
			es.push(t);
		}else{
			Exp *t = new Exp();
			if (bac[i][0] == '-' || (bac[i][0] >= '0' && bac[i][0] <= '9')){
				t -> kind = EXP_NUM;
				t -> name = bac[i];
			}else{
				if (bac[i][0] == '\'' || bac[i][0] == '\"'){
					t -> kind = EXP_STR;
					t -> name = bac[i].substr(1,bac[i].size()-2);
				}else{
					t -> kind = EXP_VAR;
					t -> name = StrLower(bac[i]);
				}
			}
			es.push(t);
		}
	}
	Exp *root = es.top();es.pop();
	if (es.empty())return root;
	throw "您输入的表达式有误,不能完全解析";
	return 0;
}
Esempio n. 23
0
void CreatePointCloud(short * buf_int, int frame_width, int frame_height, int maxZ) 
{ 
//if(cloud_status==10) { return;}
frame_width=frame_width;
frame_height=frame_height;

float scale=1.0f;
int height_ds=frame_height*scale;
int width_ds=frame_width*scale;

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;

if(cloud_status==0) 
{
  cloud=cloud_1;
 LOGI ("Save First Cloud");
 
}
else
{
 pcl::PointCloud<pcl::PointXYZ>::Ptr tmp (new pcl::PointCloud<pcl::PointXYZ>);
 cloud_2=tmp;
 cloud=cloud_2;
 LOGI ("Save new Cloud");

}
    
    // Fill in the cloud data
    cloud->width = width_ds;
    cloud->height = height_ds;
    cloud->points.resize (cloud->width * cloud->height);

for(int  i=0;i<height_ds;i++)
        {
            for(int j=0;j<width_ds;j++)
            {
                int iold=i*frame_height/height_ds;
                int jold=j*frame_width/width_ds;

		short depth = *(buf_int+iold*frame_width+jold);

		cloud->points[i*width_ds+j].x=((j-width_ds/2)*depth/(525*scale))/1000.f;  
		cloud->points[i*width_ds+j].y=((i-height_ds/2)*depth/(525*scale))/1000.f;
		cloud->points[i*width_ds+j].z=(depth)/1000.f;
		if (depth==0) {
	 		cloud->points[i*width_ds+j].x=(short)0;
			cloud->points[i*width_ds+j].y=(short)0;
			cloud->points[i*width_ds+j].z=(short)0;
		}
		//else  {LOGI("i=%d,j=%d,depth=%d,x=%f y=%f z=%f",i,j,depth,cloud->points[i*width_ds+j].x,cloud->points[i*width_ds+j].y,cloud->points[i*width_ds+j].z);	}

             }
        }
   
 LOGI ("DATA LOADED");

//// Execute ICP for cloud_1 cloud_2
if(cloud_status==0) 
{
cloud_status++;
return;
}

cloud_status++;


ICP(cloud_1,cloud_2);
//usleep(1000000);

 LOGI ("ICP");
cloud_1=cloud_2;
 LOGI ("cloud1=cloud2");

}