// This test goes from text ASM to binary to text ASM and once again back to binary. // Very convenient for testing. Then the two binaries are compared. bool SuperTrip(const char *asm_code) { std::vector<u16> code1, code2; std::string text; if (!Assemble(asm_code, code1)) { printf("SuperTrip: First assembly failed\n"); return false; } printf("First assembly: %i words\n", (int)code1.size()); if (!Disassemble(code1, false, text)) { printf("SuperTrip: Disassembly failed\n"); return false; } else { printf("Disass:\n"); printf("%s", text.c_str()); } if (!Assemble(text.c_str(), code2)) { printf("SuperTrip: Second assembly failed\n"); return false; } /* std::string text2; Disassemble(code1, true, &text1); Disassemble(code2, true, &text2); File::WriteStringToFile(text1, "code1.txt"); File::WriteStringToFile(text2, "code2.txt"); */ return true; }
static void resolveStubWithBranch(void *stub, const void *loc) { ARM_INSTRUCTION movt; ARM_INSTRUCTION movw; ARM_INSTRUCTION jmp; movw.condition = ARM_CONDITION_ALWAYS; movw.type = ARM_MOV_INSTRUCTION; movw.instruction = ARM_INST_MOVW; movw.argCount = 2; movw.value[0] = ARM_R12; movw.value[1] = (SceUInt16)((SceUInt)loc & 0xFFFF); movt.condition = ARM_CONDITION_ALWAYS; movt.type = ARM_MOV_INSTRUCTION; movt.instruction = ARM_INST_MOVT; movt.argCount = 2; movt.value[0] = ARM_R12; movt.value[1] = (SceUInt16)((SceUInt)loc >> 16); //Only the top part jmp.condition = ARM_CONDITION_ALWAYS; jmp.type = ARM_BRANCH_INSTRUCTION; jmp.instruction = ARM_INST_BX; jmp.argCount = 1; jmp.value[0] = ARM_R12; Assemble(&movw, &((SceUInt*)stub)[0]); Assemble(&movt, &((SceUInt*)stub)[1]); Assemble(&jmp, &((SceUInt*)stub)[2]); }
static void resolveStubWithSvc(void *stub, SceUInt n) { ARM_INSTRUCTION movw; ARM_INSTRUCTION svc; ARM_INSTRUCTION jmp; movw.condition = ARM_CONDITION_ALWAYS; movw.type = ARM_MOV_INSTRUCTION; movw.instruction = ARM_INST_MOVW; movw.argCount = 2; movw.value[0] = ARM_R12; movw.value[1] = (SceUInt16)n; svc.condition = ARM_CONDITION_ALWAYS; svc.type = ARM_SVC_INSTRUCTION; svc.instruction = ARM_INST_SVC; svc.argCount = 1; svc.value[0] = 0; jmp.condition = ARM_CONDITION_ALWAYS; jmp.type = ARM_BRANCH_INSTRUCTION; jmp.instruction = ARM_INST_BX; jmp.argCount = 1; jmp.value[0] = ARM_R14; Assemble(&movw, &((SceUInt*)stub)[0]); Assemble(&svc, &((SceUInt*)stub)[1]); Assemble(&jmp, &((SceUInt*)stub)[2]); }
/* assembles lists of line strips from the given track recursively traversing the subtracks data */ void Track::Assemble(std::list< std::list<wxPoint> > &pointlists, const LLBBox &box, double scale, int &last, int level, int pos) { if(pos == (int)SubTracks[level].size()) return; SubTrack &s = SubTracks[level][pos]; if(box.IntersectOut(s.m_box)) return; if(s.m_scale < scale) { pos <<= level; if(last < pos - 1) { std::list<wxPoint> new_list; pointlists.push_back(new_list); } if(last < pos) AddPointToList(pointlists, pos); last = wxMin(pos + (1<<level), TrackPoints.size() - 1); AddPointToList(pointlists, last); } else { Assemble(pointlists, box, scale, last, level-1, pos<<1); Assemble(pointlists, box, scale, last, level-1, (pos<<1)+1); } }
int main(int argc, char **argv){ SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); int N[3] = {20, 25, 1}, Npml[3] = {5, 7, 0}, Nc = 2, b[3][2] = {{-1, 0}, {1, 0}, {0, 0}}, LowerPML = 0, BCPeriod = 3; double h[3] = {0.2, 0.3, 0.1}; int i, Nxyzr = 2*N[0]*N[1]*N[2]; double sigma[3], *muinv; Vec muinvpml; muinv = (double *) malloc(sizeof(double)*3*Nxyzr ); for(i=0; i<3; i++) sigma[i] = pmlsigma(1e-25, Npml[i]*h[i]); MuinvPMLFull(PETSC_COMM_SELF, &muinvpml, N[0], N[1], N[2], Npml[0], Npml[1], Npml[2], sigma[0], sigma[1], sigma[2], 1.0, LowerPML); AddMuAbsorption(muinv, muinvpml, 1e25, 0); VecDestroy(&muinvpml); Mat Moperator; MatCreateAIJ(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, Nc*Nxyzr, Nc*Nxyzr, 26, NULL, 26, NULL, &Moperator); MoperatorGeneralFill(Moperator, N[0], N[1], N[2], h[0], h[1], h[2], b[0], b[1], b[2], muinv, BCPeriod, 0, Nc); Assemble(Moperator); PetscObjectSetName((PetscObject) Moperator, "M"); OutputMat(PETSC_COMM_WORLD, Moperator, filenameComm, "M.m"); SlepcFinalize(); return 0; }
void elasticitySolver::solve() { std::string sysname = "A"; if(pAssembler && pAssembler->getLinearSystem(sysname)) delete pAssembler->getLinearSystem(sysname); #if defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; #elif defined(HAVE_GMM) linearSystemCSRGmm<double> *lsys = new linearSystemCSRGmm<double>; #else linearSystemFull<double> *lsys = new linearSystemFull<double>; #endif assemble(lsys); // printLinearSystem(lsys,pAssembler->sizeOfR()); lsys->systemSolve(); printf("-- done solving!\n"); double energ = 0; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for(std::size_t i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field, elasticFields[i]._e, elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, energ); } printf("elastic energy=%f\n", energ); }
void elasticitySolver::solve() { //linearSystemFull<double> *lsys = new linearSystemFull<double>; #if defined(HAVE_TAUCS) linearSystemCSRTaucs<double> *lsys = new linearSystemCSRTaucs<double>; #elif defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; #else linearSystemGmm<double> *lsys = new linearSystemGmm<double>; lsys->setNoisy(2); #endif assemble(lsys); lsys->systemSolve(); printf("-- done solving!\n"); GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); // printLinearSystem(lsys); double energ=0; for (unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term,elasticFields[i].g->begin(),elasticFields[i].g->end(), Integ_Bulk,energ); } printf("elastic energy=%f\n",energ); }
GLboolean evergreenSetupVertexProgram(struct gl_context * ctx) { context_t *context = EVERGREEN_CONTEXT(ctx); EVERGREEN_CHIP_CONTEXT *evergreen = GET_EVERGREEN_CHIP(context); struct evergreen_vertex_program *vp = (struct evergreen_vertex_program *) context->selected_vp; if(GL_FALSE == vp->loaded) { if(vp->r700Shader.bNeedsAssembly == GL_TRUE) { Assemble( &(vp->r700Shader) ); } /* Load vp to gpu */ r600EmitShader(ctx, &(vp->shaderbo), (GLvoid *)(vp->r700Shader.pProgram), vp->r700Shader.uShaderBinaryDWORDSize, "VS"); vp->loaded = GL_TRUE; } EVERGREEN_STATECHANGE(context, vs); /* TODO : enable this after MemUse fixed *= (context->chipobj.MemUse)(context, vp->shadercode.buf->id); */ evergreen->SQ_PGM_RESOURCES_VS.u32All = 0; SETbit(evergreen->SQ_PGM_RESOURCES_VS.u32All, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit); evergreen->vs.SQ_ALU_CONST_CACHE_VS_0.u32All = 0; /* set from buffer object. */ evergreen->vs.SQ_PGM_START_VS.u32All = 0; SETfield(evergreen->SQ_PGM_RESOURCES_VS.u32All, vp->r700Shader.nRegs + 1, NUM_GPRS_shift, NUM_GPRS_mask); if(vp->r700Shader.uStackSize) /* we don't use branch for now, it should be zero. */ { SETfield(evergreen->SQ_PGM_RESOURCES_VS.u32All, vp->r700Shader.uStackSize, STACK_SIZE_shift, STACK_SIZE_mask); } EVERGREEN_STATECHANGE(context, spi); SETfield(evergreen->SPI_VS_OUT_CONFIG.u32All, vp->r700Shader.nParamExports ? (vp->r700Shader.nParamExports - 1) : 0, VS_EXPORT_COUNT_shift, VS_EXPORT_COUNT_mask); SETfield(evergreen->SPI_PS_IN_CONTROL_0.u32All, vp->r700Shader.nParamExports, NUM_INTERP_shift, NUM_INTERP_mask); /* SETbit(evergreen->SPI_PS_IN_CONTROL_0.u32All, PERSP_GRADIENT_ENA_bit); CLEARbit(evergreen->SPI_PS_IN_CONTROL_0.u32All, LINEAR_GRADIENT_ENA_bit); */ return GL_TRUE; }
// Entry to recursive Assemble at the head of the SubTracks tree void Track::Segments(std::list< std::list<wxPoint> > &pointlists, const LLBBox &box, double scale) { if(!SubTracks.size()) return; int level = SubTracks.size()-1, last = -2; Assemble(pointlists, box, 1/scale/scale, last, level, 0); }
int main(int argc,char *argv[]) { PetscErrorCode ierr; MPI_Comm comm; PetscMPIInt size; ierr = PetscInitialize(&argc,&argv,NULL,help);CHKERRQ(ierr); comm = PETSC_COMM_WORLD; ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); if (size != 2) SETERRQ(comm,PETSC_ERR_USER,"This example must be run with exactly two processes"); ierr = Assemble(comm,2,MATMPIBAIJ);CHKERRQ(ierr); ierr = Assemble(comm,2,MATMPISBAIJ);CHKERRQ(ierr); ierr = Assemble(comm,1,MATMPIBAIJ);CHKERRQ(ierr); ierr = Assemble(comm,1,MATMPISBAIJ);CHKERRQ(ierr); ierr = PetscFinalize();CHKERRQ(ierr); return 0; }
int Assembl(char *answer,ulong parm) { int i,j,k,n,good; char s[TEXTLEN]; t_asmmodel model,attempt; t_memory *pmem; t_dump *pasm; // Visualize changes. Setcpu(0,address,0,0,CPU_ASMHIST|CPU_ASMCENTER); if (string[0]=='\0') // No immediate command Sendshortcut(PM_DISASM,address,WM_CHAR,0,0,' '); else { // Assemble immediate command. If there are several possible encodings, // select the shortest one. model.length=0; for (j=0; ; j++) { // Try all possible encodings good=0; for (k=0; k<4; k++) { // Try all possible constant sizes n=Assemble(string,address,&attempt,j,k,model.length==0?answer:s); if (n>0) { good=1; // If another decoding is found, check if it is shorter. if (model.length==0 || n<model.length) model=attempt; // Shortest encoding so far ; }; }; if (good==0) break; // No more encodings }; if (model.length==0) return -1; // Invalid command // Check for imprecise parameters. k=model.mask[0]; for (i=1; i<model.length; i++) k&=model.mask[i]; if (k!=0xFF) { strcpy(answer,"Command contains imprecise operands"); return -1; }; // If there is no backup copy, create it. Dump window always assumes that // backup has the same base and size as the dump, so check it to avoid // strange ireproducible errors. pmem=Findmemory(address); if (pmem==NULL) { //strcpy(answer,"Attempt to assemble to non-existing memory"); wsprintf(answer,"%X",model.code[0]); for(i=1; i<model.length; i++) { wsprintf(answer,"%s%X",answer,model.code[i]); } return -1; }; pasm=(t_dump *)Plugingetvalue(VAL_CPUDASM); if (pasm!=NULL && pmem->copy==NULL && pmem->base==pasm->base && pmem->size==pasm->size) Dumpbackup(pasm,BKUP_CREATE); // Now write assembled code to memory. Writememory(model.code,address,model.length,MM_RESTORE|MM_DELANAL); }; return 0; };
// // Solves the problem (WITHOUT adaptation) // void OdeProb::Solve() { // // Writes mesh on the screan // for(size_t m = 0; m < m_elt.size(); m++) // m_elt[m].Write(stdout); Malloc(); Assemble(); m_s->SolveSymPos(*m_b, *m_y); // m_y->Write("Ysol.dat"); }
bool ArpParser::Parse(const unsigned char* head, const unsigned int len) { if (head == NULL || len <= ARP_MIN_LEN) { return false; } header_length_ = len; body_length_ = 0; header_ = head; body_ = NULL; hardware_type_ = Assemble(head[0], head[1]); protocol_type_ = Assemble(head[2], head[3]); hardware_len_ = head[4]; protocol_len_ = head[5]; op_ = Assemble(head[6], head[7]); sender_mac_.set_addr(head + 8); sender_ip_.set_addr(AssembleUint32(head + 14)); recver_mac_.set_addr(head + 18); recver_ip_.set_addr(AssembleUint32(head + 24)); return true; }
int main(int argc,char *argv[]) { PetscErrorCode ierr; MPI_Comm comm; PetscInt n = 6; ierr = PetscInitialize(&argc,&argv,NULL,help);CHKERRQ(ierr); comm = PETSC_COMM_WORLD; ierr = PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);CHKERRQ(ierr); ierr = Assemble(comm,n,MATMPISBAIJ);CHKERRQ(ierr); ierr = PetscFinalize();CHKERRQ(ierr); return 0; }
static int assemble(struct r_asm_t *a, struct r_asm_op_t *op, const char *buf) { char buf_err[128]; static t_asmmodel asm_obj; int attempt, constsize, oattempt = 0, oconstsize = 0, ret = 0, oret = 0xCAFE; /* attempt == 0: First attempt */ /* constsize == 0: Address constants and inmediate data of 16/32b */ for (constsize = 0; constsize < 4; constsize++) { for (attempt = 0; ret > 0; attempt++) { ret = Assemble((char*)buf, a->pc, &asm_obj, attempt, constsize, buf_err); if (ret > 0 && ret < oret) { oret = ret; oattempt = attempt; oconstsize = constsize; } } } op->size = R_MAX (0, Assemble((char*)buf, a->pc, &asm_obj, oattempt, oconstsize, buf_err)); if (op->size > 0) memcpy (op->buf, asm_obj.code, R_MIN(op->size, (R_ASM_BUFSIZE-1))); return op->size; }
// FIXME : add this as a member of SkPath void Simplify(const SkPath& path, SkPath* result) { #if DEBUG_SORT || DEBUG_SWAP_TOP gDebugSortCount = gDebugSortCountDefault; #endif // returns 1 for evenodd, -1 for winding, regardless of inverse-ness result->reset(); result->setFillType(SkPath::kEvenOdd_FillType); SkPathWriter simple(*result); // turn path into list of segments SkTArray<SkOpContour> contours; SkOpEdgeBuilder builder(path, contours); builder.finish(); SkTDArray<SkOpContour*> contourList; MakeContourList(contours, contourList, false, false); SkOpContour** currentPtr = contourList.begin(); if (!currentPtr) { return; } SkOpContour** listEnd = contourList.end(); // find all intersections between segments do { SkOpContour** nextPtr = currentPtr; SkOpContour* current = *currentPtr++; if (current->containsCubics()) { AddSelfIntersectTs(current); } SkOpContour* next; do { next = *nextPtr++; } while (AddIntersectTs(current, next) && nextPtr != listEnd); } while (currentPtr != listEnd); // eat through coincident edges CoincidenceCheck(&contourList, 0); FixOtherTIndex(&contourList); SortSegments(&contourList); #if DEBUG_ACTIVE_SPANS DebugShowActiveSpans(contourList); #endif // construct closed contours if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &simple) : !bridgeXor(contourList, &simple)) { // if some edges could not be resolved, assemble remaining fragments SkPath temp; temp.setFillType(SkPath::kEvenOdd_FillType); SkPathWriter assembled(temp); Assemble(simple, &assembled); *result = *assembled.nativePath(); } }
void elasticitySolver::postSolve() { GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); double energ=0; for (unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, energ); } printf("elastic energy=%f\n",energ); }
void ContField1D::MultiplyByInvMassMatrix( const Array<OneD, const NekDouble> &inarray, Array<OneD, NekDouble> &outarray, CoeffState coeffstate) { GlobalLinSysKey key(StdRegions::eMass, m_locToGloMap); if(coeffstate == eGlobal) { if(inarray.data() == outarray.data()) { Array<OneD, NekDouble> tmp(inarray); GlobalSolve(key,tmp,outarray); } else { GlobalSolve(key,inarray,outarray); } } else { Array<OneD, NekDouble> globaltmp(m_ncoeffs,0.0); if(inarray.data() == outarray.data()) { Array<OneD,NekDouble> tmp(inarray); Assemble(tmp,outarray); } else { Assemble(inarray,outarray); } GlobalSolve(key,outarray,globaltmp); GlobalToLocal(globaltmp,outarray); } }
int LineAsm(char *answer,ulong parm) { int i,j,k,n,good; char s[TEXTLEN],*p; t_asmmodel model,attempt; char *stop; p = strstr(string,";"); if(p) { *p = '\0'; p++; address = strtoul(p,&stop,16); } // Assemble immediate command. If there are several possible encodings, // select the shortest one. model.length=0; for(j=0; ; j++) { // Try all possible encodings good=0; for (k=0; k<4; k++) { // Try all possible constant sizes n=Assemble(string,address,&attempt,j,k,model.length==0?answer:s); if (n>0) { good=1; // If another decoding is found, check if it is shorter. if (model.length==0 || n<model.length) model=attempt; // Shortest encoding so far ; }; }; if (good==0) break; // No more encodings }; if (model.length==0) return -1; // Invalid command // Check for imprecise parameters. k=model.mask[0]; for(i=1; i<model.length; i++) { k&=model.mask[i]; } if(k!=0xFF) { strcpy(answer,"Command contains imprecise operands"); return -1; }; // If there is no backup copy, create it. Dump window always assumes that // backup has the same base and size as the dump, so check it to avoid // strange ireproducible errors. wsprintf(answer,"%02X",model.code[0]); for(i=1; i<model.length; i++) { wsprintf(answer,"%s%02X",answer,model.code[i]); } return -1; };
/** * The operation is evaluated locally (i.e. with respect to all local * expansion modes) by the function ExpList#IProductWRTBase. The inner * product with respect to the global expansion modes is than obtained * by a global assembly operation. * * The values of the function \f$f(x)\f$ evaluated at the quadrature * points \f$x_i\f$ should be contained in the variable #m_phys of the * ExpList object \a in. The result is stored in the array * #m_coeffs. * * @param In An ExpList, containing the discrete evaluation * of \f$f(x)\f$ at the quadrature points in its * array #m_phys. */ void ContField1D::IProductWRTBase( const Array<OneD, const NekDouble> &inarray, Array<OneD, NekDouble> &outarray, CoeffState coeffstate) { if(coeffstate == eGlobal) { Array<OneD, NekDouble> wsp(m_ncoeffs); IProductWRTBase_IterPerExp(inarray,wsp); Assemble(wsp,outarray); } else { IProductWRTBase_IterPerExp(inarray,outarray); } }
/** * This is equivalent to the operation: * \f[\boldsymbol{M\hat{u}}_g\f] * where \f$\boldsymbol{M}\f$ is the global matrix of type specified by * \a mkey. After scattering the global array \a inarray to local * level, this operation is evaluated locally by the function * ExpList#GeneralMatrixOp. The global result is then obtained by a * global assembly procedure. * * @param mkey This key uniquely defines the type matrix * required for the operation. * @param inarray The vector \f$\boldsymbol{\hat{u}}_g\f$ of size * \f$N_{\mathrm{dof}}\f$. * @param outarray The resulting vector of size * \f$N_{\mathrm{dof}}\f$. */ void ContField1D::v_GeneralMatrixOp( const GlobalMatrixKey &gkey, const Array<OneD,const NekDouble> &inarray, Array<OneD, NekDouble> &outarray, CoeffState coeffstate) { if(coeffstate == eGlobal) { Array<OneD,NekDouble> tmp1(2*m_ncoeffs); Array<OneD,NekDouble> tmp2(tmp1+m_ncoeffs); GlobalToLocal(inarray,tmp1); GeneralMatrixOp_IterPerExp(gkey,tmp1,tmp2); Assemble(tmp2,outarray); } else { GeneralMatrixOp_IterPerExp(gkey,inarray,outarray); } }
// This test goes from text ASM to binary to text ASM and once again back to binary. // Then the two binaries are compared. bool RoundTrip(const std::vector<u16> &code1) { std::vector<u16> code2; std::string text; if (!Disassemble(code1, false, text)) { printf("RoundTrip: Disassembly failed.\n"); return false; } if (!Assemble(text.c_str(), code2)) { printf("RoundTrip: Assembly failed.\n"); return false; } if (!Compare(code1, code2)) { Disassemble(code1, true, text); printf("%s", text.c_str()); } return true; }
void InitTkPopLGP() { unsigned int i, j, nInstrs, nTkIndivs, step, qIdx; static unsigned int genomeLen; struct tkIndiv *tkIndivs; nTkIndivs = 10 * popSize; genomeLen = qIndivLen * 2; tkIndivs = malloc(nTkIndivs * sizeof(struct tkIndiv)); for (i = 0; i < nTkIndivs; i++) { tkIndivs[i].genome = malloc(qIndivLen * sizeof(int) * 2); for (j = 0; j < genomeLen; j++) { tkIndivs[i].genome[j] = 0; } //nInstrs = (rand() % (qIndivLen - 19) + 20); // E=0.1555!!! nInstrs = ((rand() % 40) + 20); step = 1 + (qIndivLen - nInstrs) / (nInstrs + 1); for (j = step - 1; j < genomeLen; j += step) { qIdx = j * 2; tkIndivs[i].genome[qIdx] = (rand() % (nFuncs - 1)) + 1; tkIndivs[i].genome[qIdx + 1] = rand() % termsCardins[tkIndivs[i].genome[qIdx]]; } Assemble(&tkIndivs[i]); tkIndivs[i].fitness = EvalIndivFunc(trainingData, nSamplesTrain, &tkIndivs[i]); } InsertSort(tkIndivs, nTkIndivs); for (i = 0; i < popSize; i++) { CopyTkIndiv(&tkPop[i], &tkIndivs[i]); //tkPop[i] = tkIndivs[i]; } }
int main(int argc, char *argv[]) { struct mddev_ident *array_list = conf_get_ident(NULL); if (!array_list) { fprintf(stderr, Name ": No arrays found in config file\n"); rv = 1; } else for (; array_list; array_list = array_list->next) { mdu_array_info_t array; if (strcasecmp(array_list->devname, "<ignore>") == 0) continue; mdfd = open_mddev(array_list->devname, 0); if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) { rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */ continue; } if (mdfd >= 0) close(mdfd); rv |= Assemble(array_list->st, array_list->devname, array_list, NULL, NULL, 0, readonly, runstop, NULL, NULL, 0, verbose, force); } return rv; }
int main(int argc, char *argv[]) { struct mddev_ident *array_list = conf_get_ident(NULL); struct context c = { .freeze_reshape = 1 }; if (!array_list) { pr_err("No arrays found in config file\n"); rv = 1; } else for (; array_list; array_list = array_list->next) { mdu_array_info_t array; if (strcasecmp(array_list->devname, "<ignore>") == 0) continue; mdfd = open_mddev(array_list->devname, 0); if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) { rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */ continue; } if (mdfd >= 0) close(mdfd); rv |= Assemble(array_list->st, array_list->devname, array_list, NULL, &c); } return rv; }
void elasticitySolver::assemble(linearSystem<double> *lsys) { if (pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to // give priority to fixations : when a dof is fixed, it cannot be // numbered afterwards // Dirichlet conditions for (unsigned int i = 0; i < allDirichlet.size(); i++) { FilterDofComponent filter(allDirichlet[i]._comp); FixNodalDofs(*LagSpace,allDirichlet[i].g->begin(),allDirichlet[i].g->end(), *pAssembler,*allDirichlet[i]._f,filter); } // LagrangeMultipliers for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { NumberDofs(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Elastic Fields for (unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E != 0.) NumberDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Voids for (unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) FixVoidNodalDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); for (unsigned int i = 0; i < allNeumann.size(); i++) { LoadTerm<SVector3> Lterm(*LagSpace,*allNeumann[i]._f); Assemble(Lterm,*LagSpace,allNeumann[i].g->begin(),allNeumann[i].g->end(), Integ_Boundary,*pAssembler); } // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { LagrangeMultiplierTerm LagTerm(*LagSpace, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._d); Assemble(LagTerm, *LagSpace, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, *pAssembler); LaplaceTerm<double,double> LapTerm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._tau); Assemble(LapTerm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); LoadTerm<double> Lterm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._f); Assemble(Lterm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble elastic term for GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < elasticFields.size(); i++) { IsotropicElasticTerm Eterm(*LagSpace,elasticFields[i]._E,elasticFields[i]._nu); Assemble(Eterm,*LagSpace,elasticFields[i].g->begin(),elasticFields[i].g->end(), Integ_Bulk,*pAssembler); } /*for (int i=0;i<pAssembler->sizeOfR();i++){ for (int j=0;j<pAssembler->sizeOfR();j++){ double d;lsys->getFromMatrix(i,j,d); printf("%12.5E ",d); } double d;lsys->getFromRightHandSide(i,d); printf(" | %12.5E\n",d); }*/ printf("nDofs=%d\n",pAssembler->sizeOfR()); printf("nFixed=%d\n",pAssembler->sizeOfF()); }
GLboolean r700SetupVertexProgram(struct gl_context * ctx) { context_t *context = R700_CONTEXT(ctx); R700_CHIP_CONTEXT *r700 = (R700_CHIP_CONTEXT*)(&context->hw); struct r700_vertex_program *vp = context->selected_vp; struct gl_program_parameter_list *paramList; unsigned int unNumParamData; unsigned int ui; if(GL_FALSE == vp->loaded) { if(vp->r700Shader.bNeedsAssembly == GL_TRUE) { Assemble( &(vp->r700Shader) ); } /* Load vp to gpu */ r600EmitShader(ctx, &(vp->shaderbo), (GLvoid *)(vp->r700Shader.pProgram), vp->r700Shader.uShaderBinaryDWORDSize, "VS"); if(GL_TRUE == r700->bShaderUseMemConstant) { paramList = vp->mesa_program->Base.Parameters; if(NULL != paramList) { unNumParamData = paramList->NumParameters; r600AllocShaderConsts(ctx, &(vp->constbo0), unNumParamData *4*4, "VSCON"); } } vp->loaded = GL_TRUE; } DumpHwBinary(DUMP_VERTEX_SHADER, (GLvoid *)(vp->r700Shader.pProgram), vp->r700Shader.uShaderBinaryDWORDSize); /* TODO : enable this after MemUse fixed *= (context->chipobj.MemUse)(context, vp->shadercode.buf->id); */ R600_STATECHANGE(context, vs); R600_STATECHANGE(context, fs); /* hack */ r700->vs.SQ_PGM_RESOURCES_VS.u32All = 0; SETbit(r700->vs.SQ_PGM_RESOURCES_VS.u32All, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit); r700->vs.SQ_ALU_CONST_CACHE_VS_0.u32All = 0; /* set from buffer object. */ r700->vs.SQ_PGM_START_VS.u32All = 0; SETfield(r700->vs.SQ_PGM_RESOURCES_VS.u32All, vp->r700Shader.nRegs + 1, NUM_GPRS_shift, NUM_GPRS_mask); if(vp->r700Shader.uStackSize) /* we don't use branch for now, it should be zero. */ { SETfield(r700->vs.SQ_PGM_RESOURCES_VS.u32All, vp->r700Shader.uStackSize, STACK_SIZE_shift, STACK_SIZE_mask); } R600_STATECHANGE(context, spi); if(vp->mesa_program->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) { R600_STATECHANGE(context, cl); SETbit(r700->PA_CL_VS_OUT_CNTL.u32All, USE_VTX_POINT_SIZE_bit); SETbit(r700->PA_CL_VS_OUT_CNTL.u32All, VS_OUT_MISC_VEC_ENA_bit); } else if (r700->PA_CL_VS_OUT_CNTL.u32All != 0) { R600_STATECHANGE(context, cl); CLEARbit(r700->PA_CL_VS_OUT_CNTL.u32All, USE_VTX_POINT_SIZE_bit); CLEARbit(r700->PA_CL_VS_OUT_CNTL.u32All, VS_OUT_MISC_VEC_ENA_bit); } SETfield(r700->SPI_VS_OUT_CONFIG.u32All, vp->r700Shader.nParamExports ? (vp->r700Shader.nParamExports - 1) : 0, VS_EXPORT_COUNT_shift, VS_EXPORT_COUNT_mask); SETfield(r700->SPI_PS_IN_CONTROL_0.u32All, vp->r700Shader.nParamExports, NUM_INTERP_shift, NUM_INTERP_mask); /* SETbit(r700->SPI_PS_IN_CONTROL_0.u32All, PERSP_GRADIENT_ENA_bit); CLEARbit(r700->SPI_PS_IN_CONTROL_0.u32All, LINEAR_GRADIENT_ENA_bit); */ /* sent out shader constants. */ paramList = vp->mesa_program->Base.Parameters; if(NULL != paramList) { /* vp->mesa_program was cloned, not updated by glsl shader api. */ /* _mesa_reference_program has already checked glsl shProg is ok and set ctx->VertexProgem._Current */ /* so, use ctx->VertexProgem._Current */ struct gl_program_parameter_list *paramListOrginal = ctx->VertexProgram._Current->Base.Parameters; _mesa_load_state_parameters(ctx, paramList); if (paramList->NumParameters > R700_MAX_DX9_CONSTS) return GL_FALSE; R600_STATECHANGE(context, vs_consts); r700->vs.num_consts = paramList->NumParameters; unNumParamData = paramList->NumParameters; for(ui=0; ui<unNumParamData; ui++) { if(paramList->Parameters[ui].Type == PROGRAM_UNIFORM) { r700->vs.consts[ui][0].f32All = paramListOrginal->ParameterValues[ui][0]; r700->vs.consts[ui][1].f32All = paramListOrginal->ParameterValues[ui][1]; r700->vs.consts[ui][2].f32All = paramListOrginal->ParameterValues[ui][2]; r700->vs.consts[ui][3].f32All = paramListOrginal->ParameterValues[ui][3]; } else { r700->vs.consts[ui][0].f32All = paramList->ParameterValues[ui][0]; r700->vs.consts[ui][1].f32All = paramList->ParameterValues[ui][1]; r700->vs.consts[ui][2].f32All = paramList->ParameterValues[ui][2]; r700->vs.consts[ui][3].f32All = paramList->ParameterValues[ui][3]; } } /* Load vp constants to gpu */ if(GL_TRUE == r700->bShaderUseMemConstant) { r600EmitShaderConsts(ctx, vp->constbo0, 0, (GLvoid *)&(r700->vs.consts[0][0]), unNumParamData * 4 * 4); } } else r700->vs.num_consts = 0; COMPILED_SUB * pCompiledSub; GLuint uj; GLuint unConstOffset = r700->vs.num_consts; for(ui=0; ui<vp->r700AsmCode.unNumPresub; ui++) { pCompiledSub = vp->r700AsmCode.presubs[ui].pCompiledSub; r700->vs.num_consts += pCompiledSub->NumParameters; for(uj=0; uj<pCompiledSub->NumParameters; uj++) { r700->vs.consts[uj + unConstOffset][0].f32All = pCompiledSub->ParameterValues[uj][0]; r700->vs.consts[uj + unConstOffset][1].f32All = pCompiledSub->ParameterValues[uj][1]; r700->vs.consts[uj + unConstOffset][2].f32All = pCompiledSub->ParameterValues[uj][2]; r700->vs.consts[uj + unConstOffset][3].f32All = pCompiledSub->ParameterValues[uj][3]; } unConstOffset += pCompiledSub->NumParameters; } return GL_TRUE; }
int main(int argc, char ** argv) { char * binfilename = NULL; char * srcfilename = NULL; char * base = NULL; int i, cycle; bus32 tmp; bus8 inst_mem[4096]; /* instruction memory */ bus8 main_mem[4096]; /* main memory */ bus32 gnd; /* ground bus signal */ bus32 pc; /* program counter */ bus32 pc4; /* PC + 4 bus */ bus32 ir; /* instruction register */ bus32 jmp_addr; /* jump bus */ bus32 imm_sext; /* immediate sign extended bus */ bus32 imm_shext; /* immediate sign extended shifted bus */ bus32 branch_addr; /* branch bus */ bus32 mbranch_addr; /* mbranch bus */ /* control unit signals */ wire reg_write, reg_dest; wire mem_read, mem_write, mem_toreg; wire jump, branch; wire alu_src; bus3 alu_op; /* register memory signals & controls */ bus32 reg_in, reg_out1, reg_out2; bus32 reg_write_addr; /* main memory signal */ bus32 mem_out; /* alu signals */ wire zero; bus32 alu_src_val, alu_out; if (argc == 1) { fprintf(stderr, "usage: %s <filename>\n", argv[0]); return -1; } srcfilename = argv[1]; base = _parse_filename(srcfilename); if (!base) return -1; binfilename = malloc(sizeof(char) * (strlen(base) + 5)); sprintf(binfilename, "%s.bin", base); printf("assembling %s to %s...\n", srcfilename, binfilename); if (!Assemble(srcfilename, binfilename)) return -1; printf("loading %s into memory...\n", binfilename); LoadMemory(binfilename, inst_mem); /* load PC with initial VM address of 0x00000000 */ setbus32(gnd, "00000000000000000000000000000000"); setbus32(pc, gnd); /* initialize memory */ InitializeRegisterFileAccess(); for (i=0; i < 4096; i++) setbus8(main_mem[i], "00000000"); for(cycle=0; ; cycle++) { /* load IR with PC value */ MemoryAccess(ir, pc, gnd, '0', inst_mem); /* report fetched register values */ printf("cycle: %d, PC: %.32s (%d), IR: %.32s\n\t", cycle, pc, bus32toint(pc), ir); /* halt check */ if (bus32toint(ir) == 0x0000003F) { printf("\nmachine halted\n"); break; } /* PC + 4 data path */ RCAdder_32(pc4, gnd, pc, "00000000000000000000000000000100", '0'); /* jump data path */ shiftleft2x(jmp_addr, ir); jmp_addr[0] = pc4[0]; jmp_addr[1] = pc4[1]; jmp_addr[2] = pc4[2]; jmp_addr[3] = pc4[3]; /* sign extended / shifted immediate data path */ signextend(imm_sext, &ir[16]); shiftleft2x(imm_shext, imm_sext); /* control unit data path */ ControlUnit(ir, &ir[26], ®_write, ®_dest, &mem_read, &mem_write, &mem_toreg, &jump, &branch, &alu_src, alu_op); /* register memory data path - read */ Mux2_5(reg_write_addr, &ir[11], &ir[16], reg_dest); RegisterFileAccess(®_out1, ®_out2, &ir[6], &ir[11], reg_write_addr, reg_in, '0'); /* alu data path */ Mux2_32(alu_src_val, reg_out2, imm_sext, alu_src); zero = ALU(&alu_out, reg_out1, alu_src_val, alu_op); /* branch data path */ RCAdder_32(branch_addr, gnd, pc4, imm_shext, '0'); Mux2_32(mbranch_addr, pc4, branch_addr, AND2_1(zero, branch)); Mux2_32(pc, mbranch_addr, jmp_addr, jump); /* main memory data path */ MemoryAccess(mem_out, alu_out, reg_out2, mem_write, main_mem); Mux2_32(reg_in, alu_out, mem_out, mem_toreg); /* register memory data path - write */ RegisterFileAccess(®_out1, ®_out2, &ir[6], &ir[11], reg_write_addr, reg_in, reg_write); /* dump register memory and signal information */ for (i=0; i < 14; i++) { inttobusn(i, 5, tmp); RegisterFileAccess(®_out1, ®_out2, tmp, &ir[11], reg_write_addr, reg_in, '0'); printf("R%d: %d, ", i, bus32toint(reg_out1)); } printf("\b\b\n\tbranch_addr = %.32s (%d) jmp_addr = %.32s (%d)\n", branch_addr, bus32toint(branch_addr), jmp_addr, bus32toint(jmp_addr)); printf("\topcode = %.6s, imm_sext = %.32s (%d), imm_shext = %.32s (%d), PC+4 = %.32s (%d)\n", ir, imm_sext, bus32toint(imm_sext), imm_shext, bus32toint(imm_shext), pc4, bus32toint(pc4)); printf("\treg_write = %c, reg_dest = %c, mem_read = %c, mem_write = %c, mem_toreg = %c, jump = %c, branch = %c, alu_src = %c, alu_op = %.3s, zero = %c\n", reg_write, reg_dest, mem_read, mem_write, mem_toreg, jump, branch, alu_src, alu_op, zero); getchar(); } printf("\ntotal no. cycles: %d\n", cycle); // report end of program information free(binfilename); }
void main(void) { // Old form. So what? int i,j,n; ulong l; char *pasm; t_disasm da; t_asmmodel am; char s[TEXTLEN],errtext[TEXTLEN]; // Demonstration of Disassembler. printf("Disassembler:\n"); // Quickly determine size of command. l=Disasm("\x81\x05\xE0\x5A\x47\x00\x01\x00\x00\x00\x11\x22\x33\x44\x55\x66", 10,0x400000,&da,DISASM_SIZE); printf("Size of command = %i bytes\n",l); // ADD [475AE0],1 MASM mode, lowercase, don't show default segment ideal=0; lowercase=1; putdefseg=0; l=Disasm("\x81\x05\xE0\x5A\x47\x00\x01\x00\x00\x00", 10,0x400000,&da,DISASM_CODE); printf("%3i %-24s %-24s (MASM)\n",l,da.dump,da.result); // ADD [475AE0],1 IDEAL mode, uppercase, show default segment ideal=1; lowercase=0; putdefseg=1; l=Disasm("\x81\x05\xE0\x5A\x47\x00\x01\x00\x00\x00", 10,0x400000,&da,DISASM_CODE); printf("%3i %-24s %-24s (IDEAL)\n",l,da.dump,da.result); // CALL 45187C l=Disasm("\xE8\x1F\x14\x00\x00", 5,0x450458,&da,DISASM_CODE); printf("%3i %-24s %-24s jmpconst=%08X\n",l,da.dump,da.result,da.jmpconst); // JNZ 450517 l=Disasm("\x75\x72", 2,0x4504A3,&da,DISASM_CODE); printf("%3i %-24s %-24s jmpconst=%08X\n",l,da.dump,da.result,da.jmpconst); // Demonstration of Assembler. printf("\nAssembler:\n"); // Assemble one of the commands above. First try form with 32-bit immediate. pasm="ADD [DWORD 475AE0],1"; printf("%s:\n",pasm); j=Assemble(pasm,0x400000,&am,0,0,errtext); n=sprintf(s,"%3i ",j); for (i=0; i<j; i++) n+=sprintf(s+n,"%02X ",am.code[i]); if (j<=0) sprintf(s+n," error=\"%s\"",errtext); printf("%s\n",s); // Then variant with 8-bit immediate constant. j=Assemble(pasm,0x400000,&am,0,2,errtext); n=sprintf(s,"%3i ",j); for (i=0; i<j; i++) n+=sprintf(s+n,"%02X ",am.code[i]); if (j<=0) sprintf(s+n," error=\"%s\"",errtext); printf("%s\n",s); // Error, unable to determine size of operands. pasm="MOV [475AE0],1"; printf("%s:\n",pasm); j=Assemble(pasm,0x400000,&am,0,4,errtext); n=sprintf(s,"%3i ",j); for (i=0; i<j; i++) n+=sprintf(s+n,"%02X ",am.code[i]); if (j<=0) sprintf(s+n," error=\"%s\"",errtext); printf("%s\n",s); // Show results. Sleep(10000); };
void RunExperiment(int expNo) { unsigned int i, j, wrFreqCount; double expBestFit = HUGE_VAL; double expBestValFit = HUGE_VAL; FILE *fpExp; //InitQPop(); //InitTkPop(); InitDemes(); wrFreqCount = 0; gwi = 1; nEvalsExp = 0; i = 0; bestExpTkIndiv.fitness = HUGE_VAL; bestExpTkIndiv.validFitness = HUGE_VAL; bestExpTkIndiv.error = HUGE_VAL; //RunGeneration(i, &expBestFit); RunGenerationDemes(i, &expBestFit); accumFit[0] += tkPop[0].fitness; //expBestFit; accumLen[0] += tkPop[0].length; accumValFit[0] += bestTkIndiv.validFitness; for (i = 1, wrFreqCount = 1; i <= nGenerations; i++, wrFreqCount++) //!!! { //RunGeneration(i, &expBestFit); RunGenerationDemes(i, &expBestFit); if (wrFreqCount == writeFreq) { accumFit[i/writeFreq] += bestExpTkIndiv.fitness;//tkPop[0].fitness;//expBestFit; accumLen[i/writeFreq] += bestExpTkIndiv.length;//tkPop[0].length; fprintf(experimsOut, "%d;\t", i); if (validatingData) { accumValFit[i/writeFreq] += bestExpTkIndiv.validFitness; fprintf(experimsOut, "%d %g %g;\t", bestExpTkIndiv.length, bestExpTkIndiv.fitness, bestExpTkIndiv.validFitness); } // For no demes //for (j = 0; j < popSize; j++) //{ // fprintf(experimsOut, "%d %g %g;\t", tkPop[j].length, tkPop[j].fitness, tkPop[j].validFitness); //} // For demes for (j = 0; j < nDemes; j++) { fprintf(experimsOut, "%d %g %g;\t", demes[j].bestTkIndiv.length, demes[j].bestTkIndiv.fitness, demes[j].bestTkIndiv.validFitness); } fputc('\n', experimsOut); wrFreqCount = 0; } } if (expBestFit < bestFit) { bestFit = expBestFit; } if (validatingData) { printf("\nPrograms evaluated=%d", nEvalsExp); printf("\nBest Program: T=%g; V=%g; L=%d\n\n", bestExpTkIndiv.fitness, bestExpTkIndiv.validFitness, bestExpTkIndiv.length); } Assemble(&bestExpTkIndiv); // Just to calculate test error fprintf(experimsOut, "Best: Len=%d; Trn=%g; Val=%g; Tst=%g;\n", bestExpTkIndiv.length, //bestExpTkIndiv.fitness, bestExpTkIndiv.validFitness, EvalIndivFunc(trainingData, nSamplesTrain, &bestExpTkIndiv), // Maybe useless EvalIndivFunc(validatingData, nSamplesValid, &bestExpTkIndiv), // Maybe useless EvalIndivFunc(testingData, nSamplesTest, &bestExpTkIndiv)); fprintf(experimsOut, " Genotype: "); for (i = 0; i < qIndivLen; i++) { fprintf(experimsOut, "%x,", bestTkIndiv.genome[2*i]); fprintf(experimsOut, "%x ", bestTkIndiv.genome[2*i+1]); } fprintf(experimsOut, "\n\n"); fpExp = NewExperimOutFile("trainOut", expNo); WriteProgOuts(fpExp, trainingData, nSamplesTrain); fpExp = NewExperimOutFile("validOut", expNo); WriteProgOuts(fpExp, validatingData, nSamplesValid); fpExp = NewExperimOutFile("testOut", expNo); WriteProgOuts(fpExp, testingData, nSamplesTest); nEvalsExp = 0; }