void runRaspi(Arm *raspi, int entry, int suppress) { // assign variables that will keep swapping, // thus avoiding repeated assignment overhead // a pointer to the cpsr register for convenience u32 *cpsr = &(raspi->cpsr); // set the program counter to the given entry point raspi->pc = entry; raspi->halt = 1; // the current instruction BaseInstr* crrt; // view from hereon out as the 'execution' stage exec: crrt = &(mem.d[raspi->pc++]); // switch on the current instructions condition // if it in any way doesn't satisfy the conditions, then // jump to the next label- avoid execution of this instruction // entirely switch (crrt->cond) { case EQ_FLAG: if (!Z_SET(*cpsr)) goto next; break; case NE_FLAG: if ( Z_SET(*cpsr)) goto next; break; case GE_FLAG: if ( N_SET(*cpsr) != V_SET(*cpsr)) goto next; break; case LT_FLAG: if ( N_SET(*cpsr) == V_SET(*cpsr)) goto next; break; case GT_FLAG: if ( Z_SET(*cpsr) || ( N_SET(*cpsr) != V_SET(*cpsr))) goto next; break; case LE_FLAG: if (!Z_SET(*cpsr) && ( N_SET(*cpsr) == V_SET(*cpsr))) goto next; break; case AL_FLAG: break; } // if we pass the condition checks, then proceed to // call the function saved into the base instr struct crrt->function(crrt); next: // if at any point we hit halt, then the halting function // will have been called and therefore the halt flag should // be set to all 0's. If this is the case, then __finish__ if (!raspi->halt) goto fini; // else jump back to execution after we've // fetched the next instruction goto exec; fini: // on finish, dump the current raspberry pi registers and // non-zero memory location/value pairs if (!suppress) // printOut(raspi); printTestSuite(raspi); }
// size(x)=n // h[0]=0; ...; h[k-1]=0; h[k]=-s*xi; h[k+1]=x[k+1]; ...; h[n-1]=x[n-1]; void zhouseholder_vec(int n, int k, dcomplex *h, double *alpha, const dcomplex *x) { // function [h,alpha]=householder_vec(x,k) // y=H*x, H=I-2*h*h'/(h'*h), h=x-y // i<k y(i)=x(i) h(i)=0 // i=k y(k)=s*eta h(k)=x(k)-y(k)=x(k)-s*eta=-s*xi // i>k y(i)=0 h(i)=x(i) // eta=norm2(x(k:end)) // s=sgn(x(k)) // xi=-h(k)/s=-(x(k)-s*eta)/s=eta-x(k)/s=eta-|x(k)| // =(eta^2-|x(k)|^2)/(eta+|x(k|)=(|x(k+1)|^2+..+|x(n)|^2)/(eta+|x(k)|) // h'*h=2*xi*eta // alpha=2/(h'*h)=1/(xi*eta) double eta,s,xi,axk; //----------- norm xi=zvec_sum_pow2_abs(n-k-1,&x[k+1]); // xi=sum(abs(x((k+1):end)).^2); axk=Z_ABS2(x[k]); eta=sqrt(axk+xi); axk=sqrt(axk); if(eta==0) xi=eta-axk; // eta=eta-|x(k)| else xi=xi/(eta+axk); // eta=xi/(eta+|x(k)|) //----------- h zvec_zeros(k,h); zvec_copy(n-k-1,&h[k+1],&x[k+1]); // h((k+1):end)=x((k+1):end); if((Z_R(x[k])*Z_I(x[k]))==0.0){ Z_SET(h[k],-xi,0); }else{ s=-xi/axk; Z_R(h[k])=s*Z_R(x[k]); Z_I(h[k])=s*Z_I(x[k]); } //----------- alpha if(xi==0 || eta==0) (*alpha)=0; else (*alpha)=1.0/(xi*eta); }
// y=x void zvec_copy_dd(int n, dcomplex *y, const double *x_r, const double *x_i) { int i; for(i=0; i<n; i++){ Z_SET(y[i],x_r[i],x_i[i]); } }
// y=x void zvec_copy_d(int n, dcomplex *y, const double *x) { int i; for(i=0; i<n; i++){ Z_SET(y[i],x[i],0); } }
// y=A'*x void zvec_lintr_ct(int m, int n, dcomplex *y, const dcomplex *A, int LDA, const dcomplex *x) { int i,j; for(j=0; j<n; j++){ Z_SET(y[j],0,0); for(i=0; i<m; i++){ Z_ADD_DOT(y[j],MAT(A,i,j,LDA),x[i]); } } }
// sum(x) dcomplex zvec_sum(int n, const dcomplex *x) { dcomplex value; int i; Z_SET(value,0,0); for(i=0; i<n; i++){ Z_ADD(value,x[i]); } return value; }
// x'*y dcomplex zvec_dot(int n, const dcomplex *x, const dcomplex *y) { int i; dcomplex value; Z_SET(value,0,0); for(i=0; i<n; i++){ Z_ADD_DOT(value,x[i],y[i]); } return value; }
// B=H*A, H=I-alpha*h*h' void zhouseholder_left(int m, int n, dcomplex *A, int LDA, int k, const dcomplex *h, double alpha) { dcomplex zalpha,*p=NULL; p=zvec_allocate(m); // p=A'*h zvec_lintr_ct(n,m-k,p,&MAT(A,k,0,LDA),LDA,&h[k]); // B=H*A=A-alpha*h*(A'*h)'=A-alpha*h*p' Z_SET(zalpha,-alpha,0); zmat_rank1op(m-k,n,&MAT(A,k,0,LDA),LDA,zalpha,&h[k],p); // done p=zvec_free(p); }
// B=A*H, H=I-alpha*h*h' void zhouseholder_right(int m, int n, dcomplex *A, int LDA, int k, const dcomplex *h, double alpha) { dcomplex zalpha,*p=NULL; p=zvec_allocate(m); // p=A*h zvec_lintr(m,n-k,p,&COL(A,k,LDA),LDA,&h[k]); // B=A*H=A-alpha*(A*h)*h'=A-alpha*p*h' Z_SET(zalpha,-alpha,0); zmat_rank1op(m,n-k,&COL(A,k,LDA),LDA,zalpha,p,&h[k]); // done p=zvec_free(p); }
dcomplex zpow_si(dcomplex x, int n) { int i; dcomplex y,a; if(n==0){ Z_SET(y,1,0); } else if(n>0){ Z_LET(y,x); for(i=1 ;i<n ;i++){ Z_SET_TIMES(a,y,x); Z_LET(y,a); } } else if(n<0){ Z_LET(y,x); for(i=1; i<(-n); i++){ Z_SET_TIMES(a,y,x); Z_LET(y,a); } Z_SET_INV(a,y); Z_LET(y,a); } return y; }
// x=rand(n,1)*a+b void zvec_rand(int n, dcomplex *x, double a, double b){ int i; for(i=0; i<n; i++){ Z_SET(x[i],genrand_real3()*a+b,genrand_real3()*a+b); } }
// x=ones(n,1) void zvec_ones(int n, dcomplex *x) { int i; for(i=0; i<n; i++){ Z_SET(x[i],1,0); } }
// x[0]=0; x[1]=1; x[2]=2; ...; x[n-1]=n-1 void zvec_grid(int n, dcomplex *x) { int i; for(i=0; i<n; i++){ Z_SET(x[i],i,0); } }
// x=zeros(n,1) void zvec_zeros(int n, dcomplex *x) { int i; for(i=0; i<n; i++){ Z_SET(x[i],0,0); } }
// x=zeros(n,1); x[k]=1 void zvec_unit(int n, dcomplex *x, int k) { zvec_zeros(n,x); Z_SET(x[k],1,0); }
// x=ones(n,1)*a void zvec_set_dd(int n, dcomplex *x, double real, double imag) { int i; for(i=0; i<n; i++){ Z_SET(x[i],real,imag); } }
// x=ones(n,1)*a void zvec_set_d(int n, dcomplex *x, double a) { int i; for(i=0; i<n; i++){ Z_SET(x[i],a,0); } }