node *insertNode(node *root, int cont){ if(root==NULL){ return createNode(cont); } else if(cont>root->data) { root->right=insertNode(root->right,cont); if(BF(root)==-2){ if(cont>root->right->data) root=RR(root); else root=RL(root); } } else if(cont<root->data) { root->left=insertNode(root->left,cont); if(BF(root)==2){ if(cont < root->left->data) root=LL(root); else root=LR(root); } } /*else{ if(cont==root->data) printf("the node %d already exists in the tree",cont); return root; }*/ root->ht=height(root); return(root); }
void DOFInterpolation<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { //Intrepid version: // for (int i=0; i < val_qp.size() ; i++) val_qp[i] = 0.0; // Intrepid::FunctionSpaceTools:: evaluate<ScalarT>(val_qp, val_node, BF); for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { if (2==numRank) { typename PHAL::Ref<ScalarT>::type vqp = val_qp(cell,qp) = 0; for (int node=0; node < numNodes; ++node) { vqp += val_node(cell, node) * BF(cell, node, qp); } } else { for (int level=0; level < numLevels; ++level) { typename PHAL::Ref<ScalarT>::type vqp = val_qp(cell,qp,level); vqp = 0; for (int node=0; node < numNodes; ++node) { vqp += val_node(cell, node, level) * BF(cell, node, qp); } } } } } }
/* Insert sessid and socket pair in AVL Tree */ AVLTree_Node* insertion(AVLTree_Node *T,uint16_t x, struct node *head) { if(T==NULL) { T=(AVLTree_Node*)malloc(sizeof(AVLTree_Node)); T->data=x; T->head = head; T->left=NULL; T->right=NULL; } else if(x > T->data) // insert in right subtree { T->right=insertion(T->right,x,head); if(BF(T)==-2) if(x>T->right->data) T=RR(T); else T=RL(T); } else if(x<T->data) { T->left=insertion(T->left,x,head); if(BF(T)==2) if(x < T->left->data) T=LL(T); else T=LR(T); } T->ht=height(T); //root=T; return(T); }
/* Send the BC command to the device */ static void stmp3xxx_mmc_bc(struct stmp3xxx_mmc_host *host) { struct mmc_command *cmd = host->cmd; struct stmp3xxx_dma_descriptor *dma_desc = &host->dma_desc; dma_desc->command->cmd = BM_APBH_CHn_CMD_WAIT4ENDCMD | BM_APBH_CHn_CMD_SEMAPHORE | BM_APBH_CHn_CMD_IRQONCMPLT | BF(0, APBH_CHn_CMD_XFER_COUNT) | BF(3, APBH_CHn_CMD_CMDWORDS) | BF(0, APBH_CHn_CMD_COMMAND); /* NO_DMA_XFER */ dma_desc->command->pio_words[0] = BM_SSP_CTRL0_ENABLE | BM_SSP_CTRL0_IGNORE_CRC; dma_desc->command->pio_words[1] = BF(cmd->opcode, SSP_CMD0_CMD) | BM_SSP_CMD0_APPEND_8CYC; dma_desc->command->pio_words[2] = BF(cmd->arg, SSP_CMD1_CMD_ARG); init_completion(&host->dma_done); stmp3xxx_dma_reset_channel(host->dmach); stmp3xxx_dma_go(host->dmach, dma_desc, 1); wait_for_completion(&host->dma_done); cmd->error = stmp3xxx_mmc_cmd_error(host->status); if (stmp3xxx_dma_running(host->dmach)) dev_dbg(host->dev, "DMA command not finished\n"); if (cmd->error) { dev_dbg(host->dev, "Command error 0x%x\n", cmd->error); stmp3xxx_dma_reset_channel(host->dmach); } }
node * insert(node *T,int x) { if(T==NULL) { T=(node*)malloc(sizeof(node)); T->data=x; T->left=NULL; T->right=NULL; } else if(x > T->data) // insert in right subtree { T->right=insert(T->right,x); if(BF(T)==-2) if(x>T->right->data) T=RR(T); else T=RL(T); } else if(x<T->data) { T->left=insert(T->left,x); if(BF(T)==2) if(x < T->left->data) T=LL(T); else T=LR(T); } T->ht=height(T); return(T); }
void stmp37xx_circ_advance_active(struct stmp37xx_circ_dma_chain *chain, unsigned count) { void __iomem *c; u32 mask_clr, mask; BUG_ON(chain->free_count < count); chain->free_count -= count; chain->free_index += count; chain->free_index %= chain->total_count; chain->active_count += count; switch (chain->bus) { case STMP3XXX_BUS_APBH: c = REGS_APBH_BASE + HW_APBH_CHn_SEMA + 0x70 * chain->channel; mask_clr = BM_APBH_CHn_SEMA_INCREMENT_SEMA; mask = BF(count, APBH_CHn_SEMA_INCREMENT_SEMA); break; case STMP3XXX_BUS_APBX: c = REGS_APBX_BASE + HW_APBX_CHn_SEMA + 0x70 * chain->channel; mask_clr = BM_APBX_CHn_SEMA_INCREMENT_SEMA; mask = BF(count, APBX_CHn_SEMA_INCREMENT_SEMA); break; default: BUG(); return; } /* Set counting semaphore (kicks off transfer). Assumes peripheral has been set up correctly */ stmp3xxx_clearl(mask_clr, c); stmp3xxx_setl(mask, c); }
static int set_otp_timing(void) { u32 clk_rate = 0; u32 relax, strobe_read, strobe_prog; u32 timing = 0; /* get clock */ clk_rate = mxc_get_clock(MXC_IPG_CLK); if (clk_rate == -1) { printf("ERROR: mxc_get_clock failed\n"); return -1; } log("clk_rate: %d.", clk_rate); relax = clk_rate / (1000000000 / DEF_RELAX) - 1; strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; timing = BF(relax, OCOTP_TIMING_RELAX); timing |= BF(strobe_read, OCOTP_TIMING_STROBE_READ); timing |= BF(strobe_prog, OCOTP_TIMING_STROBE_PROG); log("timing: 0x%X", timing); writel(timing, IMX_OTP_BASE + HW_OCOTP_TIMING); return 0; }
int timing_ctrl_rams(int ss) { __raw_writel(BF(ss, DIGCTL_ARMCACHE_VALID_SS) | BF(ss, DIGCTL_ARMCACHE_DRTY_SS) | BF(ss, DIGCTL_ARMCACHE_CACHE_SS) | BF(ss, DIGCTL_ARMCACHE_DTAG_SS) | BF(ss, DIGCTL_ARMCACHE_ITAG_SS), DIGCTRL_BASE_ADDR + HW_DIGCTL_ARMCACHE); return 0; }
/* * Change divisors to reflect the rate of 'hz'. Note that we should not * play with clock rate, because the same source is used to clock both * SSP ports. */ static void stmp3xxx_set_sclk_speed(struct stmp3xxx_mmc_host *host, unsigned int hz) { unsigned long ssp; u32 div1, div2; u32 val; struct stmp3xxxmmc_platform_data *pdata = host->dev->platform_data; if (get_evk_board_version() == 1) { /*EVK Ver1 max clock is 12M */ if (hz > 12000000) hz = 12000000; } if (pdata && pdata->setclock) { /* if the SSP is buggy and platform provides callback... well, let it be. */ host->clkrt = pdata->setclock(hz); return; } /* ...but the RightIdea(tm) is to set divisors to match the requested clock. */ hz /= 1000; ssp = clk_get_rate(host->clk); for (div1 = 2; div1 < 254; div1 += 2) { div2 = ssp / hz / div1; if (div2 < 0x100) break; } if (div1 >= 254) { dev_err(host->dev, "Cannot set clock to %dkHz\n", hz); return; } dev_dbg(host->dev, "Setting clock rate to %ld kHz [%x+%x] " "(requested %d), source %ldk\n", ssp / div1 / div2, div1, div2, hz, ssp); val = __raw_readl(host->ssp_base + HW_SSP_TIMING); val &= ~(BM_SSP_TIMING_CLOCK_DIVIDE | BM_SSP_TIMING_CLOCK_RATE); val |= BF(div1, SSP_TIMING_CLOCK_DIVIDE) | BF(div2 - 1, SSP_TIMING_CLOCK_RATE); __raw_writel(val, host->ssp_base + HW_SSP_TIMING); host->clkrt = ssp / div1 / div2 * 1000; }
node * Delete(node *T,int x) { node *p; if(T==NULL) { return NULL; } else if(x > T->data) // insert in right subtree { T->right=Delete(T->right,x); if(BF(T)==2) if(BF(T->left)>=0) T=LL(T); else T=LR(T); } else if(x<T->data) { T->left=Delete(T->left,x); if(BF(T)==-2)//Rebalance during windup if(BF(T->right)<=0) T=RR(T); else T=RL(T); } else { //data to be deleted is found if(T->right !=NULL) { //delete its inordersuccesor p=T->right; while(p->left != NULL) p=p->left; T->data=p->data; T->right=Delete(T->right,p->data); if(BF(T)==2)//Rebalance during windup if(BF(T->left)>=0) T=LL(T); else T=LR(T); } else return(T->left); } T->ht=height(T); return(T); }
static struct avl_node *_avl_delete(struct avl_node *n, int key) { if(!n) return NULL; if(key < K(n)) L(n) = _avl_delete(L(n), key); else if(key > K(n)) R(n) = _avl_delete(R(n), key); else { // key == K(n) if(NULL == L(n) || NULL == R(n)) { struct avl_node *tmp = L(n) ? L(n) : R(n); if(tmp) { *n = *tmp; // copy contents of child to n } else { // n is leaf tmp = n; n = NULL; } free(tmp); } else { // two children case struct avl_node *d = _avl_minimum(n); K(n) = K(d); R(n) = _avl_delete(d, key); } } // no child case if(!n) return NULL; H(n) = MAX(HH(n->left), HH(n->right)) + 1; int bf = BF(n); if(bf > 1) { if(0 > BF(L(n))) { // LR case L(n) = _leftRotate(L(n)); } // else LL case return _rightRotate(n); } if(bf < -1) { if(0 < BF(R(n))) { // RL case R(n) = _rightRotate(R(n)); } // else RR case return _leftRotate(n); } return n; }
void CismSurfaceGradFO<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { gradS_qp(cell,qp,0) = dsdx_node(cell, 0) * BF(cell, 0, qp); gradS_qp(cell,qp,1) = dsdy_node(cell, 0) * BF(cell, 0, qp); for (std::size_t node=1; node < numNodes; ++node) { gradS_qp(cell,qp,0) += dsdx_node(cell, node) * BF(cell, node, qp); gradS_qp(cell,qp,1) += dsdy_node(cell, node) * BF(cell, node, qp); } } } }
bool testKNNG(unsigned int Size, unsigned int k, T min, T max, int num_threads) { typedef reviver::dpoint<T, DIM> Point; std::vector<Point> data; std::vector<long unsigned int> bf_ans; data.resize(Size); for(unsigned int i=0;i < data.size();++i) { data[i] = newRandomPoint<Point, T>(min, max); } bruteNN<Point> BF(&data[0], data.size()); sfcnn_knng<Point, DIM, T> SFC(&data[0], data.size(), k, num_threads); for(unsigned int i=0;i < data.size();++i) { BF.ksearch(data[i], k+1, bf_ans); for(unsigned int j=1;j < k+1;++j) { if(bf_ans[j] != SFC[i][j-1]) return false; } } return true; }
static int fuse_read_addr(struct ocotp_priv *priv, u32 addr, u32 *pdata) { u32 ctrl_reg; int ret; writel(OCOTP_CTRL_ERROR, priv->base + OCOTP_CTRL_CLR); ctrl_reg = readl(priv->base + OCOTP_CTRL); ctrl_reg &= ~OCOTP_CTRL_ADDR_MASK; ctrl_reg &= ~OCOTP_CTRL_WR_UNLOCK_MASK; ctrl_reg |= BF(addr, OCOTP_CTRL_ADDR); writel(ctrl_reg, priv->base + OCOTP_CTRL); writel(OCOTP_READ_CTRL_READ_FUSE, priv->base + OCOTP_READ_CTRL); ret = imx6_ocotp_wait_busy(priv, 0); if (ret) return ret; if (readl(priv->base + OCOTP_CTRL) & OCOTP_CTRL_ERROR) *pdata = 0xbadabada; else *pdata = readl(priv->base + OCOTP_READ_FUSE_DATA); return 0; }
Bool NV30EXACheckComposite(int op, PicturePtr psPict, PicturePtr pmPict, PicturePtr pdPict) { nv_pict_surface_format_t *fmt; nv_pict_op_t *opr; opr = NV30_GetPictOpRec(op); if (!opr) NOUVEAU_FALLBACK("unsupported blend op 0x%x\n", op); fmt = NV30_GetPictSurfaceFormat(pdPict->format); if (!fmt) NOUVEAU_FALLBACK("dst picture format 0x%08x not supported\n", pdPict->format); if (!NV30EXACheckCompositeTexture(psPict, pdPict, op)) NOUVEAU_FALLBACK("src picture\n"); if (pmPict) { if (pmPict->componentAlpha && PICT_FORMAT_RGB(pmPict->format) && opr->src_alpha && opr->src_card_op != BF(ZERO)) NOUVEAU_FALLBACK("mask CA + SA\n"); if (!NV30EXACheckCompositeTexture(pmPict, pdPict, op)) NOUVEAU_FALLBACK("mask picture\n"); } return TRUE; }
//BEGIN send::host_list message_udp::send::host_list::host_list(const net::buffer & random, const std::string & local_ID, const std::list<net::endpoint> & hosts) { assert(random.size() == 4); assert(hosts.size() <= protocol_udp::host_list_elements); bit_field BF(16); unsigned cnt = 0; for(std::list<net::endpoint>::const_iterator it_cur = hosts.begin(), it_end = hosts.end(); it_cur != it_end; ++it_cur) { if(it_cur->version() == net::IPv4){ BF[cnt] = 0; }else{ BF[cnt] = 1; } ++cnt; } buf.append(protocol_udp::host_list) .append(random) .append(convert::hex_to_bin(local_ID)) .append(BF.get_buf()); //append addresses for(std::list<net::endpoint>::const_iterator it_cur = hosts.begin(), it_end = hosts.end(); it_cur != it_end; ++it_cur) { buf.append(it_cur->IP_bin()) .append(it_cur->port_bin()); } }
static struct avl_node *_avlInsert(struct avl_node *n, int key) { if(!n) return _avlNewNode(key); if(key < K(n)) { L(n) = _avlInsert(L(n), key); } else { R(n) = _avlInsert(R(n), key); } H(n) = MAX(HH(n->left), HH(n->right)) + 1; int bf = BF(n); if(bf > 1) { if(key > K(L(n))) { // LR case L(n) = _leftRotate(L(n)); } // else LL case return _rightRotate(n); } if(bf < -1) { if(key < K(R(n))) { // RL case R(n) = _rightRotate(R(n)); } // else RR case return _leftRotate(n); } return n; }
bool testNN(unsigned int Size, unsigned int k, T min, T max) { typedef reviver::dpoint<T, DIM> Point; std::vector<Point> data; std::vector<Point> query; std::vector<long unsigned int> sfcnn_ans; std::vector<long unsigned int> bf_ans; data.resize(Size); query.resize(Size); for(unsigned int i=0;i < data.size();++i) { data[i] = newRandomPoint<Point, T>(min, max); query[i] = newRandomPoint<Point, T>(min, max); } bruteNN<Point> BF(&data[0], data.size()); sfcnn<Point, DIM, T> SFC(&data[0], data.size()); for(unsigned int i=0;i < data.size();++i) { BF.ksearch(query[i], k, bf_ans); SFC.ksearch(query[i], k, sfcnn_ans); for(unsigned int j=0;j < Point::__DIM;++j) { if(bf_ans[j] != sfcnn_ans[j]) return false; } } return true; }
bool message_udp::recv::host_list::recv(const net::buffer & recv_buf, const net::endpoint & endpoint) { if(!expect(recv_buf)){ return false; } std::string remote_ID(convert::bin_to_hex(std::string( reinterpret_cast<const char *>(recv_buf.data())+5, 20))); bit_field BF(recv_buf.data()+25, 2, 16); std::list<net::endpoint> hosts; unsigned offset = protocol_udp::host_list_size; for(unsigned x=0; x<16 && offset != recv_buf.size(); ++x){ if(BF[x] == 0){ //IPv4 boost::optional<net::endpoint> ep = net::bin_to_endpoint( recv_buf.str(offset, 4), recv_buf.str(offset + 4, 2)); if(ep){ hosts.push_back(*ep); } offset += 6; }else{ //IPv6 boost::optional<net::endpoint> ep = net::bin_to_endpoint( recv_buf.str(offset, 16), recv_buf.str(offset + 16, 2)); if(ep){ hosts.push_back(*ep); } offset += 18; } } func(endpoint, remote_ID, hosts); return true; }
void DOFInterpolation<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { //Intrepid version: // for (int i=0; i < val_qp.size() ; i++) val_qp[i] = 0.0; // Intrepid::FunctionSpaceTools:: evaluate<ScalarT>(val_qp, val_node, BF); for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { ScalarT& vqp = val_qp(cell,qp); vqp = val_node(cell, 0) * BF(cell, 0, qp); for (std::size_t node=1; node < numNodes; ++node) { vqp += val_node(cell, node) * BF(cell, node, qp); } } } }
void inorder4(node *T) { if(T!=NULL) { inorder4(T->left); printf(" %d(Bf=%d)",T->data,BF(T)); inorder4(T->right); } }
void preorder(node *T) { if(T!=NULL) { printf("%d(Bf=%d) ",T->data,BF(T)); preorder(T->left); preorder(T->right); } }
void FFT::fft8(Complex *z) { float t1, t2, t3, t4, t5, t6, t7, t8; fft4(z); BF(t1, z[5].re, z[4].re, -z[5].re); BF(t2, z[5].im, z[4].im, -z[5].im); BF(t3, z[7].re, z[6].re, -z[7].re); BF(t4, z[7].im, z[6].im, -z[7].im); BF(t8, t1, t3, t1); BF(t7, t2, t2, t4); BF(z[4].re, z[0].re, z[0].re, t1); BF(z[4].im, z[0].im, z[0].im, t2); BF(z[6].re, z[2].re, z[2].re, t7); BF(z[6].im, z[2].im, z[2].im, t8); TRANSFORM(z[1], z[3], z[5], z[7], sqrthalf, sqrthalf); }
void DOFTensorInterpolationBase<EvalT, Traits, ScalarT>:: evaluateFields(typename Traits::EvalData workset) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { for (std::size_t i=0; i<vecDim; i++) { for (std::size_t j=0; j<vecDim; j++) { // Zero out for node==0; then += for node = 1 to numNodes typename PHAL::Ref<ScalarT>::type vqp = val_qp(cell,qp,i,j); vqp = val_node(cell, 0, i, j) * BF(cell, 0, qp); for (std::size_t node=1; node < numNodes; ++node) { vqp += val_node(cell, node, i, j) * BF(cell, node, qp); } } } } } }
void FFT::fft4(Complex *z) { float t1, t2, t3, t4, t5, t6, t7, t8; BF(t3, t1, z[0].re, z[1].re); BF(t8, t6, z[3].re, z[2].re); BF(z[2].re, z[0].re, t1, t6); BF(t4, t2, z[0].im, z[1].im); BF(t7, t5, z[2].im, z[3].im); BF(z[3].im, z[1].im, t4, t8); BF(z[3].re, z[1].re, t3, t7); BF(z[2].im, z[0].im, t2, t5); }
static int otp_write_bits(int addr, u32 data, u32 magic) { u32 c; /* for control register */ /* init the control register */ c = __raw_readl(otp_base + HW_OCOTP_CTRL); c &= ~BM_OCOTP_CTRL_ADDR; c |= BF(addr, OCOTP_CTRL_ADDR); c |= BF(magic, OCOTP_CTRL_WR_UNLOCK); __raw_writel(c, otp_base + HW_OCOTP_CTRL); /* init the data register */ __raw_writel(data, otp_base + HW_OCOTP_DATA); otp_wait_busy(0); mdelay(2); /* Write Postamble */ return 0; }
static void set_otp_timing(void) { unsigned long clk_rate = 0; unsigned long strobe_read, relex, strobe_prog; u32 timing = 0; clk_rate = clk_get_rate(otp_clk); /* do optimization for too many zeros */ relex = clk_rate / (1000000000 / DEF_RELAX) - 1; strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; timing = BF(relex, OCOTP_TIMING_RELAX); timing |= BF(strobe_read, OCOTP_TIMING_STROBE_READ); timing |= BF(strobe_prog, OCOTP_TIMING_STROBE_PROG); __raw_writel(timing, otp_base + HW_OCOTP_TIMING); }
static inline void fft8(FFTComplex *z) { fft4(z); FFTSample t1,t2,t3,t4,t7,t8; BF(t1, z[5].re, z[4].re, -z[5].re); BF(t2, z[5].im, z[4].im, -z[5].im); BF(t3, z[7].re, z[6].re, -z[7].re); BF(t4, z[7].im, z[6].im, -z[7].im); BF(t8, t1, t3, t1); BF(t7, t2, t2, t4); BF(z[4].re, z[0].re, z[0].re, t1); BF(z[4].im, z[0].im, z[0].im, t2); BF(z[6].re, z[2].re, z[2].re, t7); BF(z[6].im, z[2].im, z[2].im, t8); z++; TRANSFORM_EQUAL(z,2); }
void inorder(node *T) { if(T!=NULL) { inorder(T->left); printf("%d ",T->data,BF(T)); inorder(T->right); } }
static void fft4(FFTComplex *z) { FFTSample t1, t2, t3, t4, t5, t6, t7, t8; BF(t3, t1, z[0].re, z[1].re); BF(t8, t6, z[3].re, z[2].re); BF(z[2].re, z[0].re, t1, t6); BF(t4, t2, z[0].im, z[1].im); BF(t7, t5, z[2].im, z[3].im); BF(z[3].im, z[1].im, t4, t8); BF(z[3].re, z[1].re, t3, t7); BF(z[2].im, z[0].im, t2, t5); }