void special_ctrl_operations(int instruction)
{
	int index;
	func f_ptr;
	*((int*)(&specialCtrlOp))=instruction;
#if DEBUG
	printf("Special control operations instruction: 0x%x\n",instruction);
	printf("option = %x\n",specialCtrlOp.option);
	printf("opcode = %x\n",specialCtrlOp.opcode);
	printf("pass1 = %x\n",specialCtrlOp.pass1);
	printf("pass2 = %x\n",specialCtrlOp.pass2);
	printf("pass3 = %x\n",specialCtrlOp.pass3);
	printf("pass4 = %x\n",specialCtrlOp.pass4);
	printf("pass5 = %x\n",specialCtrlOp.pass5);
	printf("pass6 = %x\n",specialCtrlOp.pass6);
	printf("pass7 = %x\n",specialCtrlOp.pass7);
	printf("pass8 = %x\n",specialCtrlOp.pass8);
	printf("pass9 = %x\n",specialCtrlOp.pass9);
	printf("pass10 = %x\n",specialCtrlOp.pass10);
#endif
	
	index=specialCtrlOp.opcode;
	f_ptr=(void*) special_ctrl_o[index];
	f_ptr(instruction);
}
Beispiel #2
0
int main()
{
  int input;

  f_ptr=f1;
  f_ptr();
  assert(global==1);
  
  f_ptr=f2;
  f_ptr();
  assert(global==2);

  f_ptr=input?f1:f2;
  f_ptr();
  assert(global==(input?1:2));
}
void data_pro_add_12m(int instruction){
	int op,imm12,index;
	func f_ptr;
#if DEBUG
	printf("data_pro_add_12m: 0x%X \n",instruction);
#endif
	*((int *)(&dataProAdd)) = instruction;
	op=(dataProAdd.op<<2)+dataProAdd.op2;
#if DEBUG
	printf("Operate Code : 0x%x \n", op);
	printf("Rn: 0x%x \n", dataProAdd.rn);
	printf("Rd: 0x%x \n", dataProAdd.rd);
#endif
	imm12=decode_imm12(dataProAdd.imm1, dataProAdd.imm3,dataProAdd.imm8);
#if DEBUG
	printf("imm 12: 0x%x \n",imm12);
#endif
	index = op;
	if((op == 0) && (dataProAdd.rn == 15)){
		index = op + 4;
	}else if((op == 6) && (dataProAdd.rn == 15)){
		index = op - 4;
	}
#if DEBUG
	printf("index is %d", index);
#endif
	f_ptr=(void *)data_pro_p[index];
	f_ptr(instruction);
}
void ls_exbh_tb(int instruction){
	int index;
	func f_ptr;
	*((int *)(&TbB)) = instruction;
#if DEBUG
	printf("ls_exbh_tb: 0x%X \n",instruction);
	printf("Op: 0x%X \n",TbB.op);
	printf("Rt: 0x%X \n",TbB.rt);
	printf("Rt2: 0x%X \n",TbB.rt2);
#endif
	if(TbB.l == 1 && TbB.op == 4)
		index = 0;
	else if(TbB.l == 1 && TbB.op == 5)
		index = 1;
	else if(TbB.l == 0 && TbB.op == 4)
		index = 2;
	else if(TbB.l == 0 && TbB.op == 5)
		index = 3;
	else if(TbB.l == 1 && TbB.op == 0)
		index = 4;
	else if(TbB.l == 1 && TbB.op == 1)
		index = 5;
	else
		index = 6;
	//printf("index is %d", index);
	f_ptr=(void *)ls_ex_bh_tb[index];
	f_ptr(instruction);
}
int main()
{
  int num = 70;
  void (* f_ptr)(int);

  f_ptr = your_num( num, my_num);
  f_ptr(9999999);

  return 0;
}
void data_pro_mov_16m(int instruction){
	int op, imm16,index;
	func f_ptr;
	//printf("data_pro_mov_16m: 0x%X \n",instruction);
	*((int *)(&dataProMov)) = instruction;
	op = (dataProMov.op<<2)+dataProMov.op2;
	//printf("Operate Code : 0x%x \n",op);
	//printf("Rd: 0x%x \n", dataProMov.rd);
	imm16=decode_imm16(dataProMov.imm1,dataProMov.imm4, dataProMov.imm3,dataProMov.imm8);
	//printf("imm 16: 0x%x \n",imm16);
	index = op;
	//printf("index is %d", index);
	f_ptr=(void *)move_p[index];
	f_ptr(instruction);
}
Beispiel #7
0
double newton(double x0, double epsilon, double (*f_ptr)(double), double (*fprim_ptr)(double))
{
    double  x_i,
            x_i1  = x0,
            delta = 2*epsilon;
    
    while ( delta > epsilon )
    {
        x_i = x_i1;
        x_i1 = x_i - f_ptr(x_i)/fprim_ptr(x_i);
        delta = fabs( x_i1 - x_i );
    }
    
    return x_i1;
}
void data_pro_bitoperation(int instruction){
	int index;
	func f_ptr;
	//printf("data_pro_bitoperation: 0x%X \n",instruction);
	*((int *)(&dataProBit)) = instruction;
	//printf("Operate Code : 0x%x \n", dataProBit.op);
	//printf("Rn: 0x%x \n", dataProBit.rn);
	//printf("Rd: 0x%x \n", dataProBit.rd);
	//imm12=decode_bitOperation(dataProBit.imm3, dataProBit.imm2,dataProBit.imm5);
	//printf("imm 12: 0x%x \n",imm12);
	index = dataProBit.op;
	if((dataProBit.op == 3) && (dataProBit.rn == 15))
		index = dataProBit.op + 4;
	//printf("index is %d", index);
	f_ptr=(void *)bitfield_saturate[index];
	f_ptr(instruction);	
}
nyx_error_t nyx_haptics_cancel_all(nyx_device_handle_t handle)
{
	nyx_device_t *d = (nyx_device_t *)handle;
	CHECK_DEVICE(d);
	CHECK_DEVICE_TYPE(d, NYX_DEVICE_HAPTICS);
	nyx_haptics_cancel_all_function_t f_ptr = LOOKUP_METHOD(d,
	        NYX_HAPTICS_CANCEL_ALL_MODULE_METHOD);

	if (f_ptr)
	{
		return f_ptr(d);
	}
	else
	{
		return NYX_ERROR_NOT_IMPLEMENTED;
	}
}
void branch_instr(int instruction)
{
	func f_ptr;
	*((int *)(&branch)) = instruction;
#if DEBUG
	printf("branch instruction: 0x%x \n",instruction);
	printf("offset1 = %x\n",branch.off1);
	printf("j2 = %x\n",branch.j2);
	printf("pass1 = %x\n",branch.pass1);
	printf("j1 = %x\n",branch.j1);
	printf("pass2 = %x\n",branch.pass2);
	printf("pass3 = %x\n",branch.pass3);
	printf("offset2 = %x\n",branch.off2);
	printf("S = %x\n",branch.s);
	printf("pass4 = %x\n",branch.pass4);
#endif
	f_ptr=(void*) branch_i[0];
	f_ptr(instruction);

}
void branch_with_link(int instruction)
{
	func f_ptr;
	*((int*)(&branchWithLink))=instruction;
#if DEBUG
	printf("branch with link instruction: 0x% \n",instruction);
	printf("offset1 = %x\n",branchWithLink.off1);
	printf("J2 = %x\n",branchWithLink.j2);
	printf("pass1 = %x\n",branchWithLink.pass1);
	printf("J1 = %x\n",branchWithLink.j1);
	printf("pass2 = %x\n",branchWithLink.pass2);
	printf("pass3 = %x\n",branchWithLink.pass3);
	printf("offset2 = %x\n",branchWithLink.off2);
	printf("S = %x\n",branchWithLink.s);
	printf("pass4 = %x\n",branchWithLink.pass4);
#endif
	f_ptr=(void*)branch_with_l[0];
    f_ptr(instruction);

}
void ls_double(int instruction){
	int index;
	func f_ptr;
	*((int *)(&LdrD)) = instruction;
#if DEBUG
	printf("ls_double: 0x%X \n",instruction);
	printf("Imm8: 0x%X \n",LdrD.imm8);
	printf("Rt: 0x%X \n",LdrD.rt);
	printf("Rt2: 0x%X \n",LdrD.rt2);
#endif
	if(LdrD.l == 1)
		index = 0;
	else if(LdrD.l == 0)
		index = 1;
	else
		index = 2;
	//printf("index is %d",index);
	f_ptr=(void *)ls_doub[index];
	f_ptr(instruction);
}
void conditional_branch(int instruction)
{
	func f_ptr;
	*((int*)(&conditionalBranch))=instruction;
#if DEBUG
	printf("Conditional Branch instruction: 0x% \n",instruction);
	printf("offset1 = %x\n",conditionalBranch.off1);
	printf("J2 = %x\n",conditionalBranch.j2);
	printf("pass1 = %x\n",conditionalBranch.pass1);
	printf("J1 = %x\n",conditionalBranch.j1);
	printf("pass2 = %x\n",conditionalBranch.pass2);
	printf("offset2 = %x\n",conditionalBranch.off2);
	printf("cond = %x\n",conditionalBranch.cond);
	printf("S = %x\n",conditionalBranch.s);
	printf("pass3 = %x\n",conditionalBranch.pass3);
#endif
	f_ptr=(void*)conditional_b[0];
	f_ptr(instruction);

}
void move_to_reg(int instruction)
{
	func f_ptr;
	*((int*)(&moveToReg))=instruction;
#if DEBUG
	printf("Move to register from status instruction:%x\n",instruction);
	printf("SYSm = %x\n",moveToReg.sysm);
	printf("Rd = %x\n",moveToReg.rd);
	printf("pass1 = %x\n",moveToReg.pass1);
	printf("pass2 = %x\n",moveToReg.pass2);
	printf("pass3 = %x\n",moveToReg.pass3);
	printf("pass4 = %x\n",moveToReg.pass4);
	printf("pass5 = %x\n",moveToReg.pass5);
	printf("pass6 = %x\n",moveToReg.pass6);
	printf("pass7 = %x\n",moveToReg.pass7);
	printf("pass8 = %x\n",moveToReg.pass8);
	printf("pass9 = %x\n",moveToReg.pass9);
#endif
	f_ptr=(void*)move_to_r[0];
	f_ptr(instruction);

}
void move_to_status(int instruction)
{
	func f_ptr;
	*((int*)(&moveToStatus))=instruction;
#if DEBUG
	printf("move to status from register instruction: 0x% \n",instruction);
	printf("SYSm = %x\n",moveToStatus.sysm);
	printf("pass1 = %x\n",moveToStatus.pass1);
	printf("pass2 = %x\n",moveToStatus.pass2);
	printf("pass3 = %x\n",moveToStatus.pass3);
	printf("pass4 = %x\n",moveToStatus.pass4);
	printf("Rn = %x\n",moveToStatus.rn);
	printf("pass5 = %x\n",moveToStatus.pass5);
	printf("pass6 = %x\n",moveToStatus.pass6);
	printf("pass7 = %x\n",moveToStatus.pass7);
	printf("pass8 = %x\n",moveToStatus.pass8);
	printf("pass9 = %x\n",moveToStatus.pass9);
#endif
	f_ptr=(void*)move_to_s[0];
	f_ptr(instruction);

}
void data_pro_modified_12m(int instruction){
	int imm12,index;
	func f_ptr;
	*((int *)(&dataProModified)) = instruction;
#if DEBUG
	printf("data_pro_modified_12m: 0x%X \n",instruction);
	printf("Operate Code : 0x%x \n", dataProModified.op);
	printf("S: 0x%x \n", dataProModified.s);
	printf("Rn: 0x%x \n", dataProModified.rn);
	printf("Rd: 0x%x \n", dataProModified.rd);
#endif
	imm12=decode_imm12(dataProModified.imm1, dataProModified.imm3,dataProModified.imm8);
#if DEBUG
	printf("imm 12: 0x%x \n",imm12);
#endif

	index = dataProModified.op;
//	printf("index : %d", index);

	if((dataProModified.op == 0x8) &&(dataProModified.rd ==0xf)&&(dataProModified.s==0x1 )){
		index = dataProModified.op+16;
	}else if((dataProModified.op == 13) &&(dataProModified.rd ==15)&&(dataProModified.s==1 )){
		index = dataProModified.op+16;
	}else if((dataProModified.op == 2) &&(dataProModified.rn ==15)){
		index = dataProModified.op+16;
	}else if((dataProModified.op == 3) &&(dataProModified.rn ==15)){
		index = dataProModified.op+16;
	}else if((dataProModified.op == 4) &&(dataProModified.rd ==15)&&(dataProModified.s==1 )){
		index = dataProModified.op+16;
	}else if((dataProModified.op == 0) &&(dataProModified.rd ==15)&&(dataProModified.s==1 )){
		index = dataProModified.op+16;
	}
#if DEBUG
	printf("index is %d", index);
#endif
	f_ptr=(void *)data_pro_m[index];
	f_ptr(instruction);
}
static void* OC_bsearch( const struct Ordered_container* c_ptr, OC_comp_fp_t f_ptr, const void* arg_ptr )
{
    int left = 0 ;
    int right;
    int mid = 0;
    
    if ( OC_empty( c_ptr ) )
        return NULL;
    
    right = c_ptr->size - 1;
    
    while( left <= right )
    {
        int com_value;
        
        mid = ( right + left ) / 2 ;
        
        com_value = f_ptr( arg_ptr, c_ptr->array[ mid ] );
        
        if ( com_value == 0 )
        {
            return c_ptr->array + mid ;
        }
        if ( com_value < 0 )
        {
            right = mid - 1;
        }
        else
        {
            left = mid + 1;
        }
        
    }
    
    return NULL;
}
void no_op_hints(int instruction)
{
	int index;
	func f_ptr;
	*((int*)(&noOpHints))=instruction;
#if DEBUG
	printf("No operation & hints instruction: 0x%\n",instruction);
	printf("hint = %x\n",noOpHints.hint);
	printf("pass1 = %x\n",noOpHints.pass1);
	printf("pass2 = %x\n",noOpHints.pass2);
	printf("pass3 = %x\n",noOpHints.pass3);
	printf("pass4 = %x\n",noOpHints.pass4);
	printf("pass5 = %x\n",noOpHints.pass5);
	printf("pass6 = %x\n",noOpHints.pass6);
	printf("pass7 = %x\n",noOpHints.pass7);
	printf("pass8 = %x\n",noOpHints.pass8);
	printf("pass9 = %x\n",noOpHints.pass9);
	printf("pass10 = %x\n",noOpHints.pass10);
	printf("pass11 = %x\n",noOpHints.pass11);
#endif

	if(noOpHints.hint<=4)
		index=noOpHints.hint;
	else if(noOpHints.hint>=240 && noOpHints.hint<=255)
		index=5;
	else
		index=-1;
				
	if(index==-1)
		branch_reserved(instruction);
	else{
		printf("Index is : %d\n",index);
		f_ptr=(void*)no_op_h[index];
		f_ptr(instruction);
	}
}
Beispiel #19
0
/// =-=-=-=-=-=-=-
/// @brief high level function which process a result set from
///        the above gathering function for a rebalancing operation
    error proc_results_for_rebalance(
        rsComm_t*                  _comm,
        const std::string&         _parent_resc_name,
        const std::string&         _child_resc_name,
        const dist_child_result_t& _results ) {
        // =-=-=-=-=-=-=-
        // check incoming params
        if ( !_comm ) {
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       "null comm pointer" );
        }
        else if ( _parent_resc_name.empty() ) {
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       "empty parent resc name" );
        }
        else if ( _child_resc_name.empty() ) {
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       "empty child resc name" );
        }
        else if ( _results.empty() ) {
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       "empty results vector" );
        }

        // =-=-=-=-=-=-=-
        // iterate over the result set and repl the objects
        dist_child_result_t::const_iterator r_itr = _results.begin();
        for ( ; r_itr != _results.end(); ++r_itr ) {
            // =-=-=-=-=-=-=-
            // get a valid source object from which to replicate
            int src_mode = 0;
            std::string obj_path, src_hier;
            error ret = get_source_data_object_attributes(
                            *r_itr,
                            _parent_resc_name,
                            _comm,
                            obj_path,
                            src_hier,
                            src_mode );
            if ( !ret.ok() ) {
                return PASS( ret );
            }

            // =-=-=-=-=-=-=-
            // create a file object so we can resolve a valid
            // hierarchy to which to replicate
            file_object_ptr f_ptr( new file_object(
                                       _comm,
                                       obj_path,
                                       "",
                                       "",
                                       0,
                                       src_mode,
                                       0 ) );
            // =-=-=-=-=-=-=-
            // short circuit the magic re-repl
            hierarchy_parser sub_parser;
            sub_parser.set_string( src_hier );
            std::string sub_hier;
            sub_parser.str( sub_hier, _parent_resc_name );
            f_ptr->in_pdmo( sub_hier );

            // =-=-=-=-=-=-=-
            // init the parser with the fragment of the
            // upstream hierarchy not including the repl
            // node as it should add itself
            hierarchy_parser parser;
            size_t pos = src_hier.find( _parent_resc_name );
            if ( std::string::npos == pos ) {
                std::stringstream msg;
                msg << "missing repl name ["
                    << _parent_resc_name
                    << "] in source hier string ["
                    << src_hier
                    << "]";
                return ERROR(
                           SYS_INVALID_INPUT_PARAM,
                           msg.str() );
            }

            // =-=-=-=-=-=-=-
            // substring hier from the root to the parent resc
            std::string src_frag = src_hier.substr(
                                       0, pos + _parent_resc_name.size() + 1 );
            parser.set_string( src_frag );

            // =-=-=-=-=-=-=-
            // handy reference to root resc name
            std::string root_resc;
            parser.first_resc( root_resc );

            // =-=-=-=-=-=-=-
            // resolve the target child resource plugin
            resource_ptr dst_resc;
            error r_err = resc_mgr.resolve(
                              _child_resc_name,
                              dst_resc );
            if ( !r_err.ok() ) {
                return PASS( r_err );
            }

            // =-=-=-=-=-=-=-
            // then we need to query the target resource and ask
            // it to determine a dest resc hier for the repl
            std::string host_name;
            float            vote = 0.0;
            r_err = dst_resc->call < const std::string*,
            const std::string*,
            hierarchy_parser*,
            float* > (
                _comm,
                RESOURCE_OP_RESOLVE_RESC_HIER,
                f_ptr,
                &CREATE_OPERATION,
                &host_name,
                &parser,
                &vote );
            if ( !r_err.ok() ) {
                return PASS( r_err );
            }

            // =-=-=-=-=-=-=-
            // extract the hier from the parser
            std::string dst_hier;
            parser.str( dst_hier );

            // =-=-=-=-=-=-=-
            // now that we have all the pieces in place, actually
            // do the replication
            r_err = repl_for_rebalance(
                        _comm,
                        obj_path,
                        _parent_resc_name,
                        src_hier,
                        dst_hier,
                        root_resc,
                        root_resc,
                        src_mode );
            if ( !r_err.ok() ) {
                return PASS( r_err );
            }

        } // for r_itr

        return SUCCESS();

    } // proc_results_for_rebalance