Esempio n. 1
0
// Use packed bootstrapping, so we can bootstrap all in just one go.
void packedRecrypt(const CtPtrs& cPtrs,
                   const std::vector<zzX>& unpackConsts,
                   const EncryptedArray& ea)
{
  FHEPubKey& pKey = (FHEPubKey&)cPtrs[0]->getPubKey();

  // Allocate temporary ciphertexts for the recryption
  int nPacked = divc(cPtrs.size(), ea.getDegree()); // ceil(totoalNum/d)
  std::vector<Ctxt> cts(nPacked, Ctxt(pKey));

  repack(CtPtrs_vectorCt(cts), cPtrs, ea);  // pack ciphertexts
  //  cout << "@"<< lsize(cts)<<std::flush;
  for (Ctxt& c: cts) {     // then recrypt them
    c.reducePtxtSpace(2);  // we only have recryption data for binary ctxt
#ifdef DEBUG_PRINTOUT
    ZZX ptxt;
    decryptAndPrint((cout<<"  before recryption "), c, *dbgKey, *dbgEa);
    dbgKey->Decrypt(ptxt, c);
    c.DummyEncrypt(ptxt);
    decryptAndPrint((cout<<"  after recryption "), c, *dbgKey, *dbgEa);
#else
    pKey.reCrypt(c);
#endif
  }
  unpack(cPtrs, CtPtrs_vectorCt(cts), ea, unpackConsts);
}
Esempio n. 2
0
void MDFN_BackupSavFile(const uint8 max_backup_count, const char* sav_ext)
{
    FileStream cts(MDFN_MakeFName(MDFNMKF_SAVBACK, -1, sav_ext), FileStream::MODE_READ_WRITE, true);
    std::unique_ptr<MemoryStream> tmp;
    uint8 counter = max_backup_count - 1;

    cts.read(&counter, 1, false);
//
//
    try
    {
        tmp.reset(new MemoryStream(new FileStream(MDFN_MakeFName(MDFNMKF_SAV, 0, sav_ext), FileStream::MODE_READ)));
    }
    catch(MDFN_Error& e)
    {
        if(e.GetErrno() == ENOENT)
            return;

        throw;
    }
//
//
//
    {
        try
        {
            MemoryStream oldbks(new GZFileStream(MDFN_MakeFName(MDFNMKF_SAVBACK, counter, sav_ext), GZFileStream::MODE::READ));

            if(oldbks.size() == tmp->size() && !memcmp(oldbks.map(), tmp->map(), oldbks.size()))
            {
                //puts("Skipped backup.");
                return;
            }
        }
        catch(MDFN_Error& e)
        {
            if(e.GetErrno() != ENOENT)
                throw;
        }
        //
        counter = (counter + 1) % max_backup_count;
        //
        GZFileStream bks(MDFN_MakeFName(MDFNMKF_SAVBACK, counter, sav_ext), GZFileStream::MODE::WRITE, 9);

        bks.write(tmp->map(), tmp->size());

        bks.close();
    }

//
//
    cts.rewind();
    cts.write(&counter, 1);
    cts.close();
}
Esempio n. 3
0
static void PrintFoldmapHisto( const uint8* fm, int w, int h )
{
	vector<int>	cts( 256, 0 );
	int			i, n = w * h;

	for( i = 0; i < n; ++i )
		++cts[fm[i]];

	for( i = 0; i < 256; ++i ) {

		if( cts[i] )
			printf( "Foldmask: value=%3d, count=%8d\n", i, cts[i] );
	}
}
Esempio n. 4
0
IRAM NOINSTR static void esp_handle_uart_int(struct esp_uart_state *us) {
  const int uart_no = us->cfg->uart_no;
  /* Since both UARTs use the same int, we need to apply the mask manually. */
  const unsigned int int_st = READ_PERI_REG(UART_INT_ST(uart_no)) &
                              READ_PERI_REG(UART_INT_ENA(uart_no));
  if (int_st == 0) return;
  us->stats.ints++;
  if (int_st & UART_RXFIFO_OVF_INT_ST) us->stats.rx_overflows++;
  if (int_st & UART_CTS_CHG_INT_ST) {
    if (cts(uart_no) != 0 && tx_fifo_len(uart_no) > 0) us->stats.tx_throttles++;
  }
  if (int_st & (UART_RX_INTS | UART_TX_INTS)) {
    if (int_st & UART_RX_INTS) us->stats.rx_ints++;
    if (int_st & UART_TX_INTS) us->stats.tx_ints++;
    /* Wake up the processor and disable TX and RX ints until it runs. */
    WRITE_PERI_REG(UART_INT_ENA(uart_no), UART_INFO_INTS);
    us->cfg->dispatch_cb(uart_no);
  }
  WRITE_PERI_REG(UART_INT_CLR(uart_no), int_st);
}
Esempio n. 5
0
void esp_uart_print_status(void *arg) {
  struct esp_uart_state *us = (struct esp_uart_state *) arg;
  struct esp_uart_stats *s = &us->stats;
  struct esp_uart_stats *ps = &us->prev_stats;
  int uart_no = us->cfg->uart_no;
  fprintf(
      stderr,
      "UART%d ints %u/%u/%u; rx en %d bytes %u buf %u fifo %u, ovf %u, lcs %u; "
      "tx %u %u %u, thr %u; hf %u i 0x%03x ie 0x%03x cts %d\n",
      uart_no, s->ints - ps->ints, s->rx_ints - ps->rx_ints,
      s->tx_ints - ps->tx_ints, us->rx_enabled, s->rx_bytes - ps->rx_bytes,
      us->rx_buf.used, rx_fifo_len(us->cfg->uart_no),
      s->rx_overflows - ps->rx_overflows,
      s->rx_linger_conts - ps->rx_linger_conts, s->tx_bytes - ps->tx_bytes,
      us->tx_buf.used, tx_fifo_len(us->cfg->uart_no),
      s->tx_throttles - ps->tx_throttles, system_get_free_heap_size(),
      READ_PERI_REG(UART_INT_RAW(uart_no)),
      READ_PERI_REG(UART_INT_ENA(uart_no)), cts(uart_no));
  memcpy(ps, s, sizeof(*s));
}
Esempio n. 6
0
void runConflictRefinerWithPreferences(IloCP cp, 
                                       IloConstraintArray preferredCts, 
                                       IloConstraintArray otherCts) {
  IloEnv env = cp.getEnv();
  IloConstraintArray cts(env);  
  IloNumArray prefs(env);
  IloInt i;
  for (i=0; i<otherCts.getSize(); ++i) {
    cts.add(otherCts[i]);
    prefs.add(1.0); // Normal preference
  }
  for (i=0; i<preferredCts.getSize(); ++i) {
    cts.add(preferredCts[i]);
    prefs.add(2.0); // Higher preference
  }
  if (cp.refineConflict(cts, prefs)) {
    cp.writeConflict(cp.out());
  } 
  cts.end();
  prefs.end();
}
Esempio n. 7
0
void CProcessor::PrintSpeed(Stroka strUrl)
{
    if (DocCount % 50 == 0) {
        time_t curTime = time(&curTime);
        CTimeSpan cts(curTime - StartTime);
        double vm, tm;  //  Объем и время
        vm = (double) TotalVolume / 1048576.0;
        tm = (double) cts.GetTotalSeconds();
        double speed = (vm * 3600) / tm;
        Stroka intervalTime;
        intervalTime = Substitute("$0:$1:$2", cts.GetHours(), cts.GetMinutes(), cts.GetSeconds());

        double iTouchedSents = 0;
        if (SentenceCount != 0)
            iTouchedSents = 100 * TouchedSentenceCount / SentenceCount;

        Stroka suTime;
        suTime = Sprintf("Time:%s Doc:%lu Vol:%.2fMb Speed:%.0fMb/h (%s), Used sentences:%.2f%%",
            intervalTime.c_str(), DocCount, vm, speed, strUrl.c_str(), iTouchedSents);
        Clog << suTime << '\r';
    }
}