Beispiel #1
0
void oprconvert2add(char oprout[], char oprin[]){ //Find address of registers in 2 addresable instructions
	int i,j,k,num,x,num1,num2,flag1,flag2;
	char temp1[105],temp2[105];
	j=0;
	k=0;
	x=1;
	flag1=flag2=0;
	for(i=0;i<strlen(oprin);i++){
		if((oprin[i]=='R' || oprin[i]=='F') && x==1){
			j=0;
			if(oprin[i]=='F')
			flag1=1;
			i++;
			while(oprin[i]!=' ' && oprin[i]!=','){
				temp1[j++]=oprin[i];
				i++;
			}
			temp1[j]='\0';
			x++;
		}
	
		if((oprin[i]=='R' || oprin[i]=='F')&& x==2){
			j=0;
			i++;
			if(oprin[i]=='F')
			flag2=1;
			while(oprin[i]!=' ' && oprin[i]!=',' && oprin[i]){
				temp2[j++]=oprin[i];
				i++;
			}
			temp2[j]='\0';

			x++;
		}	
	}
	num1=convNum(temp1);
	num2=convNum(temp2);
	if(flag1)
	num1 +=9;
	if(flag2)
	num2 +=9;
	
	getbin(num1,temp1);
	getbin(num2,temp2);
	for(k=0;temp1[k];){
		oprout[k++]= temp1[k];
	}
	for(i=0;temp2[i];i++){
		oprout[k++]= temp2[i];
	}
	
	oprout[k] = '\0';
}
Beispiel #2
0
void oprconvert1add(char oprout[], char oprin[]){  //Find address of registers in 1 addresable instructions
	int i,j,k,num1;
	char temp1[105];
	j=0;
	k=0;
	for(i=0;i<strlen(oprin);i++){
		
		if(oprin[i]=='R'){
			j=0;
			i++;
			while(oprin[i]!=' ' && oprin[i]!=',' && oprin[i]){
				temp1[j++]=oprin[i];
				i++;
			}
			temp1[j]='\0';
		}	
	}
	num1=convNum(temp1);
	getbin(num1,temp1);
	for(k=0;temp1[k];){
		oprout[k++]= temp1[k];
	}
	
	oprout[k] = '\0';
}
Beispiel #3
0
int
main(int argc, char **argv)
{
	struct intel1_ucode_header uh;
	int datasize, totalsize;
	void *theupdate;
	struct intel1_ucode_ext_table *eh;

	if (argc < 2)
		errx(1, "need filename");

	in = fopen(argv[1], "r");
	if (!in)
		err(2, "could not open \"%s\"", argv[1]);

	for (;;) {
		if (getbin(&uh, sizeof(uh)) < 0)
			break;
		if (uh.uh_header_ver != 1)
			errx(3, "wrong file format, last line %d", lc);
		if (uh.uh_data_size)
			datasize = uh.uh_data_size;
		else
			datasize = 2000;
		if (uh.uh_total_size)
			totalsize = uh.uh_total_size;
		else
			totalsize = datasize + 48;

		theupdate = malloc(totalsize);
		memcpy(theupdate, &uh, 48);
		if (getbin((char *)theupdate + 48, totalsize - 48) < 0)
			errx(3, "data format");

		if (totalsize != datasize + 48)
			eh = (void *)((char *)theupdate + 48 + datasize);
		else
			eh = NULL;

		writeout(theupdate, totalsize, eh);
		free(theupdate);

	}

	fclose(in);
	exit(0);
}
Beispiel #4
0
void multi(int *table, char *buffer){

			
		int count = 0;
		int i = 12;
		while(isdigit(buffer[i])){
			count++;
			i++;
		}
		
		char inparr[count];
		i = 12;
		int i1 = 0;
		while(i1<count){
			inparr[i1] = buffer[i];
			i1++;
			i++;
		}
		int muxnum = atoi(inparr);
		int selectnum = 0;
		int j = 1;
		while(j<muxnum){
			j = j*2;							
			selectnum++;
		}
		
		char selecters[selectnum];
		char muxinputs[muxnum];
		int o = i+1;
		i = 0;
		while(i<muxnum){
			muxinputs[i] = buffer[o];
			o = o+2;	
			i++;
		}
		i = 0;
		while(i<selectnum){
			selecters[i] = buffer[o]; 	
			o = o+2;
			i++;
		}
		int select[selectnum];
		i = 0;
		while(i<selectnum){
			select[i] = table[(int)selecters[i]];
			i++;
		}
		int selected = 0;
		for (i = 0; i < selectnum; i++){
 			selected = 10 * selected + select[i];
		}
		
		int gray = getbin(selected);
		int dex = binary_decimal(gray);
			
		table[(int)buffer[o]] = table[(int)muxinputs[dex]];
		 
}
Beispiel #5
0
void decoder(int *table, char *buffer){

		int count = 0;
		int i = 8;
		while(isdigit(buffer[i])){
			count++;
			i++;
		}
		
		char inparr[count];
		i = 8;
		int i1 = 0;
		while(i1<count){
			inparr[i1] = buffer[i];
			i1++;
			i++;
		}
		int inpnum = atoi(inparr);
		int outnum = poww(2,inpnum);
		char inputvars[inpnum];
		char outputvars[outnum];
		int o = i + 1;
		i = 0;
		while(i<inpnum){
			inputvars[i] = buffer[o];
			i++;
			o = o+2;
		}
		i=0;
		while(i<outnum){
			outputvars[i] = buffer[o];
			table[(int)outputvars[i]] = 0; /*set default for outputs to 0 */
			i++;	
			o = o+2;
		}
		i = 0;
		int select[inpnum];		
		while(i<inpnum){
			select[i] = table[(int)inputvars[i]];
			i++;
		}
		int selected = 0;
		for (i = 0; i < inpnum; i++){
 			selected = 10 * selected + select[i];
		}
		int gray = getbin(selected);
		int dex = binary_decimal(gray);
		table[(int)outputvars[dex]] = 1;

}
Beispiel #6
0
void oprconvimmid12(char oprout[], char oprin[]){ //Find address of registers in 2 addresable instructions with imm data
		int i,j,k,num,x,num1,num2;
	char temp1[105],temp2[105];
	j=0;
	k=0;
	x=1;
	for(i=0;i<strlen(oprin);i++){
		if(oprin[i]=='R' && x==1){
			j=0;
			i++;
			while(oprin[i]!=' ' && oprin[i]!=','){
				temp1[j++]=oprin[i];
				i++;
			}
			temp1[j]='\0';
			x++;
		}
	
		if(oprin[i]>=48 && oprin[i]<=57 && x==2){
			j=0;
			while(oprin[i]!=' ' && oprin[i]!=',' && oprin[i]){
				temp2[j++]=oprin[i];
				i++;
			}
			temp2[j]='\0';

			x++;
		}	
	}
	num1=convNum(temp1);
	num2=convNum(temp2);
	getbin(num1,temp1);
	getAddress(num2,temp2);
	for(k=0;temp1[k];){
		oprout[k++]= temp1[k];
	}
	for(i=0;temp2[i];i++){
		oprout[k++]= temp2[i];
	}
	
	oprout[k] = '\0';	
}
static int zrun(const char *name, const char *args[])
{
	int rc;
	siginfo_t si;
	char *binary;

	binary = getbin(name);
	if (binary == NULL) {
		ERROR("error while forking in zrun: can't find %s", name);
		return -1;
	}

	rc = fork();
	if (rc == 0) {
		rc = execve(binary, (char * const*)args, environ);
		ERROR("can't execute %s in zrun: %m", args[0]);
		_exit(1);
		return rc;
	}

	free(binary);
	if (rc < 0) {
		/* can't fork */
		ERROR("error while forking in zrun: %m");
		return rc;
	}

	/* wait termination of the child */
	rc = waitid(P_PID, (id_t)rc, &si, WEXITED);
	if (rc)
		ERROR("unexpected wait status in zrun of %s: %m", args[0]);
	else if (si.si_code != CLD_EXITED)
		ERROR("unexpected termination status of %s in zrun", args[0]);
	else if (si.si_status != 0)
		ERROR("child for %s terminated with error code %d in zwrite", args[0], si.si_status);
	else
		return 0;
	return -1;
}
Beispiel #8
0
void oprconvimmid8(char oprout[], char oprin[]){  //Find address of registers in 3 addresable instructions with immd data
		int i,j,k,num,x,num1,num2,num3,flag;
	char temp1[105],temp2[105],temp3[105],comp[105];
	j=0;
	k=0;
	x=1;
	flag=0;
	for(i=0;i<strlen(oprin);i++){
		if(oprin[i]=='R' && x==1){
			j=0;
			i++;
			while(oprin[i]!=' ' && oprin[i]!=','){
				temp1[j++]=oprin[i];
				i++;
			}
			temp1[j]='\0';
			x++;
		}
		if(oprin[i]=='R' && x==2){
			j=0;
			i++;
			while(oprin[i]!=' ' && oprin[i]!=','){
				temp2[j++]=oprin[i];
				i++;
			}
			temp2[j]='\0';
			x++;
		}
		if(((oprin[i]>=48 && oprin[i]<=57 ) || oprin[i]=='-') && x==3){
			j=0;
			while(oprin[i]){
				
				if(oprin[i]=='-')
				flag=1;
				else
				temp3[j++]=oprin[i];
				

				i++;
			}
			temp3[j]='\0';

			x++;
		}	
	}
	
	
	num1=convNum(temp1);
	num2=convNum(temp2);
	num3=convNum(temp3);
	getbin(num1,temp1);
	getbin(num2,temp2);
	getAddress(num3,temp3);
	if(flag)
	twosCompl(temp3,comp);


	for(k=0;temp1[k];){
		oprout[k++]= temp1[k];
	}
	for(i=0;temp2[i];i++){
		oprout[k++]= temp2[i];
	}
	if(flag==0){
	
		for(i=0;temp3[i];i++){
			oprout[k++]= temp3[i];
		}
	}
	else{
			for(i=0;comp[i];i++){
			oprout[k++]= comp[i];
		}
	}
	oprout[k] = '\0';
}
Beispiel #9
0
void deriveNSfractions(bool data, int mode, bool bjet = false)
{
  if (mode==0) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1);
    return;
  }
  if (mode==2) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(0.7);
    return;
  }
  if (mode==4) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1.3);
    return;
  }

  TString fnpp;
  if (bjet)
    fnpp = data ? "dtppjpf" : "mcppbfa";
  else
    fnpp = data ? "dtppjpf" : "mcppqcd";
  auto filepp = config.getfile_djt(fnpp);

  seth(1,0,PI);
  auto hppNS = geth("hppNS");
  auto hppAS = geth("hppAS");

  Fill(filepp,[&] (dict &d) {
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hppNS->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hppAS->Fill(d["dphi21"],d["weight"]);
  });

  float a_pp = hppNS->Integral()/hppAS->Integral();
  cout<<"a_pp "<<a_pp<<endl;


  TString fnPbPb;
  if (bjet)
    fnPbPb = data ? "dtPbbjt" : "mcPbbfa";
  else
    fnPbPb = data ? "dtPbjcl" : "mcPbqcd";
  auto file = config.getfile_djt(fnPbPb);
  vector<TString> histn;
  for (unsigned i=0;i<binbounds.size()-1;i++)
    histn.push_back(Form("PbPb%d%d",binbounds[i],binbounds[i+1]));
  setv(histn);

  auto hPbPbNS = getv("hPbPbNS");
  auto hPbPbAS = getv("hPbPbAS");

  auto hPbPbNSsig = getv("hPbPbNSsig");

  Fill(file,[&] (dict &d) {
    int b = getbin(d["bin"]);
    float w = d["weight"];
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;  
    if (bjet && d["pairCode21"]==0) w*=processweight((int)d["bProdCode"]);
    if (!data && d["pthat"]<50) return;  
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hPbPbNS[b]->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hPbPbAS[b]->Fill(d["dphi21"],d["weight"]);

    if (!data && d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13 && (d["subid2"]==0 && d["refpt2"]>20))
      hPbPbNSsig[b]->Fill(d["dphi21"],d["weight"]);

  });

  vector<double> binmean;
  vector<double> nsfractrue;
  vector<double> nsfracest;

  for (unsigned i=0;i<binbounds.size()-1;i++) {
    float a_PbPb = hPbPbNS[i]->Integral()/hPbPbAS[i]->Integral();
    float x = (1-a_pp/a_PbPb)/(1-a_pp);
    NSfrac.push_back(mode==1 ? x : -1);// = old stupid adding of the signal : 2-x);
    // cout<<binbounds[i]<<" - "<<binbounds[i+1]<<" = "<<NSfrac[i]<<endl;

    nsfractrue.push_back(1-hPbPbNSsig[i]->Integral()/hPbPbNS[i]->Integral());
    nsfracest.push_back(NSfrac[NSfrac.size()-1]);
    binmean.push_back((binbounds[i]+binbounds[i+1])/2);
  }

  auto c = getc();
  TGraph *g = new TGraph(binbounds.size()-1,&binmean[0],&nsfractrue[0]);
  g->Draw();
  SavePlot(c,bjet ? "bjetfractionofNS" : "incfractionofNS");

  auto c2 = getc();
  TGraph *g2 = new TGraph(binbounds.size()-1,&binmean[0],&nsfracest[0]);
  g2->Draw();
  SavePlot(c2,bjet ? "bjetfractionofNSdata" : "incfractionofNSdata");



///////////////////////////// DATA:
// bin<20 : 0.93
// bin>=20 && bin<60 : 0.84
// bin>=60 : 0.39
////////////////////////////


}