CSrvCmd *TaskTextInputQue(CTask *srv,CTask *master, U8 *data,I64 flags) { CSrvCmd *result; Bool old_preempt=Preempt(OFF); CTask *task; if (!data || !TaskValidate(srv) || master && !TaskValidate(master) || srv->popup_task && !Bt(&srv->task_flags,TASKf_FILTER_INPUT)) { Preempt(old_preempt); return NULL; } result=ACAlloc(sizeof(CSrvCmd)); result->master_task=master; //in case somebody cares result->cmd_code=SVCT_TEXT_INPUT; result->flags=flags; result->aux_str=AStrNew(data); PushFD; task=srv->last_input_filter_task; if (Bt(&flags,SVCf_HIGHEST_PRIORITY) || task==srv) { if (task!=srv) TaskWait(srv); task=Spawn(&InputFilterTask,NULL,"Input Filter",,srv); Cli; task->next_input_filter_task=srv->next_input_filter_task; task->last_input_filter_task=srv; srv->next_input_filter_task=task; task->next_input_filter_task->last_input_filter_task=task; } else {
public CTaskSettings *SettingsPush(CTask *task=NULL,I64 flags=0) { //This is typically used at the start of an application. //It saves many settings so they can be restored //at the end of the application with $LK,"SettingsPop","MN:SettingsPop"$(). CTaskSettings *tempse; CDoc *doc; if (!task) task=Fs; if (!TaskValidate(task)) return NULL; tempse=CAlloc(sizeof(CTaskSettings),task); tempse->draw_it=task->draw_it; GetVGAPalette4(tempse->palette4); tempse->task_end_cb=task->task_end_cb; if (!(flags&TSF_SAME_SONG)) { if (tempse->song_task=task->song_task) { Suspend(task->song_task); Snd(0); } task->song_task=NULL; } if (tempse->animate_task=task->animate_task) Suspend(task->animate_task); task->animate_task=NULL; if (doc=DocPut(task)) { tempse->cursor=!Bt(&doc->flags,DOCf_HIDE_CURSOR); tempse->scroll=!Bt(&doc->flags,DOCf_NO_SCROLL_BARS); } tempse->left=task->win_left; tempse->right=task->win_right; tempse->top=task->win_top; tempse->bottom=task->win_bottom; tempse->scroll_x=task->win_scroll_x; tempse->scroll_y=task->win_scroll_y; tempse->scroll_z=task->win_scroll_z; tempse->win_inhibit=task->win_inhibit; MemCpy(&tempse->snap,&task->snap,sizeof(CSnap)); tempse->win_max_refresh=task->win_max_refresh; tempse->text_attr=task->text_attr; StrCpy(tempse->task_title,task->task_title); tempse->title_src =task->title_src; tempse->border_attr=task->border_attr; tempse->border_src =task->border_src; tempse->border=!Bt(&task->display_flags,DISPLAYf_NO_BORDER); tempse->preempt=Bt(&task->task_flags,TASKf_PREEMPT); if (TaskValidate(ws_task)) tempse->wordstat=TRUE; else tempse->wordstat=FALSE; tempse->next=task->next_settings; task->next_settings=tempse; return tempse; }
U0 SysGlblsInit() { I64 i,j; U8 *m; CRAXRBCRCXRDX ee; CPUId(0x1,&ee); sys_cache_line_width=ee.rbx.u8[1]*8; QueInit(&sys_pci_dev_root); sys_rnd_seed = 93186752^GetTimeStamp; sys_focus_task=Fs; QueInit(&sys_macro_root); sys_dft_iso_name="::/Temp/CDDVD.ISO"; MemSet(mp_apic_ids,0,MP_MAX_PROCESSORS*sizeof(U8)); LBts(&adam_task->task_flags,TASKf_INIT_EXT);//So dbgger doesn't call $LK,"TaskInitExt","MN:TaskInitExt"$(). InDbg(ON); reverse_bits_table=CAlloc(256); for (i=0;i<256;i++) for (j=0;j<8;j++) if (Bt(&i,7-j)) LBts(reverse_bits_table+i,j); set_bits_table=CAlloc(256); for (i=0;i<256;i++) for (j=0;j<8;j++) if (Bt(&i,j)) set_bits_table[i]++; ext=CAlloc(EXT_TABLE_SIZE*sizeof(U8 *)); fp_mgets=&SysMGetS; fp_ctrl_alt_let_cbs=CAlloc(26*sizeof(U8 *)); ctrl_alt_let_descs=CAlloc(26*sizeof(U8 *));; ctrl_alt_let_in_irq_flags=0; psect_cache=CAlloc(PSECT_CACHE_SIZE*sizeof(CPSectCache)); psect_cache_index=0; StrCpy(sys_temp_filename,"HOME/Temp.TXT.Z"); MemSet(&sys_put_key_root,0,sizeof(CKeyDev)); QueInit(&sys_put_key_root); KeyDevAdd(&AKDInputFilterPutKey,&AKDInputFilterPutS,0x40000000,FALSE); KeyDevAdd(&AKDRawDisplayPutKey,&AKDRawDisplayPutS,0x60000000,FALSE); #exe { if (*kernel_cfg->acct_name) StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts/%s\");",kernel_cfg->sys_acct_drv,kernel_cfg->acct_name); else StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts\");",kernel_cfg->sys_acct_drv); StreamPutS("#exe{OptOff(OPTf_WARN_PAREN);}"); StreamPrintF("DskCacheInit(%s);",kernel_cfg->dsk_cache_size_exp); StreamPutS("#exe{OptOn(OPTf_WARN_PAREN);}"); };
void RpalParser::B() { pushProc("B()"); Bt(); while (_nt == "or") { read_token("or"); Bt(); build("or", 2); } popProc("B()"); }
public U0 DocProfile(U8 *filename,I64 flags) { I64 i,*cmd_stats=CAlloc(sizeof(I64)*DOCT_NUM_TYPES), *flags_stats=CAlloc(sizeof(I64)*64), *type_flags_stats=CAlloc(sizeof(I64)*64); //Note, word wrap is determined by //doc->win_task when a $LK,"CDoc","MN:CDoc"$ is recalculated //use $LK,"DocRecalc","MN:DocRecalc"$(). CDoc *doc=DocRead(filename,flags); //doc->root which is equal to doc is the //header of the CQue and represents the end-of-file marker. CDocEntry *doc_e=doc->root.next; while (doc_e!=doc) { cmd_stats[doc_e->type_u8]++; for (i=0; i<64; i++) if (Bt(&doc_e->flags1,i)) flags_stats[i]++; for (i=16; i<32; i++) if (Bt(&doc_e->type,i)) type_flags_stats[i]++; doc_e=doc_e->next; } DocDel(doc); "$$FG,PURPLE$$-------%s-------\n" ,filename; "$$FG,GREEN$$The lowest byte of the 32-bit 'doc_e->type', '$$FG,PURPLE$$doc_e->type.u8[0]$$FG,GREEN$$', is cmd and accessed with the union '$$FG,PURPLE$$doc_e->type_u8$$FG,GREEN$$'." "See $$LK,\"CDocEntry\",\"MN:CDocEntry\"$$, " "$$LK,\"Doc Type Defines\",\"MN:DOCT_TEXT\"$$ and $$LK,\"Doc Type Codes\",\"FF:::/TempleOS/Adam/Doc/Doc.CPP,ST_DOC_CMDS\"$$.\n$$FG$$"; for (i=0; i<DOCT_NUM_TYPES; i++) if (cmd_stats[i]) "%4Z:%d\n",i,"ST_DOC_CMDS",cmd_stats[i]; "\n$$FG,GREEN$$'$$FG,PURPLE$$doc_e->type.u8[1]$$FG,GREEN$$' is the screen color attr of the entry." "'$$FG,PURPLE$$doc_e->type.u16[1]$$FG,GREEN$$' is some flags for blinking and stuff." "See $$LK,\"Doc Type Flag Defines\",\"MN:DOCET_BLINK\"$$.\n$$FG$$"; for (i=16; i<32; i++) if (type_flags_stats[i]) "%4d:%d\n",i,type_flags_stats[i]; "$$FG,GREEN$$\n'$$FG,PURPLE$$doc_e->flags1$$FG,GREEN$$' is 64-bit." "See $$LK,\"Doc Flag Defines\",\"MN:DOCEf1_AUX_STR\"$$ and $$LK,\"Doc Flag Codes\",\"FF:::/TempleOS/Adam/Doc/Doc.CPP,ST_DOC_FLAGS\"$$.\n$$FG$$"; for (i=0; i<64; i++) if (flags_stats[i]) "%4Z:%d\n",i,"ST_DOC_FLAGS",flags_stats[i]; Free(cmd_stats); Free(flags_stats); PressAKey; NewLine; }
Bool OptIC6(CIntermediateCode *tempi) { CIntermediateCode *tempil1,*tempil2; if (tempi->ic_opcode<IC_IMM_U64) return FALSE; tempil1=tempi; if (!(tempil2=OptLag1(tempil1))) return FALSE; if (tempil2->ic_opcode==IC_ADD_CONST && tempil1->ic_opcode==IC_DEREF && tempil1->ic_flags&ICF_P1_WAS_STK && tempil1->p1.type&TY_MASK==TY_REG && tempil2->r.type&TY_MASK==TY_REG && MIN_I32<=tempil2->ic_data<=MAX_I32 && !Bt(&non_ptr_vars_mask,tempil2->p1.reg)) if (tempil2->p1.type&TY_MASK==TY_REG) { tempil1->ic_flags= tempil1->ic_flags & ~ICF_P1_WAS_STK | tempil2->ic_flags; tempil1->ic_opcode=IC_MOV; tempil1->p1.type=TY_DISP+tempil1->p1.ptype; tempil1->p1.reg=tempil2->p1.reg; tempil1->p1.disp=tempil2->ic_data; OptSetNOP2(tempil2,-1); return TRUE; } else { tempil2->ic_opcode=IC_MOV; tempil1->ic_opcode=IC_MOV; tempil1->p1.type=TY_DISP+tempil1->p1.ptype; tempil1->p1.disp=tempil2->ic_data; return TRUE; } return FALSE; }
void testSparseGammaGapMergingSmall() { uint64_t const A0[] = { 1,6,1,7,21,1,6,6,7,4,42,14,16,25,28,100,83,70,75 }; uint64_t const A1[] = { 1,3,50,52,75,77,1000,1002,2000,3000 }; uint64_t const A2[] = { 11,13,60,62,82,83 }; uint64_t const A3[] = { }; uint64_t const *A[] = { &A0[0], &A1[0], &A2[0], &A3[0], 0 }; uint64_t const An[] = { sizeof(A0)/sizeof(A0[0]), sizeof(A1)/sizeof(A1[0]), sizeof(A2)/sizeof(A2[0]), sizeof(A3)/sizeof(A3[0]), 0 }; uint64_t const B0[] = { 1,6,1,7,21,1,6,6,7,5,43,13,18,24,29,95,86,72,77 }; uint64_t const B1[] = { 11,13,60,62,82,83 }; uint64_t const B2[] = { 1000,1002,1004,1006,1008,1010,1012, 1014, 1017, 1020 }; uint64_t const B3[] = { }; uint64_t const B4[] = { 1,6,1,7,21,1,6,6,7,4,42,14,16,25,28,100,83,70,75 }; uint64_t const *B[] = { &B0[0], &B1[0], &B2[2], &B3[0], &B4[0], 0 }; uint64_t const Bn[] = { sizeof(B0)/sizeof(B0[0]), sizeof(B1)/sizeof(B1[0]), sizeof(B2)/sizeof(B2[0]), sizeof(B3)/sizeof(B3[0]), sizeof(B4)/sizeof(B4[0]), 0 }; for ( uint64_t a = 0; A[a]; ++a ) for ( uint64_t b = 0; B[b]; ++b ) { libmaus::autoarray::AutoArray<uint64_t> At(An[a],false); libmaus::autoarray::AutoArray<uint64_t> Bt(Bn[b],false); std::copy(A[a],A[a]+An[a],At.begin()); std::copy(B[b],B[b]+Bn[b],Bt.begin()); testSparseGammaGapMergingSmall(At.begin(),An[a],Bt.begin(),Bn[b]); } }
U0 Kill(CTask *task,Bool wait=TRUE) { I64 i; CCPU *c; Bool found,old_preempt=Preempt(OFF); if (TaskValidate(task)) { if (task==sys_winmgr_task) found=TRUE; else found=FALSE; for (i=0; i<mp_cnt; i++) { c=&cpu_structs[i]; if (task==c->seth_task) found=TRUE; } if (!found) { LBts(&task->task_flags,TASKf_KILL_TASK); if (wait) { do Yield; while (TaskValidate(task) && Bt(&task->task_flags,TASKf_KILL_TASK)); } } } Preempt(old_preempt); }
void optimiseTransformationMatrixContinuous() { // Get coordinates of all pairs: Matrix2D<double> Au, Bt; Au.initZeros(3, 3); Bt.initZeros(3, 3); Pass.initZeros(4,4); // Add all pairs to dependent matrices (adapted from add_point in Xmipps micrograph_mark main_widget_mark.cpp) for (int t = 0; t < pairs_t2u.size(); t++) { int u = pairs_t2u[t]; if (u >= 0) { Au(0, 0) += (double)(p_unt[2*u] * p_unt[2*u]); Au(0, 1) += (double)(p_unt[2*u] * p_unt[2*u+1]); Au(0, 2) += (double)(p_unt[2*u]); Au(1, 0) = Au(0, 1); Au(1, 1) += (double)(p_unt[2*u+1] * p_unt[2*u+1]); Au(1, 2) += (double)(p_unt[2*u+1]); Au(2, 0) = Au(0, 2); Au(2, 1) = Au(1, 2); Au(2, 2) += 1.; Bt(0, 0) += (double)(p_til[2*t] * p_unt[2*u]); Bt(0, 1) += (double)(p_til[2*t+1] * p_unt[2*u]); Bt(0, 2) = Au(0, 2); Bt(1, 0) += (double)(p_til[2*t] * p_unt[2*u+1]); Bt(1, 1) += (double)(p_til[2*t+1] * p_unt[2*u+1]); Bt(1, 2) = Au(1, 2); Bt(2, 0) += (double)(p_til[2*t]); Bt(2, 1) += (double)(p_til[2*t+1]); Bt(2,2) += 1.; } } // Solve equations solve(Au, Bt, Pass); Pass = Pass.transpose(); std::cout << " Optimised passing matrix= " << Pass << std::endl; //These values can be complete CRAP. Better not show them at all.... //double rotp, tiltp, psip; //tiltp = acos(Pass(1,1)); //rotp = acos(Pass(1,0)/sin(tiltp)); //psip = acos(Pass(0,1)/-sin(tiltp)); //std::cout << " Optimised tilt angle= " << RAD2DEG(tiltp) << std::endl; //std::cout << " Optimised in-plane rot angles= " << RAD2DEG(rotp) <<" and "<< RAD2DEG(psip) << std::endl; // Map using the new matrix mapOntoTilt(); }
Bool IsSuspended(CTask *task=NULL) { if (!task) task=Fs; if (TaskValidate(task)) return Bt(&task->task_flags,TASKf_SUSPENDED); else return FALSE; }
Bool FilesFindMatch(U8 *files_find_mask,U8 *filename,I64 fuf_flags=0) { U8 *st1=StrNew(files_find_mask), *st2=MAlloc(StrLen(files_find_mask)+1); Bool result=FALSE; while (TRUE) { StrFirstRem(st1,";",st2); if (*st2) { if (*st2=='~') { if (WildCardMatch(st2+1,filename)) { result=FALSE; break; } } else { if (WildCardMatch(st2,filename)) { if (Bt(&fuf_flags,FUf_JUST_TXT_FILES) && !FilesFindMatch(FILENAME_MASK_TXT,filename)) { result=FALSE; break; } else if (Bt(&fuf_flags,FUf_JUST_SRC_FILES) && !FilesFindMatch(FILENAME_MASK_SRC,filename)) { result=FALSE; break; } else if (Bt(&fuf_flags,FUf_JUST_AOT_FILES) && !FilesFindMatch(FILENAME_MASK_AOT,filename)) { result=FALSE; break; } else if (Bt(&fuf_flags,FUf_JUST_JIT_FILES) && !FilesFindMatch(FILENAME_MASK_JIT,filename)) { result=FALSE; break; } else if (Bt(&fuf_flags,FUf_JUST_GRA_FILES) && !FilesFindMatch(FILENAME_MASK_GRA,filename)) { result=FALSE; break; } else result=TRUE; } } } else break; } Free(st1); Free(st2); return result; }
U0 EdRACollect(CDoc *doc,CRenum *root) { I64 ch,i; CRenum *tempr; U8 buf[sizeof(CEdFindText.find_text)]; ch=EdRAGetU8(doc); while (ch>=0) { if (ch!='@') ch=EdRAGetU8(doc); else { ch=EdRAGetU8(doc); if (ch=='@') { ch=EdRAGetU8(doc); StrCpy(buf,"@@"); i=2; while (ch>=0 && i<sizeof(CEdFindText.find_text)) { if (Bt(alpha_numeric_bitmap,ch)) buf[i++]=ch; else break; ch=EdRAGetU8(doc); } if (i<sizeof(CEdFindText.find_text)) { buf[i++]=0; while (ch>=0 && Bt(white_space_bitmap,ch)) ch=EdRAGetU8(doc); if (ch==':') { ch=EdRAGetU8(doc); tempr=MAlloc(sizeof(CRenum)); StrCpy(tempr->label,buf); QueIns(tempr,root->last); } } } } } //This is needed because we moved the //cursor and it didn't recalc. DocRecalc(doc); }
Bool FileNameChk(U8 *filename) { U8 *ptr=filename; if (!filename) return FALSE; if (!*ptr) return FALSE; if (*ptr=='.') { if (!ptr[1]) return TRUE; if (ptr[1]=='.' && !ptr[2]) return TRUE; } if (StrLen(filename)>=CDIR_FILENAME_LEN) return FALSE; while (*ptr) if (!Bt(filename_chars_bitmap,*ptr++)) return FALSE; return TRUE; }
CSrvCmd *TaskExeStrQue(CTask *srv,CTask *master, U8 *data,I64 flags) { CSrvCmd *result; if (!data || !TaskValidate(srv) || master && !TaskValidate(master) || srv->popup_task && !Bt(&srv->task_flags,TASKf_FILTER_INPUT)) return NULL; result=ACAlloc(sizeof(CSrvCmd)); result->master_task=master; result->cmd_code=SVCT_EXE_STR; result->flags=flags; result->aux_str=AStrNew(data); result->ctrl=&srv->srv_ctrl; PushFD; Cli; while (LBts(&srv->srv_ctrl.flags,SVCRf_LOCKED)) Pause; if (!TaskValidate(srv)) { PopFD; SrvCmdDel(result); return NULL; } else { LBtr(&srv->task_flags,TASKf_IDLE); TaskRstAwaitingMsg(srv); QueIns(result,srv->srv_ctrl.last_waiting); LBtr(&srv->srv_ctrl.flags,SVCRf_LOCKED); if (Bt(&flags,SVCf_WAKE_MASTER)) { Suspend(master); Yield; } } PopFD; return result; }
void STWarp<T>::multiscaleIteration(WarpingField<T> &warpField) { for (int warpIter = 0; warpIter < params.warpIterations; ++warpIter) { if(params.verbosity > 1) { printf(" - warp iteration %02d\n",warpIter+1); } // Get derivatives if(params.verbosity > 1) { printf(" - computing derivatives..."); } Video<T> Bx(videoB->size()); Video<T> By(videoB->size()); Video<T> Bt(videoB->size()); Video<T> C(videoB->size()); computePartialDerivatives(warpField,Bx,By,Bt,C); if(params.verbosity >1) { printf("done.\n"); } // marginal warpField update WarpingField<T> dWarpField = WarpingField<T>(warpField.size()); warpingIteration(warpField, Bx, By, Bt, C, dWarpField); if (params.limitUpdate) { if(params.verbosity > 1) { printf(" - limiting warp update to [-1,1]"); } dWarpField.clamp(-1,1); } // w <- w + dw warpField.add(dWarpField); denoiseWarpingField(warpField); } // end of warp iteration }
U0 OptPass5(CLex *lx) { CIntermediateCode *tempi,*tempi1; I64 code,i,ty,pt,ty1,pt1; CPrsStk *ps=OptStart; tempi=lx->lcc.lcc_root.next; while (code=tempi->ic_opcode) { if (code>IC_NOP2) { if (tempi->ic_flags&ICF_TRACE) { if (Bt(&lx->pass_trace_mask,5)) { "%2d:",ps->ptr; ICPut(tempi); } } if (cmp_arg_cnt[code]==9) ps->ptr-=tempi->ic_data>>3; if (code==IC_PUSH_REGS) { for (i=0;i<NUM_REGS;i++) if (Bt(&tempi->ic_data,i)) ps->ptr++; } else if (code==IC_POP_REGS) { for (i=0;i<NUM_REGS;i++) if (Bt(&tempi->ic_data,i)) ps->ptr--; } if (tempi->p2.type&TY_MASK==TY_STK) { tempi1=PrsPop(ps); if (tempi1->ic_opcode==IC_MOV || tempi1->ic_opcode==IC_REG) { if (tempi1->ic_flags & ICF_R_TO_INT) { if (tempi1->p1.type&TY_MASK==TY_IMM) tempi1->p1.disp=tempi1->p1.disp(F64); else tempi->ic_flags|=ICF_P2_TO_INT; } else if (tempi1->ic_flags&ICF_R_TO_F64) { if (tempi1->p1.type&TY_MASK==TY_IMM) tempi1->p1.disp(F64)=tempi1->p1.disp; else tempi->ic_flags|=ICF_P2_TO_F64; } ty=tempi->p2.type&IT_MASK; ty1=tempi1->p1.type&IT_MASK; if (ty1 && ty1<ty) ty=ty1; ty1=tempi1->r.type&IT_MASK; if (ty1 && ty1<ty) ty=ty1; tempi->p2.type=tempi1->p1.type&TY_MASK+ty; pt=tempi->p2.ptype; pt1=tempi1->p1.ptype; if (pt1 && pt1<pt && pt!=IT_F64) pt=pt1; pt1=tempi1->r.ptype; if (pt1 && pt1<pt && pt!=IT_F64) pt=pt1; tempi->p2.ptype=pt; tempi->p2.reg=tempi1->p1.reg; tempi->p2.disp=tempi1->p1.disp; tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK; OptSetNOP2(tempi1); } } if (tempi->p1.type&TY_MASK==TY_STK) { tempi1=PrsPop(ps); if (tempi1->ic_opcode==IC_MOV || tempi1->ic_opcode==IC_REG) { if (tempi1->ic_flags & ICF_R_TO_INT) { if (tempi1->p1.type&TY_MASK==TY_IMM) tempi1->p1.disp=tempi1->p1.disp(F64); else tempi->ic_flags|=ICF_P1_TO_INT; } else if (tempi1->ic_flags&ICF_R_TO_F64) { if (tempi1->p1.type&TY_MASK==TY_IMM) { if (tempi1->p1.type & 1) //signed/unsigned tempi1->p1.disp(F64)=tempi1->p1.disp(U64); else tempi1->p1.disp(F64)=tempi1->p1.disp(I64); } else tempi->ic_flags|=ICF_P1_TO_F64; } ty=tempi->p1.type&IT_MASK; ty1=tempi1->p1.type&IT_MASK; if (ty1 && ty1<ty) ty=ty1; ty1=tempi1->r.type&IT_MASK; if (ty1 && ty1<ty) ty=ty1; tempi->p1.type=tempi1->p1.type&TY_MASK+ty; pt=tempi->p1.ptype; pt1=tempi1->p1.ptype; if (pt1 && pt1<pt && pt!=IT_F64) pt=pt1; pt1=tempi1->r.ptype; if (pt1 && pt1<pt && pt!=IT_F64) pt=pt1; tempi->p1.ptype=pt; tempi->p1.reg=tempi1->p1.reg; tempi->p1.disp=tempi1->p1.disp; tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK; OptSetNOP2(tempi1); } } if (tempi->r.type&TY_MASK==TY_STK) PrsPush(ps,tempi); } tempi=tempi->next; } OptEnd(lx,ps); }
//Get state of compiler option Bool GetOpt(I64 num) { return Bt(&Fs->last_lex->opts,num); }
U0 OptPass6(CLex *lx,CHashFun *fun_class) { CIntermediateCode *tempi,*tempil1,*tempif1,*tempif2, *temp_lag[4],*old_tempil1=NULL; CPrsStk *ps=OptStart(temp_lag); I64 i=0,code,num_stk,clobbered_reg_mask=CALWAYS_CLOBBERED_MASK, fun_num=0; if (fun_class) fun_num=compiled_funs++; if (Bt(&lx->opts,OPTf_NO_REG_VAR) || lx->flags&LF_NO_REG_OPT) num_stk=0; else num_stk=num_stk_temps; tempi=lx->lcc.lcc_root.next; while (code=tempi->ic_opcode) { OptNext3(tempi,temp_lag); tempil1=temp_lag[1]; if (tempil1->ic_opcode==IC_END_EXP) { if (code!=IC_RETURN_VAL2 && code!=IC_NOP1) { if (!(temp_lag[2]->ic_flags& (ICF_R_TO_F64|ICF_R_TO_INT|ICF_PUSH_RESULT|ICF_DEPEND_RESULT))) { temp_lag[2]->ic_flags|=ICF_NO_DEPEND_RESULT; temp_lag[2]->r.type=TY_NULL+temp_lag[2]->r.type&IT_MASK; tempil1->ic_flags|=ICF_NO_DEPEND_RESULT; tempil1->r.type=TY_NULL+tempil1->r.type&IT_MASK; } } } if (code<=IC_NOP2) { } else { if (tempi->p2.type&TY_MASK==TY_STK) { if (tempil1->r.type&TY_MASK==TY_STK && !(tempil1->ic_flags&ICF_PUSH_RESULT)) { tempif2=NULL; if (tempi->ic_opcode==IC_ASSIGN && tempi->ic_flags&ICF_NOT_ADDR && tempil1->ic_opcode!=IC_CALL_END && tempil1->ic_opcode!=IC_CALL_END2 && tempil1->ic_opcode!=IC_SET_RAX && !(tempi->ic_flags& (ICF_P2_TO_F64|ICF_P2_TO_INT)) && !(tempil1->ic_flags& (ICF_R_TO_F64|ICF_R_TO_INT))) { if (tempif1=OptLead1(tempi)) //predict NO_DEPEND if (tempif2=OptLead1(tempif1)) if (tempif1->ic_opcode==IC_END_EXP && tempif2->ic_opcode!=IC_RETURN_VAL2) { tempil1->r.type =tempi->p1.type&TY_MASK+tempi->p1.ptype; tempil1->r.ptype=tempi->p1.ptype; tempil1->r.reg =tempi->p1.reg; tempil1->r.disp =tempi->p1.disp; tempil1->ic_flags=tempil1->ic_flags&~(ICF_NO_DEPEND_RESULT|ICF_R_WAS_STK)| tempi->ic_flags&~(ICF_NOT_ADDR|ICF_P1_WAS_STK|ICF_P2_WAS_STK)|ICF_DEPEND_RESULT; old_tempil1=NULL; OptSetNOP1(tempi); } else tempif2=NULL; } if (!tempif2) { tempi->p2.type=TY_REG+tempi->p2.type&IT_MASK; tempi->p2.reg=CREG_RAX; tempi->p2.disp=0; tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK; tempil1->r.reg=CREG_RAX; tempil1->r.disp=0; } } } else if (tempi->p1.type&TY_MASK==TY_STK) { if (tempil1->r.type&TY_MASK==TY_STK && !(tempil1->ic_flags&ICF_PUSH_RESULT)) { tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK; tempi->p1.reg=CREG_RAX; tempi->p1.disp=0; tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK; tempil1->r.reg=CREG_RAX; tempil1->r.disp=0; } } if (tempi->ic_flags & ICF_PUSH_RESULT) tempi->r.type==TY_STK+tempi->r.type&IT_MASK; } if (old_tempil1!=tempil1) { OptPass6Lag(lx,ps,tempil1,&i,num_stk,&clobbered_reg_mask,fun_num); old_tempil1=tempil1; } tempi=tempi->next; } OptEnd(lx,ps); if (fun_class) { fun_class->used_reg_mask&=~CSTK_TEMPS_MASK; fun_class->used_reg_mask|=clobbered_reg_mask; fun_class->clobbered_reg_mask=clobbered_reg_mask; if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT) && Bt(&lx->pass_trace_mask,6)) { "UsedReg Mask:%04X\n",fun_class->used_reg_mask; "Clobbered Reg Mask:%04X\n",clobbered_reg_mask; } } }
virtual void init(Voxel& voxel) { b0_index.clear(); for(unsigned int index = 0;index < voxel.bvalues.size();++index) if(voxel.bvalues[index] == 0) b0_index.push_back(index); half_odf_size = voxel.ti.vertices_count/2; float lambda = voxel.param[0]; unsigned int max_l = voxel.param[1]; const unsigned int R = ((max_l+1)*(max_l+2)/2); std::vector<std::pair<int,int> > j_map(R); for (int k = 0; k <= max_l; k += 2) for (int m = -k; m <= k; ++m) j_map[getJ(m,k)] = std::make_pair(m,k); std::vector<float> Bt(R*voxel.bvectors.size()); for (unsigned int j = 0,index = 0; j < R; ++j) for (unsigned int n = 0; n < voxel.bvectors.size(); ++n,++index) { float atan2_xy = std::atan2(voxel.bvectors[n][1],voxel.bvectors[n][0]); if (atan2_xy < 0.0) atan2_xy += 2.0*M_PI; Bt[index] = Yj(j_map[j].second,j_map[j].first,std::acos(voxel.bvectors[n][2]),atan2_xy); } std::vector<float> UP(half_odf_size*R); { std::vector<float> U(half_odf_size*R); for (unsigned int n = 0,index = 0; n < half_odf_size; ++n) for (unsigned int j = 0; j < R; ++j,++index) { float atan2_xy = std::atan2(voxel.ti.vertices[n][1],voxel.ti.vertices[n][0]); if (atan2_xy < 0.0) atan2_xy += 2.0*M_PI; U[index] = Yj(j_map[j].second,j_map[j].first,std::acos(voxel.ti.vertices[n][2]),atan2_xy); } std::vector<float> P(R*R); for (unsigned int i = 0,index = 0; i < R; ++i,index += R+1) P[index] = boost::math::legendre_p(j_map[i].second,0.0)*2.0*M_PI; image::matrix::product(U.begin(),P.begin(),UP.begin(),image::dyndim(half_odf_size,R),image::dyndim(R,R)); } std::vector<float> iB(Bt.size()); { std::vector<float> BtB(R*R); // BtB = Bt * trans(Bt); image::matrix::square(Bt.begin(),BtB.begin(),image::dyndim(R,voxel.bvectors.size())); for (unsigned int i = 0,index = 0; i < R; ++i,index += R+1) { float l = j_map[i].second; BtB[index] += l*l*(l+1.0)*(l+1.0)*lambda; } std::vector<unsigned int> pivot(R); image::matrix::lu_decomposition(BtB.begin(),pivot.begin(),image::dyndim(R,R)); //iB = inv(BtB)*Bt; image::matrix::lu_solve(BtB.begin(),pivot.begin(),Bt.begin(),iB.begin(),image::dyndim(R,R),image::dyndim(R,voxel.bvectors.size())); } UPiB.resize(half_odf_size*voxel.bvectors.size()); image::matrix::product(UP.begin(),iB.begin(),UPiB.begin(),image::dyndim(half_odf_size,R),image::dyndim(R,voxel.bvectors.size())); }
U0 OptPass6Lag(CLex *lx, CPrsStk *ps,CIntermediateCode *tempi,I64 *i_,I64 num_stk, I64 *_clobbered_reg_mask,I64 fun_num) { I64 i=*i_,j,k,l,code,clobbered_reg_mask=*_clobbered_reg_mask; CHashFun *tempf; code=tempi->ic_opcode; if (code<=IC_NOP2) return; else { if (tempi->ic_flags&ICF_TRACE) { if (Bt(&lx->pass_trace_mask,6)) { "%2d:",i; ICPut(tempi); } } if (code==IC_CALL_START) { if (i<num_stk) k=i; else k=num_stk; j=0; if (fun_num&1) for (l=0;l<k;l++) Bts(&j,to_stk_temps_map_odd[l]); else for (l=0;l<k;l++) Bts(&j,to_stk_temps_map_even[l]); if (tempf=tempi->ic_data) { if (Bt(tempf->flags,Ff_INTERNAL)) j=0; else { j&=tempf->clobbered_reg_mask; clobbered_reg_mask|=tempf->clobbered_reg_mask; } } tempi->ic_data=j; PrsPush(ps,i); PrsPush(ps,j); } else if (code==IC_CALL_END) { tempi->ic_data=PrsPop(ps); i=PrsPop(ps); } // else if (code==IC_LEAVE) // i=0; else if (code==IC_CALL_END2) { ps->ptr--; i=PrsPop(ps); } if (cmp_arg_cnt[code]==9) i-=tempi->ic_data>>3; if (tempi->p2.type&TY_MASK==TY_STK) { i--; if (i<num_stk) { tempi->p2.type=TY_REG+tempi->p2.type&IT_MASK; if (fun_num&1) tempi->p2.reg=to_stk_temps_map_odd[i]; else tempi->p2.reg=to_stk_temps_map_even[i]; tempi->p2.disp=0; } } if (tempi->p1.type&TY_MASK==TY_STK) { i--; if (i<num_stk) { tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK; if (fun_num&1) tempi->p1.reg=to_stk_temps_map_odd[i]; else tempi->p1.reg=to_stk_temps_map_even[i]; tempi->p1.disp=0; } } if (tempi->r.type&TY_MASK==TY_STK && !(tempi->ic_flags & ICF_PUSH_RESULT)) { i++; if (i<=num_stk) { tempi->r.type=TY_REG+tempi->r.type&IT_MASK; if (fun_num&1) { tempi->r.reg=to_stk_temps_map_odd[i-1]; Bts(&clobbered_reg_mask,to_stk_temps_map_odd[i-1]); } else { tempi->r.reg=to_stk_temps_map_even[i-1]; Bts(&clobbered_reg_mask,to_stk_temps_map_even[i-1]); } tempi->r.disp=0; } } while (OptIC6(tempi)); if (tempi->r.type&IT_MASK!=IT_F64 && !(tempi->ic_flags&ICF_USE_F64)) tempi->ic_flags|=ICF_USE_INT; } *i_=i; *_clobbered_reg_mask=clobbered_reg_mask; }