Example #1
0
static void lb_init_lattice(int *grid) {
  int i, x, hgrid[lbmodel.n_dim], hsize[lbmodel.n_dim];

  lblattice.grid[0] = grid[0];
  lblattice.grid[1] = grid[1];

  lblattice.halo_size[0] = hsize[0] = HALO;
  lblattice.halo_size[1] = hsize[1] = HALO;

  lblattice.halo_grid[0] = hgrid[0] = lblattice.grid[0] + 2*hsize[0];
  lblattice.halo_grid[1] = hgrid[1] = lblattice.grid[1] + 2*hsize[1];

  lblattice.stride[1] = 1;
  lblattice.stride[0] = hgrid[1];

  lblattice.halo_grid_volume = hgrid[0]*hgrid[1];

  lbf = calloc(2*lblattice.halo_grid_volume*lbmodel.n_vel, sizeof(*lbf));

  for (i=0; i<lbmodel.n_vel; ++i) {
    for (x=0; x<WGRID; ++x) {
      FI(i,x) = calloc(lblattice.halo_grid[1],sizeof(*FI(0,0)));
    }
    lblattice.nb_offset[i] = (int)(lbmodel.c[i][0])*hgrid[1]+(int)(lbmodel.c[i][1]);
  }

}
Example #2
0
void Arg_List::argBuild()
{
	if(toPlainText() == "")
		return;
	QString argument = toPlainText();
	QString fileName = stdValue.pathTemp + "/arg.txt", cmd;
	QFile file(fileName);
	if (file.open(QFile::WriteOnly | QFile::Truncate)) {
		QTextStream out(&file);
		out<<argument;
	}
	file.close();
	if(stdValue.pathTrans == NULL)
		cmd = "\"" + stdValue.pathTools + "/trans2.exe\" -c \"" + fileName + "\" err.log dbg.log";
	else
		cmd = "\"" + stdValue.pathTrans + "/trans2.exe\" -c \"" + fileName + "\" err.log dbg.log";
	QFileInfo FI(fileName);
	if(!FI.exists())
	{
        QMessageBox::warning(this,tr("Error"),"File not exist! " + fileName,QMessageBox::Yes);
		return;
	}
	QProcess *Process = new QProcess(this);
	Process->start(cmd);
	if(!Process->waitForFinished() )
        QMessageBox::warning(this,tr("Error"),Process->errorString() + "; " + cmd,QMessageBox::Yes);
}
Example #3
0
CAMLprim value
siocgifconf_c(value caml_socket)
{
  CAMLparam1(caml_socket);
  int socket = Int_val(caml_socket);
  struct ifreq ifr[IFCONF_MAXLEN];
  struct ifconf ifc;
  int i;
  value caml_iflist = Val_int(0);
  value new_if;
  value pair;
  struct sockaddr_in *sin;
  
  ifc.ifc_len = IFCONF_MAXLEN;
  ifc.ifc_req = ifr;
  
  FI(socket, SIOCGIFCONF, &ifc);
  
  for (i = 0; i < ifc.ifc_len; i++) {
    /* ifname:string * ipaddr:int32 */
    pair = caml_alloc(2, 0);
    Store_field(pair, 0, caml_copy_string(ifc.ifc_req[i].ifr_name));
    sin = (struct sockaddr_in *)&ifc.ifc_req[i].ifr_addr;
    Store_field(pair, 1, caml_copy_int32(sin->sin_addr.s_addr));

    /* next list node */
    new_if = caml_alloc(2, 0);
    Store_field(new_if, 0, pair);
    Store_field(new_if, 1, caml_iflist);
    caml_iflist = new_if;
  }
  
  RESULT(caml_iflist, 0);
}
Example #4
0
unsigned int fillIn(G_t& G)
{
    typedef typename treedec::graph_traits<G_t>::treedec_type T_t;

    typedef typename std::vector<typename boost::graph_traits<G_t>::vertex_descriptor> O_t;
    impl::fillIn<G_t, T_t, O_t> FI(G, (T_t*)NULL, (O_t*)NULL, 0);
    FI.do_it();

    return FI.get_bagsize();
}
Example #5
0
PatchPromptDialog::PatchPromptDialog(QWidget *parent) :
	QDialog(parent),
	ui(new Ui::PatchPromptDialog)
{
	ui->setupUi(this);

	QSettings			Settings;

	Settings.beginReadArray( "recent" );

	QStringList			RecentFiles;

	for( int i = 0 ; i < 10 ; i++ )
	{
		Settings.setArrayIndex( i );

		QString			RecentFile = Settings.value( "filename" ).toString();

		if( RecentFile.isEmpty() )
		{
			continue;
		}

		if( !QFile( RecentFile ).exists() )
		{
			continue;
		}

		RecentFiles << RecentFile;
	}

	if( !RecentFiles.isEmpty() )
	{
		ui->mRecentPatches->setEnabled( true );

		ui->mRecentPatches->clear();

		for( QString FileName : RecentFiles )
		{
			QListWidgetItem		*LWI = new QListWidgetItem();

			if( LWI )
			{
				QFileInfo			 FI( FileName );

				LWI->setText( FI.fileName() );
				LWI->setData( Qt::UserRole, FileName );
				LWI->setToolTip( FileName );

				ui->mRecentPatches->addItem( LWI );
			}
		}
	}
}
Example #6
0
void lb_finalize() {
  int i, x;

  for (i=0; i<lbmodel.n_vel; ++i) {
    for (x=0; x<WGRID; ++x) {
      free(FI(i,x));
    }
  }    

  free(lbf);

}
Example #7
0
int cast5_decrypt(cast5_key *skey, const SilcUInt32 ct[2],
		  SilcUInt32 pt[2])
{
   SilcUInt32 R, L;

   R = ct[0];
   L = ct[1];

   if (skey->keylen > 10) {
      R ^= FI(L, skey->K[15], skey->K[31]);
      L ^= FIII(R, skey->K[14], skey->K[30]);
      R ^= FII(L, skey->K[13], skey->K[29]);
      L ^= FI(R, skey->K[12], skey->K[28]);
   }
   R ^= FIII(L, skey->K[11], skey->K[27]);
   L ^= FII(R, skey->K[10], skey->K[26]);
   R ^= FI(L, skey->K[9], skey->K[25]);
   L ^= FIII(R, skey->K[8], skey->K[24]);
   R ^= FII(L, skey->K[7], skey->K[23]);
   L ^= FI(R, skey->K[6], skey->K[22]);
   R ^= FIII(L, skey->K[5], skey->K[21]);
   L ^= FII(R, skey->K[4], skey->K[20]);
   R ^= FI(L, skey->K[3], skey->K[19]);
   L ^= FIII(R, skey->K[2], skey->K[18]);
   R ^= FII(L, skey->K[1], skey->K[17]);
   L ^= FI(R, skey->K[0], skey->K[16]);

   pt[0] = L;
   pt[1] = R;

   return TRUE;
}
Example #8
0
int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
#endif
{
   ulong32 R, L;

   LTC_ARGCHK(pt   != NULL);
   LTC_ARGCHK(ct   != NULL);
   LTC_ARGCHK(skey != NULL);

   LOAD32H(R,&ct[0]);
   LOAD32H(L,&ct[4]);
   if (skey->cast5.keylen > 10) {
      R ^= FI(L, skey->cast5.K[15], skey->cast5.K[31]);
      L ^= FIII(R, skey->cast5.K[14], skey->cast5.K[30]);
      R ^= FII(L, skey->cast5.K[13], skey->cast5.K[29]);
      L ^= FI(R, skey->cast5.K[12], skey->cast5.K[28]);
   }
   R ^= FIII(L, skey->cast5.K[11], skey->cast5.K[27]);
   L ^= FII(R, skey->cast5.K[10], skey->cast5.K[26]);
   R ^= FI(L, skey->cast5.K[9], skey->cast5.K[25]);
   L ^= FIII(R, skey->cast5.K[8], skey->cast5.K[24]);
   R ^= FII(L, skey->cast5.K[7], skey->cast5.K[23]);
   L ^= FI(R, skey->cast5.K[6], skey->cast5.K[22]);
   R ^= FIII(L, skey->cast5.K[5], skey->cast5.K[21]);
   L ^= FII(R, skey->cast5.K[4], skey->cast5.K[20]);
   R ^= FI(L, skey->cast5.K[3], skey->cast5.K[19]);
   L ^= FIII(R, skey->cast5.K[2], skey->cast5.K[18]);
   R ^= FII(L, skey->cast5.K[1], skey->cast5.K[17]);
   L ^= FI(R, skey->cast5.K[0], skey->cast5.K[16]);
   STORE32H(L,&pt[0]);
   STORE32H(R,&pt[4]);

   return CRYPT_OK;
}
Example #9
0
void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
{
   ulong32 R, L;

   _ARGCHK(pt != NULL);
   _ARGCHK(ct != NULL);
   _ARGCHK(key != NULL);

   LOAD32H(L,&pt[0]); 
   LOAD32H(R,&pt[4]);

   L ^= FI(R, key->cast5.K[0], key->cast5.K[16]);
   R ^= FII(L, key->cast5.K[1], key->cast5.K[17]);
   L ^= FIII(R, key->cast5.K[2], key->cast5.K[18]);
   R ^= FI(L, key->cast5.K[3], key->cast5.K[19]);
   L ^= FII(R, key->cast5.K[4], key->cast5.K[20]);
   R ^= FIII(L, key->cast5.K[5], key->cast5.K[21]);
   L ^= FI(R, key->cast5.K[6], key->cast5.K[22]);
   R ^= FII(L, key->cast5.K[7], key->cast5.K[23]);
   L ^= FIII(R, key->cast5.K[8], key->cast5.K[24]);
   R ^= FI(L, key->cast5.K[9], key->cast5.K[25]);
   L ^= FII(R, key->cast5.K[10], key->cast5.K[26]);
   R ^= FIII(L, key->cast5.K[11], key->cast5.K[27]);
   if (key->cast5.keylen > 10) {
      L ^= FI(R, key->cast5.K[12], key->cast5.K[28]);
      R ^= FII(L, key->cast5.K[13], key->cast5.K[29]);
      L ^= FIII(R, key->cast5.K[14], key->cast5.K[30]);
      R ^= FI(L, key->cast5.K[15], key->cast5.K[31]);
   }
   STORE32H(R,&ct[0]);
   STORE32H(L,&ct[4]);
}
Example #10
0
bool LPGUtils::revertFile(QString oldPath, QString newPath){
  qDebug() << "Reverting file:" << oldPath << " -> " << newPath;
  bool ok = QFile::copy(oldPath,newPath);
  //return the path to the new file if the copy was successful
  if(ok){ 
    //reset the permissions on the reverted file to match the original
    QFile::setPermissions(newPath, QFile::permissions(oldPath));
    QFileInfo FI(oldPath);
      system( QString("chown "+FI.owner()+":"+FI.group()+" "+newPath).toUtf8() );
  }else{
    qDebug() << " - Error: Could not copy file";
  }
  return ok;
}
Example #11
0
CAMLprim value
siocgifname_c(value caml_socket, value caml_ifindex)
{
  CAMLparam2(caml_socket, caml_ifindex);
  int socket = Int_val(caml_socket);
  int ifindex = Int_val(caml_ifindex);
  struct ifreq ifr;

  memset(&ifr, 0, sizeof(struct ifreq));
  ifr.ifr_ifindex = ifindex;
  FI(socket, SIOCGIFNAME, &ifr);
  
  RESULT(caml_copy_string(ifr.ifr_name), 0);
}
Example #12
0
static ulong32 FO( ulong32 in, int round_no, symmetric_key *key)
{
    u16 left, right;

    /* Split the input into two 16-bit words */
    left = (u16)(in>>16);
    right = (u16) in&0xFFFF;

    /* Now apply the same basic transformation three times */
    left ^= key->kasumi.KOi1[round_no];
    left = FI( left, key->kasumi.KIi1[round_no] );
    left ^= right;

    right ^= key->kasumi.KOi2[round_no];
    right = FI( right, key->kasumi.KIi2[round_no] );
    right ^= left;

    left ^= key->kasumi.KOi3[round_no];
    left = FI( left, key->kasumi.KIi3[round_no] );
    left ^= right;

    return (((ulong32)right)<<16)+left;
}
int main(void) {
  int n, brojac, fib;
  while (1) {
    brojac = 0;
    printf("Upisite broj >"); // Primjeri: n=5,40,50
    scanf("%d", &n);
    if (n < 0) {
    printf ("gotovo!\n"); break;
    } else {
    fib = FI (n);
    printf("%d. Fibonaccijev broj = %d , Izravno! \n", n, fib);
    }
  }
  return 0;

}
Example #14
0
QStringList LPGUtils::revertDir(QString oldPath, QString newPath){
  //Note: this is a recursive function and can take quite a while to perform lots of file copies

  //Load the directories and create it if necessary
  QDir oDir(oldPath);
  QDir nDir(newPath);
  bool ok=true;
  if( !nDir.exists() ){
    //Create the new Directory
    qDebug() << "Re-Create parent directory structure:" << newPath;
    nDir.cdUp();
    ok = nDir.mkpath(newPath.section("/",-1)); //also create all parent directories if necessary
    if(ok){ 
      qDebug() << " - Reset permissions on the main parent dir to match snapshot";
      nDir.cd(newPath.section("/",-1)); 
      QFile::setPermissions(newPath, QFile::permissions(oldPath)); //make sure the new dir has the old permissions
      QFileInfo FI(oldPath);
      system( QString("chown "+FI.owner()+":"+FI.group()+" "+newPath).toUtf8() );
    }
  }
  //Get a list of any files that error
  QStringList errors;
  if(!ok){
    errors << newPath;
    return errors;
  }
  //Get a list of all the files in the old dir and copy them over
  QStringList fList = oDir.entryList(QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDir::Name);
  for(int i=0; i<fList.length(); i++){
    if( !revertFile(oldPath+"/"+fList[i], newPath+"/"+fList[i]) ){
       errors << newPath+"/"+fList[i];
    }
  }
  //Now list all the directories in the old dir and recursively copy them over
  fList = oDir.entryList(QDir::Dirs | QDir::Hidden | QDir::NoDotAndDotDot, QDir::Name);
  for(int i=0; i<fList.length(); i++){
    QStringList errs = revertDir(oldPath+"/"+fList[i], newPath+"/"+fList[i]);
    if( !errs.isEmpty() ){ errors << errs; }
  }
  return errors;
}
Example #15
0
/*
* MISTY1 Decryption
*/
void MISTY1::decrypt_n(const byte in[], byte out[], size_t blocks) const
   {
   for(size_t i = 0; i != blocks; ++i)
      {
      u16bit B0 = load_be<u16bit>(in, 2);
      u16bit B1 = load_be<u16bit>(in, 3);
      u16bit B2 = load_be<u16bit>(in, 0);
      u16bit B3 = load_be<u16bit>(in, 1);

      for(size_t j = 0; j != 12; j += 3)
         {
         const u16bit* RK = &DK[8 * j];

         B2 ^= B3 | RK[0];
         B3 ^= B2 & RK[1];
         B0 ^= B1 | RK[2];
         B1 ^= B0 & RK[3];

         u32bit T0, T1;

         T0  = FI(B2 ^ RK[ 4], RK[ 5], RK[ 6]) ^ B3;
         T1  = FI(B3 ^ RK[ 7], RK[ 8], RK[ 9]) ^ T0;
         T0  = FI(T0 ^ RK[10], RK[11], RK[12]) ^ T1;

         B0 ^= T1 ^ RK[13];
         B1 ^= T0;

         T0  = FI(B0 ^ RK[14], RK[15], RK[16]) ^ B1;
         T1  = FI(B1 ^ RK[17], RK[18], RK[19]) ^ T0;
         T0  = FI(T0 ^ RK[20], RK[21], RK[22]) ^ T1;

         B2 ^= T1 ^ RK[23];
         B3 ^= T0;
         }

      B2 ^= B3 | DK[96];
      B3 ^= B2 & DK[97];
      B0 ^= B1 | DK[98];
      B1 ^= B0 & DK[99];

      store_be(out, B0, B1, B2, B3);

      in += BLOCK_SIZE;
      out += BLOCK_SIZE;
      }
   }
Example #16
0
/*
* KASUMI Decryption
*/
void KASUMI::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
   {
   verify_key_set(m_EK.empty() == false);

   for(size_t i = 0; i != blocks; ++i)
      {
      uint16_t B0 = load_be<uint16_t>(in, 0);
      uint16_t B1 = load_be<uint16_t>(in, 1);
      uint16_t B2 = load_be<uint16_t>(in, 2);
      uint16_t B3 = load_be<uint16_t>(in, 3);

      for(size_t j = 0; j != 8; j += 2)
         {
         const uint16_t* K = &m_EK[8*(6-j)];

         uint16_t L = B2, R = B3;

         L = FI(L ^ K[10], K[11]) ^ R;
         R = FI(R ^ K[12], K[13]) ^ L;
         L = FI(L ^ K[14], K[15]) ^ R;

         L ^= (rotl<1>(R) & K[8]);
         R ^= (rotl<1>(L) | K[9]);

         R = B0 ^= R;
         L = B1 ^= L;

         L ^= (rotl<1>(R) & K[0]);
         R ^= (rotl<1>(L) | K[1]);

         R = FI(R ^ K[2], K[3]) ^ L;
         L = FI(L ^ K[4], K[5]) ^ R;
         R = FI(R ^ K[6], K[7]) ^ L;

         B2 ^= L;
         B3 ^= R;
         }

      store_be(out, B0, B1, B2, B3);

      in += BLOCK_SIZE;
      out += BLOCK_SIZE;
      }
   }
Example #17
0
/*
* KASUMI Decryption
*/
void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const
   {
   for(size_t i = 0; i != blocks; ++i)
      {
      u16bit B0 = load_be<u16bit>(in, 0);
      u16bit B1 = load_be<u16bit>(in, 1);
      u16bit B2 = load_be<u16bit>(in, 2);
      u16bit B3 = load_be<u16bit>(in, 3);

      for(size_t j = 0; j != 8; j += 2)
         {
         const u16bit* K = &m_EK[8*(6-j)];

         u16bit L = B2, R = B3;

         L = FI(L ^ K[10], K[11]) ^ R;
         R = FI(R ^ K[12], K[13]) ^ L;
         L = FI(L ^ K[14], K[15]) ^ R;

         L ^= (rotate_left(R, 1) & K[8]);
         R ^= (rotate_left(L, 1) | K[9]);

         R = B0 ^= R;
         L = B1 ^= L;

         L ^= (rotate_left(R, 1) & K[0]);
         R ^= (rotate_left(L, 1) | K[1]);

         R = FI(R ^ K[2], K[3]) ^ L;
         L = FI(L ^ K[4], K[5]) ^ R;
         R = FI(R ^ K[6], K[7]) ^ L;

         B2 ^= L;
         B3 ^= R;
         }

      store_be(out, B0, B1, B2, B3);

      in += BLOCK_SIZE;
      out += BLOCK_SIZE;
      }
   }
Example #18
0
bool SpirValidation::runOnModule(Module& M) {
  // Holder for initialized data in the module
  DataHolder Data;

  // Initialize instruction verifiers.
  InstructionExecutorList iel;
  // Bitcast instruction verifier.
  VerifyBitcast vb(&ErrHolder);
  iel.push_back(&vb);
  // Call instruction verifier.
  VerifyCall vc(&ErrHolder);
  iel.push_back(&vc);
  // Instruction type verifier.
  VerifyInstructionType vit(&ErrHolder, &Data);
  iel.push_back(&vit);

  // Initialize function verifiers.
  FunctionExecutorList fel;
  // Function prototype verifier.
  VerifyFunctionPrototype vfp(&ErrHolder, &Data);
  fel.push_back(&vfp);

  // Initialize module verifiers.
  ModuleExecutorList mel;
  // Module triple and target data layout verifier.
  VerifyTripleAndDataLayout vtdl(&ErrHolder, &Data);
  mel.push_back(&vtdl);
  // Module metadata kernels verifier.
  VerifyMetadataKernels vkmd(&ErrHolder, &Data);
  mel.push_back(&vkmd);
  // Module OCL version verifier.
  VerifyMetadataVersions voclv(
    &ErrHolder, VerifyMetadataVersions::VERSION_OCL);
  mel.push_back(&voclv);
  // Module SPIR version verifier.
  VerifyMetadataVersions vspirv(
    &ErrHolder, VerifyMetadataVersions::VERSION_SPIR);
  mel.push_back(&vspirv);
  // Module metadata optional core features verifier.
  VerifyMetadataCoreFeatures vmdcf(&ErrHolder, &Data);
  mel.push_back(&vmdcf);
  // Module metadata KHR extensions verifier.
  VerifyMetadataKHRExtensions vmdext(&ErrHolder, &Data);
  mel.push_back(&vmdext);
  // Module metadata compiler options verifier.
  VerifyMetadataCompilerOptions vmdco(&ErrHolder, &Data);
  mel.push_back(&vmdco);

  // Initialize basic block iterator.
  BasicBlockIterator BBI(iel);

  // Initialize function iterator.
  FunctionIterator FI(fel, &BBI);

  // Initialize module iterator.
  ModuleIterator MI(mel, &FI);

  // Run validation.
  MI.execute(M);

  return false;
}
Example #19
0
static void md5_process_block64(md5_ctx_t *ctx)
{

	/* Before we start, one word to the strange constants.
	   They are defined in RFC 1321 as
	   T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64
	 */
	static const uint32_t C_array[] = {
		/* round 1 */
		0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
		0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
		0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
		0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
		/* round 2 */
		0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
		0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
		0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
		0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
		/* round 3 */
		0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
		0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
		0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
		0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
		/* round 4 */
		0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
		0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
		0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
		0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
	};
	static const char P_array[] = {
		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
		1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
		5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
		0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9  /* 4 */
	};

	uint32_t *words = (void*) ctx->wbuffer;
	uint32_t A = ctx->hash[0];
	uint32_t B = ctx->hash[1];
	uint32_t C = ctx->hash[2];
	uint32_t D = ctx->hash[3];

 /* 2 or 3 */

	static const char S_array[] = {
		7, 12, 17, 22,
		5, 9, 14, 20,
		4, 11, 16, 23,
		6, 10, 15, 21
	};
	const uint32_t *pc;
	const char *pp;
	const char *ps;
	int i;
	uint32_t temp;

 /* MD5_SIZE_VS_SPEED == 2 */
	pc = C_array;
	pp = P_array;
	ps = S_array;

	for (i = 0; i < 16; i++) {
		temp = A + FF(B, C, D) + words[(int) (*pp++)] + *pc++;
		temp = rotl32(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}
	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FG(B, C, D) + words[(int) (*pp++)] + *pc++;
		temp = rotl32(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}
	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FH(B, C, D) + words[(int) (*pp++)] + *pc++;
		temp = rotl32(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}
	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FI(B, C, D) + words[(int) (*pp++)] + *pc++;
		temp = rotl32(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}

	/* Add checksum to the starting values */
	ctx->hash[0] += A;
	ctx->hash[1] += B;
	ctx->hash[2] += C;
	ctx->hash[3] += D;

}
Example #20
0
bool ContextPrivate::save( const QString &pFileName, const QList<QUuid> *pNodeList ) const
{
	QFileInfo				 FileInfo( pFileName );
	QString					 TmpFileName = FileInfo.absoluteFilePath().append( ".out" );

	if( true )
	{
		QSettings				 CFG( TmpFileName, QSettings::IniFormat );

		if( !CFG.isWritable() )
		{
			return( false );
		}

		CFG.clear();

		emit saveStart( CFG );

		CFG.beginGroup( "fugio" );

		CFG.setValue( "version", int( 2 ) );

		CFG.setValue( "duration", double( duration() ) );

		CFG.endGroup();

		//-------------------------------------------------------------------------

		CFG.beginGroup( "meta" );

		for( auto it = mMetaInfoMap.begin() ; it != mMetaInfoMap.end() ; it++ )
		{
			const QString	K = mMetaNameMap.value( it.key() );
			const QString	V = it.value();

			if( !K.isEmpty() && !V.isEmpty() )
			{
				CFG.setValue( K, V );
			}
		}

		CFG.endGroup();

		//-------------------------------------------------------------------------

		CFG.beginGroup( "nodes" );

		for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() )
		{
			if( !pNodeList || pNodeList->contains( N->uuid() ) )
			{
				CFG.setValue( fugio::utils::uuid2string( N->uuid() ), fugio::utils::uuid2string( N->controlUuid() ) );
			}
		}

		CFG.endGroup();

		//-------------------------------------------------------------------------

		CFG.beginGroup( "connections" );

		for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() )
		{
			if( !pNodeList || pNodeList->contains( N->uuid() ) )
			{
				for( QSharedPointer<fugio::PinInterface> P : N->enumInputPins() )
				{
					if( !P->isConnected() )
					{
						continue;
					}

					QSharedPointer<fugio::PinInterface>	ConPin = P->connectedPin();

					if( !ConPin || !ConPin->node() )
					{
						continue;
					}

					if( !pNodeList || pNodeList->contains( ConPin->node()->uuid() ) )
					{
						CFG.setValue( fugio::utils::uuid2string( P->globalId() ), fugio::utils::uuid2string( ConPin->globalId() ) );
					}
				}
			}
		}

		CFG.endGroup();

		//-------------------------------------------------------------------------

		for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() )
		{
			if( !pNodeList || pNodeList->contains( N->uuid() ) )
			{
				CFG.beginGroup( fugio::utils::uuid2string( N->uuid() ) );

				N->saveSettings( CFG, false );

				CFG.endGroup();

				for( QSharedPointer<fugio::PinInterface> P : N->enumPins() )
				{
					CFG.beginGroup( fugio::utils::uuid2string( P->globalId() ) );

					P->saveSettings( CFG );

					CFG.endGroup();
				}
			}
		}

		//-------------------------------------------------------------------------

		CFG.beginGroup( "assets" );

		for( auto it : mAssetMap.toStdMap() )
		{
			QFileInfo		FI( CFG.fileName() );
			QDir			FD( FI.absolutePath() );
			QString			AP = FD.absoluteFilePath( it.second );

			qDebug() << AP;

			CFG.setValue( fugio::utils::uuid2string( it.first ), AP );
		}

		CFG.endGroup();

		//-------------------------------------------------------------------------

		emit saving( CFG );

		emit saveEnd( CFG );
	}

	QString		TmpOld;

	if( FileInfo.exists() )
	{
		TmpOld = FileInfo.dir().absoluteFilePath( FileInfo.completeBaseName() ).append( ".old" );

		if( !QFile::rename( pFileName, TmpOld ) )
		{
			qWarning() << "Couldn't rename output file";

			return( false );
		}
	}

	if( true )
	{
		QFile		SrcDat( TmpFileName );
		QFile		DstDat( pFileName );

		if( !SrcDat.open( QFile::ReadOnly ) )
		{
			qWarning() << "Couldn't open temporary file";

			return( false );
		}

		if( !DstDat.open( QFile::WriteOnly ) )
		{
			qWarning() << "Couldn't open output file";

			return( false );
		}

		QStringList	HdrLst;

		HdrLst << QString( ";-----------------------------------------------------------------" );
		HdrLst << QString( "; Created with Fugio %1" ).arg( QCoreApplication::applicationVersion() );

		for( auto it = mMetaInfoMap.begin() ; it != mMetaInfoMap.end() ; it++ )
		{
			const QString	K = mMetaNameMap.value( it.key() );
			const QString	V = it.value();

			if( !K.isEmpty() && !V.isEmpty() )
			{
				HdrLst << QString( "; %1: %2" ).arg( K ).arg( V );
			}
		}

		HdrLst << QString( ";-----------------------------------------------------------------" );
		HdrLst << QString( "" );
		HdrLst << QString( "" );

		QByteArray	TmpDat;

		TmpDat = HdrLst.join( "\n" ).toLatin1();

		while( !TmpDat.isEmpty() )
		{
			if( DstDat.write( TmpDat ) != TmpDat.size() )
			{
				qWarning() << "Couldn't write output data";

				return( false );
			}

			TmpDat = SrcDat.read( 1024 );
		}

		SrcDat.close();
		DstDat.close();
	}

	if( !QFile::remove( TmpFileName ) )
	{
		qWarning() << "Couldn't remove temporary file";
	}

	if( !TmpOld.isEmpty() && !QFile::remove( TmpOld ) )
	{
		qWarning() << "Couldn't remove old file";
	}

	return( true );
}
Example #21
0
static void lb_pbc_y(double PFI, int x) {

  int yl, yh;
  yl = lblattice.halo_size[1];
  yh = lblattice.halo_size[1] + lblattice.grid[1] - 1;

  int xc, xp, xm, xp2, xm2;
  xc  = x%WGRID;
  xp  = (x+1)%WGRID; xm  = (x-1+WGRID)%WGRID;
  xp2 = (x+2)%WGRID; xm2 = (x-2+WGRID)%WGRID;

  /* periodic boundary conditions in y */
  FI( 3, xc )[yl]   = FI( 3, xc )[yh+1];
  FI( 5, xp )[yl]   = FI( 5, xp )[yh+1];
  FI( 7, xm )[yl]   = FI( 7, xm )[yh+1];
  FI( 4, xc )[yh]   = FI( 4, xc )[yl-1];
  FI( 6, xm )[yh]   = FI( 6, xm )[yl-1];
  FI( 8, xp )[yh]   = FI( 8, xp )[yl-1];

  FI(11, xc )[yl]   = FI(11, xc )[yh+1];
  FI(13, xp2)[yl]   = FI(13, xp2)[yh+1];
  FI(15, xm2)[yl]   = FI(15, xm2)[yh+1];
  FI(12, xc )[yh]   = FI(12, xc )[yl-1];
  FI(14, xm2)[yh]   = FI(14, xm2)[yl-1];
  FI(16, xp2)[yh]   = FI(16, xp2)[yl-1];
  FI(11, xc )[yl+1] = FI(11, xc )[yh+2];
  FI(13, xp2)[yl+1] = FI(13, xp2)[yh+2];
  FI(15, xm2)[yl+1] = FI(15, xm2)[yh+2];
  FI(12, xc )[yh-1] = FI(12, xc )[yl-2];
  FI(14, xm2)[yh-1] = FI(14, xm2)[yl-2];
  FI(16, xp2)[yh-1] = FI(16, xp2)[yl-2];

  FI(19, xc )[yl]   = FI(19, xc )[yh+1];
  FI(19, xc )[yl+1] = FI(19, xc )[yh+2];
  FI(19, xc )[yl+2] = FI(19, xc )[yh+3];
  FI(19, xc )[yl+3] = FI(19, xc )[yh+4];
  FI(20, xc )[yh]   = FI(20, xc )[yl-1];
  FI(20, xc )[yh-1] = FI(20, xc )[yl-2];
  FI(20, xc )[yh-2] = FI(20, xc )[yl-3];
  FI(20, xc )[yh-3] = FI(20, xc )[yl-4];

}
Example #22
0
static void lb_stream(double *f, double PFI, int x, int y) {

  int xc, xp, xm, xp2, xm2, xp4, xm4;
  xc = x%WGRID;
  xp  = (x+1)%WGRID; xm  = (x-1+WGRID)%WGRID;
  xp2 = (x+2)%WGRID; xm2 = (x-2+WGRID)%WGRID;
  xp4 = (x+4)%WGRID; xm4 = (x-4+WGRID)%WGRID;

  FI( 0, xc )[y]   = f[0];
  FI( 1, xp )[y]   = f[1];
  FI( 2, xm )[y]   = f[2];
  FI( 3, xc )[y+1] = f[3];
  FI( 4, xc )[y-1] = f[4];
  FI( 5, xp )[y+1] = f[5];
  FI( 6, xm )[y-1] = f[6];
  FI( 7, xm )[y+1] = f[7];
  FI( 8, xp )[y-1] = f[8];
  FI( 9, xp2)[y]   = f[9];
  FI(10, xm2)[y]   = f[10];
  FI(11, xc )[y+2] = f[11];
  FI(12, xc )[y-2] = f[12];
  FI(13, xp2)[y+2] = f[13];
  FI(14, xm2)[y-2] = f[14];
  FI(15, xm2)[y+2] = f[15];
  FI(16, xp2)[y-2] = f[16];
  FI(17, xp4)[y]   = f[17];
  FI(18, xm4)[y]   = f[18];
  FI(19, xc )[y+4] = f[19];
  FI(20, xc )[y-4] = f[20];
  
}
Example #23
0
/* Hash a single block, 64 bytes long and 4-byte aligned. */
static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
{
	uint32_t correct_words[16];
	const uint32_t *words = buffer;

# if MD5_SIZE_VS_SPEED > 0
	static const uint32_t C_array[] = {
		/* round 1 */
		0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
		0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
		0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
		0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
		/* round 2 */
		0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
		0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
		0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
		0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
		/* round 3 */
		0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
		0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
		0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
		0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
		/* round 4 */
		0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
		0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
		0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
		0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
	};

	static const char P_array[] ALIGN1 = {
#  if MD5_SIZE_VS_SPEED > 1
		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,	/* 1 */
#  endif	/* MD5_SIZE_VS_SPEED > 1 */
		1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12,	/* 2 */
		5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2,	/* 3 */
		0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9	/* 4 */
	};

#  if MD5_SIZE_VS_SPEED > 1
	static const char S_array[] ALIGN1 = {
		7, 12, 17, 22,
		5, 9, 14, 20,
		4, 11, 16, 23,
		6, 10, 15, 21
	};
#  endif	/* MD5_SIZE_VS_SPEED > 1 */
# endif

	uint32_t A = ctx->A;
	uint32_t B = ctx->B;
	uint32_t C = ctx->C;
	uint32_t D = ctx->D;

	/* Process all bytes in the buffer with 64 bytes in each round of
	   the loop.  */
		uint32_t *cwp = correct_words;
		uint32_t A_save = A;
		uint32_t B_save = B;
		uint32_t C_save = C;
		uint32_t D_save = D;

# if MD5_SIZE_VS_SPEED > 1
#  define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))

		const uint32_t *pc;
		const char *pp;
		const char *ps;
		int i;
		uint32_t temp;

		for (i = 0; i < 16; i++) {
			cwp[i] = SWAP_LE32(words[i]);
		}
		words += 16;

#  if MD5_SIZE_VS_SPEED > 2
		pc = C_array;
		pp = P_array;
		ps = S_array - 4;

		for (i = 0; i < 64; i++) {
			if ((i & 0x0f) == 0)
				ps += 4;
			temp = A;
			switch (i >> 4) {
			case 0:
				temp += FF(B, C, D);
				break;
			case 1:
				temp += FG(B, C, D);
				break;
			case 2:
				temp += FH(B, C, D);
				break;
			case 3:
				temp += FI(B, C, D);
			}
			temp += cwp[(int) (*pp++)] + *pc++;
			CYCLIC(temp, ps[i & 3]);
			temp += B;
			A = D;
			D = C;
			C = B;
			B = temp;
		}
#  else
		pc = C_array;
		pp = P_array;
		ps = S_array;

		for (i = 0; i < 16; i++) {
			temp = A + FF(B, C, D) + cwp[(int) (*pp++)] + *pc++;
			CYCLIC(temp, ps[i & 3]);
			temp += B;
			A = D;
			D = C;
			C = B;
			B = temp;
		}

		ps += 4;
		for (i = 0; i < 16; i++) {
			temp = A + FG(B, C, D) + cwp[(int) (*pp++)] + *pc++;
			CYCLIC(temp, ps[i & 3]);
			temp += B;
			A = D;
			D = C;
			C = B;
			B = temp;
		}
		ps += 4;
		for (i = 0; i < 16; i++) {
			temp = A + FH(B, C, D) + cwp[(int) (*pp++)] + *pc++;
			CYCLIC(temp, ps[i & 3]);
			temp += B;
			A = D;
			D = C;
			C = B;
			B = temp;
		}
		ps += 4;
		for (i = 0; i < 16; i++) {
			temp = A + FI(B, C, D) + cwp[(int) (*pp++)] + *pc++;
			CYCLIC(temp, ps[i & 3]);
			temp += B;
			A = D;
			D = C;
			C = B;
			B = temp;
		}

#  endif	/* MD5_SIZE_VS_SPEED > 2 */
# else
		/* First round: using the given function, the context and a constant
		   the next context is computed.  Because the algorithms processing
		   unit is a 32-bit word and it is determined to work on words in
		   little endian byte order we perhaps have to change the byte order
		   before the computation.  To reduce the work for the next steps
		   we store the swapped words in the array CORRECT_WORDS.  */

#  define OP(a, b, c, d, s, T) \
	do { \
		a += FF (b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \
		++words; \
		CYCLIC (a, s); \
		a += b; \
	} while (0)

		/* It is unfortunate that C does not provide an operator for
		   cyclic rotation.  Hope the C compiler is smart enough.  */
		/* gcc 2.95.4 seems to be --aaronl */
#  define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))

		/* Before we start, one word to the strange constants.
		   They are defined in RFC 1321 as

		   T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
		 */

#  if MD5_SIZE_VS_SPEED == 1
		const uint32_t *pc;
		const char *pp;
		int i;
#  endif	/* MD5_SIZE_VS_SPEED */

		/* Round 1.  */
#  if MD5_SIZE_VS_SPEED == 1
		pc = C_array;
		for (i = 0; i < 4; i++) {
			OP(A, B, C, D, 7, *pc++);
			OP(D, A, B, C, 12, *pc++);
			OP(C, D, A, B, 17, *pc++);
			OP(B, C, D, A, 22, *pc++);
		}
#  else
		OP(A, B, C, D, 7, 0xd76aa478);
		OP(D, A, B, C, 12, 0xe8c7b756);
		OP(C, D, A, B, 17, 0x242070db);
		OP(B, C, D, A, 22, 0xc1bdceee);
		OP(A, B, C, D, 7, 0xf57c0faf);
		OP(D, A, B, C, 12, 0x4787c62a);
		OP(C, D, A, B, 17, 0xa8304613);
		OP(B, C, D, A, 22, 0xfd469501);
		OP(A, B, C, D, 7, 0x698098d8);
		OP(D, A, B, C, 12, 0x8b44f7af);
		OP(C, D, A, B, 17, 0xffff5bb1);
		OP(B, C, D, A, 22, 0x895cd7be);
		OP(A, B, C, D, 7, 0x6b901122);
		OP(D, A, B, C, 12, 0xfd987193);
		OP(C, D, A, B, 17, 0xa679438e);
		OP(B, C, D, A, 22, 0x49b40821);
#  endif	/* MD5_SIZE_VS_SPEED == 1 */

		/* For the second to fourth round we have the possibly swapped words
		   in CORRECT_WORDS.  Redefine the macro to take an additional first
		   argument specifying the function to use.  */
#  undef OP
#  define OP(f, a, b, c, d, k, s, T) \
	do { \
		a += f (b, c, d) + correct_words[k] + T; \
		CYCLIC (a, s); \
		a += b; \
	} while (0)

		/* Round 2.  */
#  if MD5_SIZE_VS_SPEED == 1
		pp = P_array;
		for (i = 0; i < 4; i++) {
			OP(FG, A, B, C, D, (int) (*pp++), 5, *pc++);
			OP(FG, D, A, B, C, (int) (*pp++), 9, *pc++);
			OP(FG, C, D, A, B, (int) (*pp++), 14, *pc++);
			OP(FG, B, C, D, A, (int) (*pp++), 20, *pc++);
		}
#  else
		OP(FG, A, B, C, D, 1, 5, 0xf61e2562);
		OP(FG, D, A, B, C, 6, 9, 0xc040b340);
		OP(FG, C, D, A, B, 11, 14, 0x265e5a51);
		OP(FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
		OP(FG, A, B, C, D, 5, 5, 0xd62f105d);
		OP(FG, D, A, B, C, 10, 9, 0x02441453);
		OP(FG, C, D, A, B, 15, 14, 0xd8a1e681);
		OP(FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
		OP(FG, A, B, C, D, 9, 5, 0x21e1cde6);
		OP(FG, D, A, B, C, 14, 9, 0xc33707d6);
		OP(FG, C, D, A, B, 3, 14, 0xf4d50d87);
		OP(FG, B, C, D, A, 8, 20, 0x455a14ed);
		OP(FG, A, B, C, D, 13, 5, 0xa9e3e905);
		OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
		OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
		OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
#  endif	/* MD5_SIZE_VS_SPEED == 1 */

		/* Round 3.  */
#  if MD5_SIZE_VS_SPEED == 1
		for (i = 0; i < 4; i++) {
			OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++);
			OP(FH, D, A, B, C, (int) (*pp++), 11, *pc++);
			OP(FH, C, D, A, B, (int) (*pp++), 16, *pc++);
			OP(FH, B, C, D, A, (int) (*pp++), 23, *pc++);
		}
#  else
		OP(FH, A, B, C, D, 5, 4, 0xfffa3942);
		OP(FH, D, A, B, C, 8, 11, 0x8771f681);
		OP(FH, C, D, A, B, 11, 16, 0x6d9d6122);
		OP(FH, B, C, D, A, 14, 23, 0xfde5380c);
		OP(FH, A, B, C, D, 1, 4, 0xa4beea44);
		OP(FH, D, A, B, C, 4, 11, 0x4bdecfa9);
		OP(FH, C, D, A, B, 7, 16, 0xf6bb4b60);
		OP(FH, B, C, D, A, 10, 23, 0xbebfbc70);
		OP(FH, A, B, C, D, 13, 4, 0x289b7ec6);
		OP(FH, D, A, B, C, 0, 11, 0xeaa127fa);
		OP(FH, C, D, A, B, 3, 16, 0xd4ef3085);
		OP(FH, B, C, D, A, 6, 23, 0x04881d05);
		OP(FH, A, B, C, D, 9, 4, 0xd9d4d039);
		OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
		OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
		OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
#  endif	/* MD5_SIZE_VS_SPEED == 1 */

		/* Round 4.  */
#  if MD5_SIZE_VS_SPEED == 1
		for (i = 0; i < 4; i++) {
			OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++);
			OP(FI, D, A, B, C, (int) (*pp++), 10, *pc++);
			OP(FI, C, D, A, B, (int) (*pp++), 15, *pc++);
			OP(FI, B, C, D, A, (int) (*pp++), 21, *pc++);
		}
#  else
		OP(FI, A, B, C, D, 0, 6, 0xf4292244);
		OP(FI, D, A, B, C, 7, 10, 0x432aff97);
		OP(FI, C, D, A, B, 14, 15, 0xab9423a7);
		OP(FI, B, C, D, A, 5, 21, 0xfc93a039);
		OP(FI, A, B, C, D, 12, 6, 0x655b59c3);
		OP(FI, D, A, B, C, 3, 10, 0x8f0ccc92);
		OP(FI, C, D, A, B, 10, 15, 0xffeff47d);
		OP(FI, B, C, D, A, 1, 21, 0x85845dd1);
		OP(FI, A, B, C, D, 8, 6, 0x6fa87e4f);
		OP(FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
		OP(FI, C, D, A, B, 6, 15, 0xa3014314);
		OP(FI, B, C, D, A, 13, 21, 0x4e0811a1);
		OP(FI, A, B, C, D, 4, 6, 0xf7537e82);
		OP(FI, D, A, B, C, 11, 10, 0xbd3af235);
		OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
		OP(FI, B, C, D, A, 9, 21, 0xeb86d391);
#  endif	/* MD5_SIZE_VS_SPEED == 1 */
# endif	/* MD5_SIZE_VS_SPEED > 1 */

		/* Add the starting values of the context.  */
		A += A_save;
		B += B_save;
		C += C_save;
		D += D_save;

	/* Put checksum in context given as argument.  */
	ctx->A = A;
	ctx->B = B;
	ctx->C = C;
	ctx->D = D;
}
Example #24
0
static void lb_write_back(double *f, double PFI, int x, int y) {

  int xc = x%WGRID;

  f[ 0] = FI( 0, xc)[y];
  f[ 1] = FI( 1, xc)[y];
  f[ 2] = FI( 2, xc)[y];
  f[ 3] = FI( 3, xc)[y];
  f[ 4] = FI( 4, xc)[y];
  f[ 5] = FI( 5, xc)[y];
  f[ 6] = FI( 6, xc)[y];
  f[ 7] = FI( 7, xc)[y];
  f[ 8] = FI( 8, xc)[y];
  f[ 9] = FI( 9, xc)[y];
  f[10] = FI(10, xc)[y];
  f[11] = FI(11, xc)[y];
  f[12] = FI(12, xc)[y];
  f[13] = FI(13, xc)[y];
  f[14] = FI(14, xc)[y];
  f[15] = FI(15, xc)[y];
  f[16] = FI(16, xc)[y];
  f[17] = FI(17, xc)[y];
  f[18] = FI(18, xc)[y];
  f[19] = FI(19, xc)[y];
  f[20] = FI(20, xc)[y];

}
Example #25
0
static bool a2024(struct vidbuffer *src, struct vidbuffer *dst)
{
	int y;
	uae_u8 *srcbuf, *dstbuf;
	uae_u8 *dataline;
	int px, py, doff, pxcnt, dbl;
	int panel_width, panel_width_draw, panel_height, srcxoffset;
	bool f64, interlace, expand, wpb, less16;
	uae_u8 enp, dpl;
	bool hires, ntsc, found;
	int idline;
	int total_width, total_height;
	
	dbl = gfxvidinfo.ychange == 1 ? 2 : 1;
	doff = (128 * 2 / gfxvidinfo.xchange) * src->pixbytes;
	found = false;

	for (idline = 21; idline <= 29; idline += 8) {
		if (src->yoffset > (idline << VRES_MAX))
			continue;
		// min 178 max 234
		dataline = src->bufmem + (((idline << VRES_MAX) - src->yoffset) / gfxvidinfo.ychange) * src->rowbytes + (((200 << RES_MAX) - src->xoffset) / gfxvidinfo.xchange) * src->pixbytes;

#if 0
		write_log (_T("%02x%02x%02x %02x%02x%02x %02x%02x%02x %02x%02x%02x\n"),
			dataline[0 * doff + 0], dataline[0 * doff + 1], dataline[0 * doff + 2],
			dataline[1 * doff + 0], dataline[1 * doff + 1], dataline[1 * doff + 2],
			dataline[2 * doff + 0], dataline[2 * doff + 1], dataline[2 * doff + 2],
			dataline[3 * doff + 0], dataline[3 * doff + 1], dataline[3 * doff + 2]);
#endif

		if (FB(src, &dataline[0 * doff]))			// 0:B = 0
			continue;
		if (!FI(src, &dataline[0 * doff]))			// 0:I = 1
			continue;
		if (FI(src, &dataline[2 * doff]))			// 2:I = 0
			continue;
		if (!FI(src, &dataline[3 * doff]))			// 3:I = 1
			continue;

		ntsc = idline < 26;
		found = true;
		break;
	}

	if (!found)
		return false;

	px = py = 0;
	if (FB(src, &dataline[1 * doff])) // 1:B FN2
		px |= 2;
	if (FG(src, &dataline[1 * doff])) // 1:G FN1
		px |= 1;
	if (FR(src, &dataline[1 * doff])) // 1:R FN0
		py |= 1;

	f64 = FR(src, &dataline[0 * doff]) != 0;		// 0:R
	interlace = FG(src, &dataline[0 * doff]) != 0;	// 0:G (*Always zero)
	expand = FI(src, &dataline[1 * doff]) != 0;		// 1:I (*Always set)
	enp = FR(src, &dataline[2 * doff]) ? 1 : 0;		// 2:R (*ENP=3)
	enp |= FG(src, &dataline[2 * doff]) ? 2 : 0;	// 2:G
	wpb = FB(src, &dataline[2 * doff]) != 0;		// 2:B (*Always zero)
	dpl = FR(src, &dataline[3 * doff]) ? 1 : 0;		// 3:R (*DPL=3)
	dpl |= FG(src, &dataline[3 * doff]) ? 2 : 0;	// 3:G
	less16 = FB(src, &dataline[3 * doff]) != 0;		// 3:B

	/* (*) = AOS A2024 driver static bits. Not yet implemented in emulation. */

	if (f64) {
		panel_width = 336;
		panel_width_draw = px == 2 ? 352 : 336;
		pxcnt = 3;
		hires = false;
		srcxoffset = 113;
		if (px > 2)
			return false;
		total_width = 336 + 336 + 352;
	} else {
		panel_width = 512;
		panel_width_draw = 512;
		pxcnt = 2;
		hires = true;
		srcxoffset = 129;
		if (px > 1)
			return false;
		total_width = 512 + 512;
	}
	panel_height = ntsc ? 400 : 512;

	if (monitor != MONITOREMU_A2024) {
		clearmonitor(dst);
	}

#if 0
	write_log (_T("0 = F6-4:%d INTERLACE:%d\n"), f64, interlace);
	write_log (_T("1 = FN:%d EXPAND:%d\n"), py + px *2, expand);
	write_log (_T("2 = ENP:%d WPB=%d\n"), enp, wpb);
	write_log (_T("3 = DPL:%d LESS16=%d\n"), dpl, less16);
#endif
#if 0
	write_log (_T("%02x%02x%02x %02x%02x%02x %02x%02x%02x %02x%02x%02x %dx%d\n"),
		dataline[0 * doff + 0], dataline[0 * doff + 1], dataline[0 * doff + 2],
		dataline[1 * doff + 0], dataline[1 * doff + 1], dataline[1 * doff + 2],
		dataline[2 * doff + 0], dataline[2 * doff + 1], dataline[2 * doff + 2],
		dataline[3 * doff + 0], dataline[3 * doff + 1], dataline[3 * doff + 2],
		px, py);
#endif

	if (less16) {
		total_width -= 16;
		if (px == pxcnt - 1)
			panel_width_draw -= 16;
	}
	total_height = panel_height * dbl;
	
	srcbuf = src->bufmem + (((44 << VRES_MAX) - src->yoffset) / gfxvidinfo.ychange) * src->rowbytes + (((srcxoffset << RES_MAX) - src->xoffset) / gfxvidinfo.xchange) * src->pixbytes;
	dstbuf = dst->bufmem + py * (panel_height / gfxvidinfo.ychange) * dst->rowbytes + px * ((panel_width * 2) / gfxvidinfo.xchange) * dst->pixbytes;

	for (y = 0; y < (panel_height / (dbl == 1 ? 1 : 2)) / gfxvidinfo.ychange; y++) {
#if 0
		memcpy (dstbuf, srcbuf, ((panel_width * 2) / gfxvidinfo.xchange) * dst->pixbytes);
#else
		uae_u8 *srcp = srcbuf;
		uae_u8 *dstp1 = dstbuf;
		uae_u8 *dstp2 = dstbuf + dst->rowbytes;
		int x;
		for (x = 0; x < (panel_width_draw * 2) / gfxvidinfo.xchange; x++) {
			uae_u8 c1 = 0, c2 = 0;
			if (FR(src, srcp)) // R
				c1 |= 2;
			if (FG(src, srcp)) // G
				c2 |= 2;
			if (FB(src, srcp)) // B
				c1 |= 1;
			if (FI(src, srcp)) // I
				c2 |= 1;
			if (dpl == 0) {
				c1 = c2 = 0;
			} else if (dpl == 1) {
				c1 &= 1;
				c1 |= c1 << 1;
				c2 &= 1;
				c2 |= c2 << 1;
			} else if (dpl == 2) {
				c1 &= 2;
				c1 |= c1 >> 1;
				c2 &= 2;
				c2 |= c2 >> 1;
			}
			if (dbl == 1) {
				c1 = (c1 + c2 + 1) / 2;
				c1 = (c1 << 6) | (c1 << 4) | (c1 << 2) | (c1 << 0);
				PRGB(dst, dstp1, c1, c1, c1);
			} else {
				c1 = (c1 << 6) | (c1 << 4) | (c1 << 2) | (c1 << 0);
				c2 = (c2 << 6) | (c2 << 4) | (c2 << 2) | (c2 << 0);
				PRGB(dst, dstp1, c1, c1, c1);
				PRGB(dst, dstp2, c2, c2, c2);
				dstp2 += dst->pixbytes;
			}
			srcp += src->pixbytes;
			if (!hires)
				srcp += src->pixbytes;
			dstp1 += dst->pixbytes;
		}
#endif
		srcbuf += src->rowbytes * dbl;
		dstbuf += dst->rowbytes * dbl;
	}
Example #26
0
static bool graffiti(struct vidbuffer *src, struct vidbuffer *dst)
{
	int y, x;
	int ystart, yend, isntsc;
	int xstart, xend;
	uae_u8 *srcbuf, *srcend;
	uae_u8 *dstbuf;
	bool command, hires, found;
	int xadd, xpixadd, extrapix;
	int waitline = 0, dbl;
	uae_u8 read_mask = 0xff, color = 0, color2 = 0;

	if (!(bplcon0 & 0x0100)) // GAUD
		return false;

	command = true;
	found = false;
	isntsc = (beamcon0 & 0x20) ? 0 : 1;
	if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS))
		isntsc = currprefs.ntscmode ? 1 : 0;

	dbl = gfxvidinfo.ychange == 1 ? 2 : 1;

	ystart = isntsc ? VBLANK_ENDLINE_NTSC : VBLANK_ENDLINE_PAL;
	yend = isntsc ? MAXVPOS_NTSC : MAXVPOS_PAL;
	if (src->yoffset >= (ystart << VRES_MAX))
		ystart = src->yoffset >> VRES_MAX;

	xadd = gfxvidinfo.xchange == 1 ? src->pixbytes * 2 : src->pixbytes;
	xpixadd = gfxvidinfo.xchange == 1 ? 4 : 2;

	xstart = 0x1c * 2 + 1;
	xend = 0xf0 * 2 + 1;

	srcbuf = src->bufmem + (((ystart << VRES_MAX) - src->yoffset) / gfxvidinfo.ychange) * src->rowbytes + (((xstart << RES_MAX) - src->xoffset) / gfxvidinfo.xchange) * src->pixbytes;
	srcend = src->bufmem + (((yend << VRES_MAX) - src->yoffset) / gfxvidinfo.ychange) * src->rowbytes;
	extrapix = 0;

	dstbuf = dst->bufmem + (((ystart << VRES_MAX) - src->yoffset) / gfxvidinfo.ychange) * dst->rowbytes + (((xstart << RES_MAX) - src->xoffset) / gfxvidinfo.xchange) * dst->pixbytes;

	y = 0;
	while (srcend > srcbuf && dst->bufmemend > dstbuf) {
		uae_u8 *srcp = srcbuf + extrapix;
		uae_u8 *dstp = dstbuf;

		x = xstart;
		while (x < xend) {
			
			uae_u8 mask = 0x80;
			uae_u8 chunky[4] = { 0, 0, 0, 0 };
			while (mask) {
				if (FR(src, srcp)) // R
					chunky[3] |= mask;
				if (FG(src, srcp)) // G
					chunky[2] |= mask;
				if (FB(src, srcp)) // B
					chunky[1] |= mask;
				if (FI(src, srcp)) // I
					chunky[0] |= mask;
				srcp += xadd;
				mask >>= 1;
			}

			if (command) {
				if (chunky[0] || chunky[1] || chunky[2] || chunky[3] || found) {
					for (int pix = 0; pix < 2; pix++) {
						uae_u8 cmd = chunky[pix * 2 + 0];
						uae_u8 parm = chunky[pix * 2 + 1];

#if 0
						//if (cmd != 0)
							write_log(_T("X=%d Y=%d %02x = %02x (%d %d)\n"), x, y, cmd, parm, color, color2);
#endif

						if (automatic && cmd >= 0x40)
							return false;
						if (cmd != 0)
							found = true;
						if (cmd & 8) {
							command = false;
							dbl = 1;
							waitline = 2;
							if (cmd & 16) {
								hires = true;
								xadd /= 2;
								xpixadd /= 2;
								extrapix = -4 * src->pixbytes;
							} else {
								hires = false;
							}
							if (xpixadd == 0) // shres needed
								return false;
							if (monitor != MONITOREMU_GRAFFITI)
								clearmonitor(dst);
						} else if (cmd & 4) {
							if ((cmd & 3) == 1) {
								read_mask = parm;
							} else if ((cmd & 3) == 2) {
								graffiti_palette[color * 4 + color2] = (parm << 2) | (parm & 3);
								color2++;
								if (color2 == 3) {
									color2 = 0;
									color++;
								}
							} else if ((cmd & 3) == 0) {
								color = parm;
								color2 = 0;
							}
						}
					}
				}

				memset(dstp, 0, dst->pixbytes * 4 * 2);
				dstp += dst->pixbytes * 4 * 2;

			} else if (waitline) {
			
				memset(dstp, 0, dst->pixbytes * 4 * 2);
				dstp += dst->pixbytes * 4 * 2;
			
			} else {

				for (int pix = 0; pix < 4; pix++) {
					uae_u8 r, g, b, c;
					
					c = chunky[pix] & read_mask;
					r = graffiti_palette[c * 4 + 0];
					g = graffiti_palette[c * 4 + 1];
					b = graffiti_palette[c * 4 + 2];
					PRGB(dst, dstp, r, g, b);
					dstp += dst->pixbytes;
					PRGB(dst, dstp, r, g, b);
					dstp += dst->pixbytes;
					
					if (gfxvidinfo.xchange == 1 && !hires) {
						PRGB(dst, dstp, r, g, b);
						dstp += dst->pixbytes;
						PRGB(dst, dstp, r, g, b);
						dstp += dst->pixbytes;
					}
				}

			}

			x += xpixadd;
		}

		y++;
		srcbuf += src->rowbytes * dbl;
		dstbuf += dst->rowbytes * dbl;
		if (waitline > 0)
			waitline--;
	}

	dst->nativepositioning = true;

	if (monitor != MONITOREMU_GRAFFITI) {
		monitor = MONITOREMU_GRAFFITI;
		write_log (_T("GRAFFITI %s mode\n"), hires ? _T("hires") : _T("lores"));
	}

	return true;
}
Example #27
0
/* Hash a single block, 64 bytes long and 4-byte aligned. */
static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
{
	uint32_t correct_words[16];
	const uint32_t *words = buffer;

	static const uint32_t C_array[] = {
		/* round 1 */
		0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
		0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
		0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
		0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
		/* round 2 */
		0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
		0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
		0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
		0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
		/* round 3 */
		0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
		0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
		0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
		0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
		/* round 4 */
		0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
		0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
		0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
		0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
	};

	static const char P_array[] = {
		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,	/* 1 */
		1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12,	/* 2 */
		5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2,	/* 3 */
		0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9	/* 4 */
	};

	static const char S_array[] = {
		7, 12, 17, 22,
		5, 9, 14, 20,
		4, 11, 16, 23,
		6, 10, 15, 21
	};

	uint32_t A = ctx->A;
	uint32_t B = ctx->B;
	uint32_t C = ctx->C;
	uint32_t D = ctx->D;

	uint32_t *cwp = correct_words;

#  define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))

	const uint32_t *pc;
	const char *pp;
	const char *ps;
	int i;
	uint32_t temp;

	for (i = 0; i < 16; i++) {
		cwp[i] = SWAP_LE32(words[i]);
	}
	words += 16;

	pc = C_array;
	pp = P_array;
	ps = S_array;

	for (i = 0; i < 16; i++) {
		temp = A + FF(B, C, D) + cwp[(int) (*pp++)] + *pc++;
		CYCLIC(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}

	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FG(B, C, D) + cwp[(int) (*pp++)] + *pc++;
		CYCLIC(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}
	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FH(B, C, D) + cwp[(int) (*pp++)] + *pc++;
		CYCLIC(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}
	ps += 4;
	for (i = 0; i < 16; i++) {
		temp = A + FI(B, C, D) + cwp[(int) (*pp++)] + *pc++;
		CYCLIC(temp, ps[i & 3]);
		temp += B;
		A = D;
		D = C;
		C = B;
		B = temp;
	}


	ctx->A += A;
	ctx->B += B;
	ctx->C += C;
	ctx->D += D;
}
//
// Function that sets myRelation pointers in a tree.
//
void Formula::set_relation(Rel_Body *r) {
  myRelation = r;
  for(List_Iterator<Formula *> FI(myChildren); FI; FI++)
    (*FI)->set_relation(r);
}