コード例 #1
0
ファイル: h265.c プロジェクト: a2mSystemes/libvdpau-sunxi
static void ref_pic_lists_modification(struct h265_private *p)
{
	int i;

	p->slice.ref_pic_list_modification_flag_l0 = get_u(p->regs, 1);

	if (p->slice.ref_pic_list_modification_flag_l0)
		for (i = 0; i <= p->slice.num_ref_idx_l0_active_minus1; i++)
			p->slice.list_entry_l0[i] = get_u(p->regs, ceil_log2(p->info->NumPocTotalCurr));

	if (p->slice.slice_type == SLICE_B)
	{
		p->slice.ref_pic_list_modification_flag_l1 = get_u(p->regs, 1);

		if (p->slice.ref_pic_list_modification_flag_l1)
			for (i = 0; i <= p->slice.num_ref_idx_l1_active_minus1; i++)
				p->slice.list_entry_l1[i] = get_u(p->regs, ceil_log2(p->info->NumPocTotalCurr));
	}
}
コード例 #2
0
ファイル: ServerImpl.cpp プロジェクト: BobWay/rippled
void
ServerImpl::report (Stat&& stat)
{
    int const bucket = ceil_log2 (stat.requests);
    std::lock_guard <std::mutex> lock (mutex_);
    ++hist_[bucket];
    high_ = std::max (high_, bucket);
    if (stats_.size() >= historySize)
        stats_.pop_back();
    stats_.emplace_front (std::move(stat));
}
コード例 #3
0
            enumerator(succinct::bit_vector const& bv, uint64_t offset,
                       uint64_t universe, uint64_t n,
                       global_parameters const& params)
                : m_params(params)
                , m_size(n)
                , m_universe(universe)
                , m_bv(&bv)
            {
                succinct::bit_vector::enumerator it(bv, offset);
                m_partitions = read_gamma_nonzero(it);
                if (m_partitions == 1) {
                    m_cur_partition = 0;
                    m_cur_begin = 0;
                    m_cur_end = n;

                    uint64_t universe_bits = ceil_log2(universe);
                    m_cur_base = it.take(universe_bits);
                    auto ub = 0;
                    if (n > 1) {
                        uint64_t universe_delta = read_delta(it);
                        ub = universe_delta ? universe_delta : (universe - m_cur_base - 1);
                    }

                    m_partition_enum = base_sequence_enumerator
                        (*m_bv, it.position(), ub + 1, n, m_params);

                    m_cur_upper_bound = m_cur_base + ub;
                } else {
                    m_endpoint_bits = read_gamma(it);

                    uint64_t cur_offset = it.position();
                    m_sizes = compact_elias_fano::enumerator(bv, cur_offset,
                                                             n, m_partitions - 1,
                                                             params);
                    cur_offset += compact_elias_fano::bitsize(params, n,
                                                              m_partitions - 1);

                    m_upper_bounds = compact_elias_fano::enumerator(bv, cur_offset,
                                                                    universe, m_partitions + 1,
                                                                    params);
                    cur_offset += compact_elias_fano::bitsize(params, universe,
                                                              m_partitions + 1);

                    m_endpoints_offset = cur_offset;
                    uint64_t endpoints_size = m_endpoint_bits * (m_partitions - 1);
                    cur_offset += endpoints_size;

                    m_sequences_offset = cur_offset;
                }

                m_position = size();
                slow_move();
            }
コード例 #4
0
ファイル: cppbuiltin.c プロジェクト: AHelper/gcc
/* Define macros for size of basic C types.  */
static void
define_builtin_macros_for_type_sizes (cpp_reader *pfile)
{
#define define_type_sizeof(NAME, TYPE)                             \
    cpp_define_formatted (pfile, NAME"="HOST_WIDE_INT_PRINT_DEC,   \
                          tree_to_uhwi (TYPE_SIZE_UNIT (TYPE)))

  define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
  define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
  define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node);
  define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
  define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
  define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
  define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
  define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);

#undef define_type_sizeof

  cpp_define_formatted (pfile, "__CHAR_BIT__=%u",
			TYPE_PRECISION (char_type_node));
  cpp_define_formatted (pfile, "__BIGGEST_ALIGNMENT__=%d",
			BIGGEST_ALIGNMENT / BITS_PER_UNIT);

  /* Define constants useful for implementing endian.h.  */
  cpp_define (pfile, "__ORDER_LITTLE_ENDIAN__=1234");
  cpp_define (pfile, "__ORDER_BIG_ENDIAN__=4321");
  cpp_define (pfile, "__ORDER_PDP_ENDIAN__=3412");

  if (WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN)
    cpp_define_formatted (pfile, "__BYTE_ORDER__=%s",
			  (WORDS_BIG_ENDIAN
			   ? "__ORDER_BIG_ENDIAN__"
			   : "__ORDER_LITTLE_ENDIAN__"));
  else
    {
      /* Assert that we're only dealing with the PDP11 case.  */
      gcc_assert (!BYTES_BIG_ENDIAN);
      gcc_assert (WORDS_BIG_ENDIAN);

      cpp_define (pfile, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__");
    }

  cpp_define_formatted (pfile, "__FLOAT_WORD_ORDER__=%s",
                        (targetm.float_words_big_endian ()
                         ? "__ORDER_BIG_ENDIAN__"
                         : "__ORDER_LITTLE_ENDIAN__"));

  /* ptr_type_node can't be used here since ptr_mode is only set when
     toplev calls backend_init which is not done with -E switch.  */
  cpp_define_formatted (pfile, "__SIZEOF_POINTER__=%d",
			1 << ceil_log2 ((POINTER_SIZE + BITS_PER_UNIT - 1) / BITS_PER_UNIT));
}
コード例 #5
0
ファイル: test.c プロジェクト: MichalPokorny/thesis
static void test_ceil_log2(void) {
	assert(ceil_log2(1) == 0);
	assert(ceil_log2(2) == 1);
	assert(ceil_log2(3) == 2);
	assert(ceil_log2(4) == 2);
	assert(ceil_log2(6) == 3);
	assert(ceil_log2(134) == 8);
}
コード例 #6
0
ファイル: F_mpz_poly-profile.c プロジェクト: wbhart/flint1
void sample_F_mpz_poly_mul(ulong length, ulong bits,
                             void* arg, ulong count)
{
   ulong m = ceil_log2(length);
   ulong output_bits = 2*bits+m;
   
   F_mpz_poly_t poly1, poly2, poly3;
   mpz_poly_t r_poly, r_poly2;  
   
   mpz_poly_init(r_poly); 
   mpz_poly_init(r_poly2); 
   mpz_poly_realloc(r_poly, length);
   mpz_poly_realloc(r_poly2, length);
  
   F_mpz_poly_init2(poly1, length);
   F_mpz_poly_init2(poly2, length);
   F_mpz_poly_init2(poly3, 2*length-1);
   
   ulong r_count;    // how often to generate new random data
   
   if (count >= 1000) r_count = 100;
   else if (count >= 100) r_count = 10;
   else if (count >= 20) r_count = 5;
   else if (count >= 8) r_count = 2;
   else r_count = 1;
   
   for (ulong i = 0; i < count; i++)
   {
      if (i%r_count == 0)
      {
         randpoly(r_poly, length, bits);
         mpz_poly_to_F_mpz_poly(poly1, r_poly);
         randpoly(r_poly2, length, bits);
         mpz_poly_to_F_mpz_poly(poly2, r_poly2);
      }
      prof_start();
      F_mpz_poly_mul(poly3, poly1, poly2);
      prof_stop();
   }
   
   mpz_poly_clear(r_poly);
   mpz_poly_clear(r_poly2);
   
   F_mpz_poly_clear(poly3);
   F_mpz_poly_clear(poly2);
   F_mpz_poly_clear(poly1);
   
}
コード例 #7
0
ファイル: workfactor.cpp プロジェクト: louiz/botan
size_t mceliece_work_factor(size_t n, size_t t)
{
    const size_t k = n - ceil_log2(n) * t;

    double min = cout_total(n, k, t, 0, 0); // correspond a p=1
    for(size_t p = 0; p != t / 2; ++p)
    {
        double lwf = best_wf(n, k + 1, t, p);
        if(lwf < 0)
            break;

        min = std::min(min, lwf);
    }

    return min;
}
コード例 #8
0
ファイル: F_mpz_poly-profile.c プロジェクト: wbhart/flint1
void run_block(ulong max_length, double ratio)
{
	int max_iter = (int) ceil(log((double) max_length) / log(ratio));
	ulong last_length = 0;
	
	for (ulong i = 0; i <= max_iter; i++)
	{
		ulong length = (ulong) floor(pow(ratio, i));
      if (length != last_length)
      {
         last_length = length;
         ulong m = ceil_log2(length);
	         
         for (ulong bits = 1; bits <= 31; bits++)
	      {
		      if (m + 2*bits <= FLINT_BITS - 2) prof2d_sample(length, bits, NULL);
	      }
		}
	}
}
コード例 #9
0
ファイル: hashtab.c プロジェクト: Avinash-Bhat/tig
unsigned int
choose_multiplier (unsigned int d, unsigned int *mlp, unsigned char *shiftp)
{
  unsigned long long mhigh;
  double nx;
  int lgup, post_shift;
  int pow, pow2;
  int n = 32, precision = 32;

  lgup = ceil_log2 (d);
  pow = n + lgup;
  pow2 = n + lgup - precision;

  nx = ldexp (1.0, pow) + ldexp (1.0, pow2);
  mhigh = nx / d;

  *shiftp = lgup - 1;
  *mlp = mhigh;
  return mhigh >> 32;
}
コード例 #10
0
ファイル: nvbctlib_t114.c プロジェクト: zandar/barebox
void t114_init_bad_block_table(build_image_context *context)
{
    u_int32_t bytes_per_entry;
    nvboot_badblock_table *table;
    nvboot_config_table *bct;

    bct = (nvboot_config_table *)(context->bct);

    assert(context != NULL);
    assert(bct != NULL);

    table = &bct->badblock_table;

    bytes_per_entry = ICEIL(context->partition_size,
                            NVBOOT_BAD_BLOCK_TABLE_SIZE);
    table->block_size_log2 = context->block_size_log2;
    table->virtual_blk_size_log2 = NV_MAX(ceil_log2(bytes_per_entry),
                                          table->block_size_log2);
    table->entries_used = iceil_log2(context->partition_size,
                                     table->virtual_blk_size_log2);
}
コード例 #11
0
ファイル: tree-phinodes.c プロジェクト: 0mp/freebsd
static int
ideal_phi_node_len (int len)
{
  size_t size, new_size;
  int log2, new_len;

  /* We do not support allocations of less than two PHI argument slots.  */
  if (len < 2)
    len = 2;

  /* Compute the number of bytes of the original request.  */
  size = sizeof (struct tree_phi_node) + (len - 1) * sizeof (struct phi_arg_d);

  /* Round it up to the next power of two.  */
  log2 = ceil_log2 (size);
  new_size = 1 << log2;

  /* Now compute and return the number of PHI argument slots given an
     ideal size allocation.  */
  new_len = len + (new_size - size) / sizeof (struct phi_arg_d);
  return new_len;
}
コード例 #12
0
ファイル: h265.c プロジェクト: a2mSystemes/libvdpau-sunxi
static void slice_header(struct h265_private *p)
{
	int i;

	p->slice.first_slice_segment_in_pic_flag = get_u(p->regs, 1);

	if (p->nal_unit_type >= 16 && p->nal_unit_type <= 23)
		p->slice.no_output_of_prior_pics_flag = get_u(p->regs, 1);

	p->slice.slice_pic_parameter_set_id = get_ue(p->regs);

	if (!p->slice.first_slice_segment_in_pic_flag)
	{
		if (p->info->dependent_slice_segments_enabled_flag)
			p->slice.dependent_slice_segment_flag = get_u(p->regs, 1);

		p->slice.slice_segment_address = get_u(p->regs, ceil_log2(PicSizeInCtbsY));
	}

	if (!p->slice.dependent_slice_segment_flag)
	{
		p->slice.pic_output_flag = 1;
		p->slice.num_ref_idx_l0_active_minus1 = p->info->num_ref_idx_l0_default_active_minus1;
		p->slice.num_ref_idx_l1_active_minus1 = p->info->num_ref_idx_l1_default_active_minus1;
		p->slice.collocated_from_l0_flag = 1;
		p->slice.slice_deblocking_filter_disabled_flag = p->info->pps_deblocking_filter_disabled_flag;
		p->slice.slice_beta_offset_div2 = p->info->pps_beta_offset_div2;
		p->slice.slice_tc_offset_div2 = p->info->pps_tc_offset_div2;
		p->slice.slice_loop_filter_across_slices_enabled_flag = p->info->pps_loop_filter_across_slices_enabled_flag;

		skip_bits(p->regs, p->info->num_extra_slice_header_bits);

		p->slice.slice_type = get_ue(p->regs);

		if (p->info->output_flag_present_flag)
			p->slice.pic_output_flag = get_u(p->regs, 1);

		if (p->info->separate_colour_plane_flag == 1)
			p->slice.colour_plane_id = get_u(p->regs, 2);

		if (p->nal_unit_type != 19 && p->nal_unit_type != 20)
		{
			p->slice.slice_pic_order_cnt_lsb = get_u(p->regs, p->info->log2_max_pic_order_cnt_lsb_minus4 + 4);

			p->slice.short_term_ref_pic_set_sps_flag = get_u(p->regs, 1);

			skip_bits(p->regs, p->info->NumShortTermPictureSliceHeaderBits);

			if (p->info->long_term_ref_pics_present_flag)
				skip_bits(p->regs, p->info->NumLongTermPictureSliceHeaderBits);

			if (p->info->sps_temporal_mvp_enabled_flag)
				p->slice.slice_temporal_mvp_enabled_flag = get_u(p->regs, 1);
		}

		if (p->info->sample_adaptive_offset_enabled_flag)
		{
			p->slice.slice_sao_luma_flag = get_u(p->regs, 1);
			p->slice.slice_sao_chroma_flag = get_u(p->regs, 1);
		}

		if (p->slice.slice_type == SLICE_P || p->slice.slice_type == SLICE_B)
		{
			p->slice.num_ref_idx_active_override_flag = get_u(p->regs, 1);

			if (p->slice.num_ref_idx_active_override_flag)
			{
				p->slice.num_ref_idx_l0_active_minus1 = get_ue(p->regs);
				if (p->slice.slice_type == SLICE_B)
					p->slice.num_ref_idx_l1_active_minus1 = get_ue(p->regs);
			}

			if (p->info->lists_modification_present_flag && p->info->NumPocTotalCurr > 1)
				ref_pic_lists_modification(p);

			if (p->slice.slice_type == SLICE_B)
				p->slice.mvd_l1_zero_flag = get_u(p->regs, 1);

			if (p->info->cabac_init_present_flag)
				p->slice.cabac_init_flag = get_u(p->regs, 1);

			if (p->slice.slice_temporal_mvp_enabled_flag)
			{
				if (p->slice.slice_type == SLICE_B)
					p->slice.collocated_from_l0_flag = get_u(p->regs, 1);

				if ((p->slice.collocated_from_l0_flag && p->slice.num_ref_idx_l0_active_minus1 > 0) || (!p->slice.collocated_from_l0_flag && p->slice.num_ref_idx_l1_active_minus1 > 0))
					p->slice.collocated_ref_idx = get_ue(p->regs);
			}

			if ((p->info->weighted_pred_flag && p->slice.slice_type == SLICE_P) || (p->info->weighted_bipred_flag && p->slice.slice_type == SLICE_B))
				pred_weight_table(p);

			p->slice.five_minus_max_num_merge_cand = get_ue(p->regs);
		}

		p->slice.slice_qp_delta = get_se(p->regs);

		if (p->info->pps_slice_chroma_qp_offsets_present_flag)
		{
			p->slice.slice_cb_qp_offset = get_se(p->regs);
			p->slice.slice_cr_qp_offset = get_se(p->regs);
		}

		if (p->info->deblocking_filter_override_enabled_flag)
			p->slice.deblocking_filter_override_flag = get_u(p->regs, 1);

		if (p->slice.deblocking_filter_override_flag)
		{
			p->slice.slice_deblocking_filter_disabled_flag = get_u(p->regs, 1);

			if (!p->slice.slice_deblocking_filter_disabled_flag)
			{
				p->slice.slice_beta_offset_div2 = get_se(p->regs);
				p->slice.slice_tc_offset_div2 = get_se(p->regs);
			}
		}

		if (p->info->pps_loop_filter_across_slices_enabled_flag && (p->slice.slice_sao_luma_flag || p->slice.slice_sao_chroma_flag || !p->slice.slice_deblocking_filter_disabled_flag))
			p->slice.slice_loop_filter_across_slices_enabled_flag = get_u(p->regs, 1);
	}

	if (p->info->tiles_enabled_flag || p->info->entropy_coding_sync_enabled_flag)
	{
		p->slice.num_entry_point_offsets = get_ue(p->regs);

		if (p->slice.num_entry_point_offsets > 0)
		{
			p->slice.offset_len_minus1 = get_ue(p->regs);

			for (i = 0; i < p->slice.num_entry_point_offsets; i++)
				p->slice.entry_point_offset_minus1[i] = get_u(p->regs, p->slice.offset_len_minus1 + 1);
		}
	}

	if (p->info->slice_segment_header_extension_present_flag)
		skip_bits(p->regs, get_ue(p->regs) * 8);
}
コード例 #13
0
ファイル: naive-psi.cpp プロジェクト: encryptogroup/PSI
uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx,
		crypto* crypt_env, CSocket* sock, uint32_t ntasks, uint32_t* matches) {

	uint32_t i, intersect_size, maskbytelen;
	//task_ctx_naive ectx;
	CSocket* tmpsock = sock;

	uint32_t* perm;
	uint8_t *hashes, *phashes;

	maskbytelen = ceil_divide(crypt_env->get_seclvl().statbits + ceil_log2(neles) + ceil_log2(pneles), 8);

	hashes = (uint8_t*) malloc(sizeof(uint8_t) * neles * maskbytelen);
	perm  = (uint32_t*) malloc(sizeof(uint32_t) * neles);


	/* Generate the random permutation the elements */
	crypt_env->gen_rnd_perm(perm, neles);

	/* Hash and permute elements */
#ifdef DEBUG
	cout << "Hashing my elements" << endl;
#endif

	//ectx.eles.input = permeles;
	//ectx.eles.inbytelen = elebytelen;
	ectx.eles.outbytelen = maskbytelen,
	ectx.eles.nelements = neles;
	ectx.eles.output = hashes;
	ectx.eles.perm = perm;
	ectx.sctx.symcrypt = crypt_env;

	run_task(ntasks, ectx, psi_hashing_function);

	phashes = (uint8_t*) malloc(sizeof(uint8_t) * pneles * maskbytelen);


#ifdef DEBUG
	cout << "Exchanging hashes" << endl;
#endif
	snd_and_rcv(hashes, neles * maskbytelen, phashes, pneles * maskbytelen, tmpsock);

	/*cout << "Hashes of my elements: " << endl;
	for(i = 0; i < neles; i++) {
		for(uint32_t j = 0; j < maskbytelen; j++) {
			cout << (hex) << (uint32_t) hashes[i * maskbytelen + j] << (dec);
		}
		cout << endl;
	}

	cout << "Hashes of partner elements: " << endl;
	for(i = 0; i < pneles; i++) {
		for(uint32_t j = 0; j < maskbytelen; j++) {
			cout << (hex) << (uint32_t) phashes[i * maskbytelen + j] << (dec);
		}
		cout << endl;
	}*/
#ifdef DEBUG
	cout << "Finding intersection" << endl;
#endif
	intersect_size = find_intersection(hashes, neles, phashes, pneles, maskbytelen,
			perm, matches);


#ifdef DEBUG
	cout << "Free-ing allocated memory" << endl;
#endif
	free(perm);
	free(hashes);
	//free(permeles);
	free(phashes);

	return intersect_size;
}
コード例 #14
0
ファイル: faust-encode.cpp プロジェクト: tkind94/afin---faust
void Encode::process_read(uint8_t *data, size_t n, size_t reference, bool isrcomplement)
{
    assert(data);
    assert(n == read.length - 1);

    struct {
        int pos[MAX_READ_LENGTH];
        int len[MAX_READ_LENGTH];
    } ms = {{0}, {0}};

    // Compute matching statistics.
    int pos = block.index->dollar;
    int len = 0;
    int N = (int)n;
    for (int i = N - 1; i >= 0; i--) {
        block.index->extend_left(pos, len, data[i]);
        if (len && ms.len[i] < len) {
            ms.len[i] = len;
            ms.pos[i] = pos;
        }
    }

    std::unordered_map<size_t, Candidate> candidates;

    size_t computed_threshold = config.length_threshold;
    if (config.dynamic_threshold && (block.count - 1) < (input.nblocks * 0.5))
        computed_threshold = std::max((size_t)16, config.length_threshold / 2);

    for (size_t i = 0; i < n; i++) {
        if (ms.len[i] < (int)computed_threshold)
            continue;

        // Compute [s,e] range in SA from LCP and MS.
        int32_t *lcp = block.index->LCP;

        size_t s = ms.pos[i];
        while(1) {
            if (s == 0) break;
            if (lcp[s] < ms.len[i]) break;
            s--;
        }

        size_t e = ms.pos[i];
        while(1) {
            if (e == block.nbytes - 1) break;
            if (lcp[e + 1] < ms.len[i]) break;
            e++;
        }

        // Update candidates.
        for (size_t j = s; j <= e; j++) {
            size_t k = block.sa[j] / read.length;

	    // Already found a full match.
	    if (encoding[k].length == read.length - 1)
                continue;

	    // Only check against candidates that have an equal or better match length.
	    if (encoding[k].length > (size_t)ms.len[i])
                continue;

            auto it = candidates.find(k);

            if ((it == candidates.end()) ||
                (it != candidates.end() && candidates[k].length < (size_t)ms.len[i]))
                candidates[k] = {
                    block.sa[j] / read.length,
                    block.sa[j] % read.length,
                    i,
                    (size_t)ms.len[i]
                };
        }
    }

    size_t reference_bits = ceil_log2(read.processed + 1);
    size_t position_bits = ceil_log2((read.length - 1) - computed_threshold + 2);

    // Update block encoding data.
    for (auto it = candidates.begin(); it != candidates.end(); it++)
    {
        size_t index = it->first;

        Candidate candidate = it->second;

        size_t read_length = read.length - 1; // Excluding \n.

        // Already found a full match.
        if (encoding[index].length == read_length)
            continue;

        // Only check against candidates that have an equal or better match length.
        if (encoding[index].length > candidate.length)
            continue;

        size_t nbits = reference_bits + 1 + position_bits;

        // For an exact match we store the reference pointer and set pos (read.length+1).
        if (candidate.length < read_length) {
            nbits +=
                position_bits +
                ceil_log2(read_length -
                          std::max(candidate.ref_position,
                                   candidate.dst_position) + 1) +
                (2 * (read_length - candidate.length));
        }

        pthread_mutex_lock(&shared.encoding_mutex);

        if (encoding[index].nbits > nbits) {
            encoding[index].nbits = nbits;
            encoding[index].reference = reference;
            encoding[index].ref_position = candidate.ref_position;
            encoding[index].dst_position = candidate.dst_position;
            encoding[index].length = candidate.length;
            encoding[index].isrcomplement = isrcomplement;

            uint8_t *target = block.text + (index * read.length);
            size_t partition = candidate.dst_position;
            size_t j = 0;

            for (size_t i = 0; i < partition; i++)
                encoding[index].differences[j++] = target[i];

            for (size_t i = partition + candidate.length; i < (read.length - 1); i++)
                encoding[index].differences[j++] = target[i];

            assert(j == (read.length-1) - candidate.length);
        }

        pthread_mutex_unlock(&shared.encoding_mutex);
    }
}
コード例 #15
0
ファイル: kk-ot-ext-snd.cpp プロジェクト: mmaker/OTExtension
BOOL KKOTExtSnd::sender_routine(uint32_t id, uint64_t myNumOTs) {
    uint32_t choicecodebitlen = ceil_log2(m_nSndVals);
    uint64_t myStartPos = id * myNumOTs;
    uint64_t myStartPos1ooN = ceil_divide(myStartPos, choicecodebitlen);

    uint64_t wd_size_bits = m_nBlockSizeBits;
    uint64_t processedOTBlocks =
        min((uint64_t)NUMOTBLOCKS, ceil_divide(myNumOTs, wd_size_bits));
    uint64_t OTsPerIteration = processedOTBlocks * wd_size_bits;
    channel *chan = new channel(id, m_cRcvThread, m_cSndThread);
    uint64_t tmpctr, tmpotlen;
    uint64_t **rndmat;
    uint64_t processedOTs;

    myNumOTs = min(myNumOTs + myStartPos, m_nOTs) - myStartPos;
    // TODO some re-formating of myNumOTs due to 1ooN OT
    uint64_t lim = myStartPos1ooN + ceil_divide(myNumOTs, choicecodebitlen);

    if (myStartPos1ooN * choicecodebitlen > m_nOTs) {
        cerr << "Thread " << id
             << " not doing any work to align to window size " << endl;
        return true;
    }

// The vector with the received bits
#ifdef GENERATE_T_EXPLICITELY
    CBitVector vRcv(2 * m_nBaseOTs * OTsPerIteration);
#else
    CBitVector vRcv(m_nBaseOTs * OTsPerIteration);
#endif

    // Holds the reply that is sent back to the receiver
    CBitVector *vSnd;

    CBitVector *seedbuf = new CBitVector[m_nSndVals];
    for (uint32_t u = 0; u < m_nSndVals; u++) {
        seedbuf[u].Create(OTsPerIteration * m_cCrypt->get_aes_key_bytes() * 8);
    }
#ifdef ZDEBUG
    cout << "seedbuf size = " << OTsPerIteration *AES_KEY_BITS << endl;
#endif
    vSnd = new CBitVector[m_nSndVals];
    for (uint32_t i = 0; i < m_nSndVals; i++) {
        vSnd[i].Create(OTsPerIteration * choicecodebitlen * m_nBitLength);
    }

    // Contains the parts of the V matrix
    CBitVector Q(wd_size_bits * OTsPerIteration);

    uint64_t otid = myStartPos1ooN;

    uint8_t *rcvbuftmpptr, *rcvbufptr;

#ifdef OTTiming
    double totalMtxTime = 0, totalTnsTime = 0, totalHshTime = 0,
           totalRcvTime = 0, totalSndTime = 0, totalUnMaskTime = 0;
    timeval tempStart, tempEnd;
#endif

    if (m_eSndOTFlav == Snd_GC_OT) {
        uint8_t *rnd_seed = (uint8_t *)malloc(m_nSymSecParam);
        m_cCrypt->gen_rnd(rnd_seed, m_nSymSecParam);
        chan->send(rnd_seed, m_nSymSecParam);
        initRndMatrix(&rndmat, m_nBitLength, m_nBaseOTs);
        fillRndMatrix(rnd_seed, rndmat, m_nBitLength, m_nBaseOTs, m_cCrypt);
        free(rnd_seed);
    }

    while (otid < lim) // do while there are still transfers missing
    {
        processedOTBlocks =
            min((uint64_t)NUMOTBLOCKS, ceil_divide(lim - otid, wd_size_bits));
        OTsPerIteration = processedOTBlocks * wd_size_bits;
        processedOTs = min(lim - otid, OTsPerIteration);

#ifdef ZDEBUG
        cout << "Processing block " << nProgress
             << " with length: " << OTsPerIteration << ", and limit: " << lim
             << endl;
#endif

#ifdef OTTiming
        gettimeofday(&tempStart, NULL);
#endif
        ReceiveMasks(vRcv, chan, OTsPerIteration);

#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalRcvTime += getMillies(tempStart, tempEnd);
        gettimeofday(&tempStart, NULL);
#endif
        BuildQMatrix(Q, otid, processedOTBlocks);
#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalMtxTime += getMillies(tempStart, tempEnd);
        gettimeofday(&tempStart, NULL);
#endif
        UnMaskBaseOTs(Q, vRcv, processedOTBlocks);
#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalUnMaskTime += getMillies(tempStart, tempEnd);
        gettimeofday(&tempStart, NULL);
#endif
        Q.Transpose(wd_size_bits, OTsPerIteration);
#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalTnsTime += getMillies(tempStart, tempEnd);
        gettimeofday(&tempStart, NULL);
#endif
        KKHashValues(Q, seedbuf, vSnd, otid, processedOTs, rndmat);
#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalHshTime += getMillies(tempStart, tempEnd);
        gettimeofday(&tempStart, NULL);
#endif
        KKMaskAndSend(vSnd, otid, processedOTs, chan);
#ifdef OTTiming
        gettimeofday(&tempEnd, NULL);
        totalSndTime += getMillies(tempStart, tempEnd);
#endif
        otid += processedOTs;
        Q.Reset();
    }

    vRcv.delCBitVector();
    chan->synchronize_end();

    Q.delCBitVector();

    for (uint32_t i = 0; i < m_nSndVals; i++) {
        vSnd[i].delCBitVector();
    }
    delete vSnd;

    if (m_eSndOTFlav == Snd_GC_OT) {
        freeRndMatrix(rndmat, m_nBaseOTs);
    }

#ifdef OTTiming
    cout << "Sender time benchmark for performing " << myNumOTs << " OTs ("
         << lim - myStartPos1ooN << " 1ooN) on " << m_nBitLength
         << " bit strings" << endl;
    cout << "Time needed for: " << endl;
    cout << "\t Matrix Generation:\t" << totalMtxTime << " ms" << endl;
    cout << "\t Unmasking values:\t" << totalUnMaskTime << " ms" << endl;
    cout << "\t Sending Matrix:\t" << totalSndTime << " ms" << endl;
    cout << "\t Transposing Matrix:\t" << totalTnsTime << " ms" << endl;
    cout << "\t Hashing Matrix:\t" << totalHshTime << " ms" << endl;
    cout << "\t Receiving Values:\t" << totalRcvTime << " ms" << endl;
#endif

    delete chan;

    return TRUE;
}
コード例 #16
0
        static void write(succinct::bit_vector_builder& bvb,
                          Iterator begin,
                          uint64_t universe, uint64_t n,
                          global_parameters const& params)
        {
            assert(n > 0);
            auto const& conf = configuration::get();

            auto cost_fun = [&](uint64_t universe, uint64_t n) {
                return base_sequence_type::bitsize(params, universe, n) + conf.fix_cost;
            };

            optimal_partition opt(begin, universe, n, cost_fun, conf.eps1, conf.eps2);

            size_t partitions = opt.partition.size();
            assert(partitions > 0);
            assert(opt.partition.front() != 0);
            assert(opt.partition.back() == n);
            write_gamma_nonzero(bvb, partitions);

            std::vector<uint64_t> cur_partition;
            uint64_t cur_base = 0;
            if (partitions == 1) {
                cur_base = *begin;
                Iterator it = begin;

                for (size_t i = 0; i < n; ++i, ++it) {
                    cur_partition.push_back(*it - cur_base);
                }

                uint64_t universe_bits = ceil_log2(universe);
                bvb.append_bits(cur_base, universe_bits);

                // write universe only if non-singleton and not tight
                if (n > 1) {
                    if (cur_base + cur_partition.back() + 1 == universe) {
                        // tight universe
                        write_delta(bvb, 0);
                    } else {
                        write_delta(bvb, cur_partition.back());
                    }
                }

                base_sequence_type::write(bvb, cur_partition.begin(),
                                          cur_partition.back() + 1,
                                          cur_partition.size(),
                                          params);
            } else {
                succinct::bit_vector_builder bv_sequences;
                std::vector<uint64_t> endpoints;
                std::vector<uint64_t> upper_bounds;

                uint64_t cur_i = 0;
                Iterator it = begin;
                cur_base = *begin;
                upper_bounds.push_back(cur_base);

                for (size_t p = 0; p < opt.partition.size(); ++p) {
                    cur_partition.clear();
                    uint64_t value = 0;
                    for (; cur_i < opt.partition[p]; ++cur_i, ++it) {
                        value = *it;
                        cur_partition.push_back(value - cur_base);
                    }

                    uint64_t upper_bound = value;
                    assert(cur_partition.size() > 0);
                    base_sequence_type::write(bv_sequences, cur_partition.begin(),
                                              cur_partition.back() + 1,
                                              cur_partition.size(), // XXX skip last one?
                                              params);
                    endpoints.push_back(bv_sequences.size());
                    upper_bounds.push_back(upper_bound);
                    cur_base = upper_bound + 1;
                }

                succinct::bit_vector_builder bv_sizes;
                compact_elias_fano::write(bv_sizes, opt.partition.begin(),
                                          n, partitions - 1,
                                          params);

                succinct::bit_vector_builder bv_upper_bounds;
                compact_elias_fano::write(bv_upper_bounds, upper_bounds.begin(),
                                          universe, partitions + 1,
                                          params);

                uint64_t endpoint_bits = ceil_log2(bv_sequences.size() + 1);
                write_gamma(bvb, endpoint_bits);

                bvb.append(bv_sizes);
                bvb.append(bv_upper_bounds);

                for (uint64_t p = 0; p < endpoints.size() - 1; ++p) {
                    bvb.append_bits(endpoints[p], endpoint_bits);
                }

                bvb.append(bv_sequences);
            }
        }
コード例 #17
0
ファイル: kk-ot-ext-snd.cpp プロジェクト: mmaker/OTExtension
void KKOTExtSnd::KKHashValues(CBitVector &Q, CBitVector *seedbuf,
                              CBitVector *snd_buf, uint64_t OT_ptr,
                              uint64_t OT_len, uint64_t **mat_mul) {
    uint64_t numhashiters =
        ceil_divide(m_nBitLength, m_cCrypt->get_hash_bytes());
    uint32_t rowbytelen = bits_in_bytes(m_nBaseOTs);
    uint32_t hashinbytelen = rowbytelen + sizeof(uint64_t);
    uint32_t hashoutbitlen = ceil_log2(m_nSndVals);
    uint64_t wd_size_bytes =
        m_nBlockSizeBytes; // 1 << (ceil_log2(m_nBaseOTs) - 3);
    uint32_t u;
    uint32_t aes_key_bytes = m_cCrypt->get_aes_key_bytes();
    uint32_t choicebitlen = ceil_log2(m_nSndVals);

    uint64_t *Qptr = (uint64_t *)Q.GetArr();

    uint8_t **sbp = (uint8_t **)malloc(sizeof(uint8_t *) * m_nSndVals);
    uint8_t *inbuf = (uint8_t *)calloc(hashinbytelen, 1);
    uint8_t *resbuf = (uint8_t *)calloc(m_cCrypt->get_hash_bytes(), 1);
    uint8_t *hash_buf = (uint8_t *)calloc(m_cCrypt->get_hash_bytes(), 1);

    uint64_t *tmpbuf = (uint64_t *)calloc(
        PadToMultiple(bits_in_bytes(m_nBitLength), sizeof(uint64_t)), 1);
    uint8_t *tmpbufb = (uint8_t *)calloc(bits_in_bytes(m_nBitLength), 1);

    uint64_t global_OT_ptr = OT_ptr + m_nCounter;
    CBitVector mask(m_nCodeWordBits);

    for (u = 0; u < m_nSndVals; u++) {
        sbp[u] = seedbuf[u].GetArr();
    }

    for (uint64_t i = 0; i < OT_len; global_OT_ptr++, i++, Qptr += 2) {
        for (u = 0; u < m_nSndVals; u++) {
            mask.Copy(m_vU, 0, rowbytelen);
            mask.ANDBytes((uint8_t *)m_vCodeWords[u], 0, rowbytelen);
            mask.XORBytes(Q.GetArr() + i * rowbytelen, rowbytelen);

#ifdef DEBUG_OT_HASH_IN
            cout << "Hash-In for i = " << global_OT_ptr << ", u = " << u << ": "
                 << (hex);
            for (uint32_t p = 0; p < rowbytelen; p++)
                cout << setw(2) << setfill('0') << (uint32_t)mask.GetArr()[p];
            cout << (dec) << endl;
// cout << "Using codeword " << (hex) << m_vCodeWords[u][0] <<
// m_vCodeWords[u][1] << (hex) << m_vCodeWords[u][2] << m_vCodeWords[u][3] <<
// (dec) << endl;

#endif

            if (m_eSndOTFlav != Snd_GC_OT) {
#ifdef FIXED_KEY_AES_HASHING
                FixedKeyHashing(m_kCRFKey, sbp[u], (BYTE *)Qptr, hash_buf, i,
                                hashinbytelen, m_cCrypt);
#else
                memcpy(inbuf, &global_OT_ptr, sizeof(uint64_t));
                // memcpy(inbuf+sizeof(uint64_t), Q.GetArr() + i *
                // wd_size_bytes, rowbytelen);
                memcpy(inbuf + sizeof(uint64_t), mask.GetArr(), rowbytelen);
                m_cCrypt->hash_buf(resbuf, aes_key_bytes, inbuf, hashinbytelen,
                                   hash_buf);
                memcpy(sbp[u], resbuf, aes_key_bytes);
                // snd_buf[u].SetBits(resbuf, i * hashoutbitlen, hashoutbitlen);
            } else {
                // TODO: mecr has not been tested with KK-OT!!
                BitMatrixMultiplication(tmpbufb, bits_in_bytes(hashoutbitlen),
                                        mask.GetArr(), m_nBaseOTs, mat_mul,
                                        tmpbuf);
                // BitMatrixMultiplication(tmpbufb, bits_in_bytes(m_nBitLength),
                // Q.GetArr() + i * wd_size_bytes, m_nBaseOTs, mat_mul, tmpbuf);
                // m_vValues[u].SetBits(tmpbufb, (OT_ptr + i)* m_nBitLength,
                // m_nBitLength);
                snd_buf[u].SetBits(tmpbufb, i * hashoutbitlen, hashoutbitlen);
                // m_vTempOTMasks.SetBytes(tmpbufb, (uint64_t) (OT_ptr + i) *
                // aes_key_bytes, (uint64_t) aes_key_bytes);
                // m_vValues[u].SetBytes(Q.GetArr() + i * wd_size_bytes, (OT_ptr
                // + i)* wd_size_bytes, rowbytelen);
            }
#endif

#ifdef DEBUG_OT_HASH_OUT
                cout << "Hash-Out for i = " << global_OT_ptr << ", u = " << u
                     << ": " << (hex);
                for (uint32_t p = 0; p < aes_key_bytes; p++)
                    cout << setw(2) << setfill('0') << (uint32_t)sbp[u][p];
                cout << (dec) << endl;
#endif
                sbp[u] += m_cCrypt->get_aes_key_bytes();
            }
        }

        // TODO: difference is in here!! (could be solved by giving the
        // bit-length as parameter in the function call)
        for (uint32_t u = 0; u < m_nSndVals; u++) {
            m_fMaskFct->expandMask(&snd_buf[u], seedbuf[u].GetArr(), 0, OT_len,
                                   m_nBitLength * choicebitlen, m_cCrypt);
            // cout << "Mask " << u << ": ";
            // snd_buf[u].PrintHex();
        }

        // m_vValues[0].PrintHex();
        // m_vValues[1].PrintHex();

        free(resbuf);
        free(inbuf);
        free(sbp);
        free(hash_buf);
        free(tmpbuf);
        free(tmpbufb);
    }
コード例 #18
0
	/**
	 * @return "size class" of a given size.
	 * class i > 0 contains blocks of size (2**(i-1), 2**i].
	 **/
	static size_t SizeClass(size_t size)
	{
		return ceil_log2(size);
	}
コード例 #19
0
ファイル: faust-encode.cpp プロジェクト: tkind94/afin---faust
void Encode::write_block()
{
    size_t nomatch = 0;
    size_t nfullmatch = 0;
    size_t nrcomplement = 0;
    size_t nbits = 0;

    size_t computed_threshold = config.length_threshold;
    if (config.dynamic_threshold && (block.count - 1) < (input.nblocks * 0.5))
        computed_threshold = std::max((size_t)16, config.length_threshold / 2);

    size_t reference_bits = ceil_log2(read.processed + 1);
    size_t position_bits = ceil_log2((read.length - 1) - computed_threshold + 2);

    for (size_t i = 0; i < block.nreads; i++) {
        if (encoding[i].length == read.length - 1)
            nfullmatch++;

        if (encoding[i].isrcomplement)
            nrcomplement++;

        nbits += encoding[i].nbits;

        if (encoding[i].reference == SIZE_MAX) {
            nomatch++;

            output.stream->write(read.processed, reference_bits);

            uint8_t *target = block.text + (i * read.length);

            for (size_t j = 0; j < read.length - 1; j++) {
                uint8_t c = nucleotide_to_int[target[j]];
                output.stream->write(c, 2);
            }
        }
        else {
            output.stream->write(encoding[i].reference, reference_bits);
            output.stream->write(encoding[i].isrcomplement, 1);

            if (encoding[i].length == read.length - 1) {
                output.stream->write((read.length - 1) - computed_threshold + 1, position_bits);
                continue;
            }

            size_t length_bits = ceil_log2((read.length - 1) -
                                           std::max(encoding[i].ref_position,
                                                    encoding[i].dst_position) + 1);

            output.stream->write(encoding[i].ref_position, position_bits);
            output.stream->write(encoding[i].dst_position, position_bits);
            output.stream->write(encoding[i].length, length_bits);

            for (size_t j = 0; j < (read.length-1) - encoding[i].length; j++) {
                uint8_t c = nucleotide_to_int[encoding[i].differences[j]];
                output.stream->write(c, 2);
            }
        }
    }

    output.nbits += nbits;
    output.nomatch += nomatch;
    output.nfullmatch += nfullmatch;
    output.nrcomplement += nrcomplement;

    printf("\n");
    vmpeak(stdout);

    printf("\n");
    printf("block.id           : %zu\n", block.count);
    printf("block.nreads       : %zu\n", block.nreads);
    printf("block.nbytes       : %zu\n", block.nbytes);
    printf("block.nomatch      : %zu (%.2f%%)\n", nomatch, (nomatch/(double)block.nreads)*100.0);
    printf("block.fullmatch    : %zu (%.2f%%)\n", nfullmatch, (nfullmatch/(double)block.nreads)*100.0);
    printf("block.nrcomplement : %zu (%.2f%%)\n", nrcomplement, (nrcomplement/(double)block.nreads)*100.0);
    printf("block.nbits        : %zu\n", nbits);
    nbits += 7; // Round up to the nearest byte.
    printf("block.nbytes       : %zu (%.2f MB)\n", nbits / 8, nbits / 8.0 / 1e6);
    printf("block.threshold    : %zu\n", computed_threshold);
    printf("block.compression  : %.2f%%\n", ((nbits/8.0)/block.nbytes)*100.0);
    printf("\n");
    printf("computed_threshold: %zu\n", computed_threshold);
    printf("reference_bits: %zu\n", reference_bits);
    printf("position_bits: %zu\n", position_bits);
    printf("\n");
}
コード例 #20
0
ファイル: kk-ot-ext-snd.cpp プロジェクト: mmaker/OTExtension
    void KKOTExtSnd::KKMaskAndSend(CBitVector * snd_buf, uint64_t OT_ptr,
                                   uint64_t OT_len, channel * chan) {
        // m_fMaskFct->Mask(OT_ptr, OT_len, m_vValues, snd_buf, m_eSndOTFlav);

        uint32_t choicecodebits = ceil_log2(m_nSndVals);
        uint64_t valsize =
            bits_in_bytes(OT_len * m_nBitLength * choicecodebits);
        uint64_t bufsize = valsize * (m_nSndVals - 2); // For R-OT
        uint8_t *buf;
        buf = (uint8_t *)malloc(bufsize);
        CBitVector tmpmask(valsize * 8);
        CBitVector *snd_buf_ptr;

        // Define the X0 values as the output of 0 and the X1 values as output
        // of m_nSndVals-1 (only 1 values)
        m_vValues[0]->SetBytes(
            snd_buf[0].GetArr(),
            bits_in_bytes(OT_ptr * choicecodebits * m_nBitLength), valsize);
        m_vValues[1]->SetBytes(
            snd_buf[m_nSndVals - 1].GetArr(),
            bits_in_bytes(OT_ptr * choicecodebits * m_nBitLength), valsize);

#ifdef DEBUG_KK_OTBREAKDOWN
        cout << endl
             << "X0: ";
        m_vValues[0].PrintHex(0, valsize);
        cout << "X1: ";
        m_vValues[1].PrintHex(0, valsize);
#endif

        uint8_t *tmpbuf = (uint8_t *)malloc(bits_in_bytes(m_nBitLength));
        for (uint32_t i = 1; i < m_nSndVals - 1; i++) {
            tmpmask.Reset();
            for (uint32_t j = 0; j < choicecodebits; j++) {
                // write the value of snd_buf[0] or snd_buf[1] in every
                // choicecodebits position
                snd_buf_ptr = m_vValues[((i >> j) & 0x01)];
                for (uint32_t o = 0; o < OT_len; o++) {
                    memset(tmpbuf, 0, bits_in_bytes(m_nBitLength));
                    snd_buf_ptr->GetBits(tmpbuf, (OT_ptr + o) * choicecodebits *
                                                         m_nBitLength +
                                                     j * m_nBitLength,
                                         m_nBitLength);
                    tmpmask.SetBits(tmpbuf, o * choicecodebits * m_nBitLength +
                                                j * m_nBitLength,
                                    m_nBitLength);
                    // tmpmask.SetBit(i*choicecodebits + o,
                    // snd_buf_ptr->GetBit(i*choicecodebits + o));
                }
            }
#ifdef DEBUG_KK_OTBREAKDOWN
            cout << "Val " << i << ": ";
            tmpmask.PrintHex(0, valsize);
            cout << "Mask " << i << ": ";
            snd_buf[i].PrintHex(0, valsize);
#endif
            tmpmask.XORBytes(snd_buf[i].GetArr(), 0, valsize);
#ifdef DEBUG_KK_OTBREAKDOWN
            cout << "Res " << i << ": ";
            tmpmask.PrintHex(0, valsize);
#endif

            memcpy(buf + (i - 1) * valsize, tmpmask.GetArr(), valsize);
        }

        chan->send_id_len(buf, bufsize, OT_ptr, OT_len);
        free(buf);
        free(tmpbuf);
        tmpmask.delCBitVector();
    }
コード例 #21
0
ファイル: faust-encode.cpp プロジェクト: tkind94/afin---faust
bool Encode::next_block()
{
    if (block.count > 0) {
        read.processed += block.nreads;

        sem_destroy(&shared.mutex);
        sem_destroy(&shared.nempty);
        sem_destroy(&shared.nstored);
    }

    sem_init(&shared.mutex, 0, 1);

    sem_init(&shared.nempty, 0, MAX_THREADS);

    sem_init(&shared.nstored, 0, 0);

    shared.nread = 0;

    shared.nwrite = 0;

    shared.finished = false;

    block.nreads = config.block_size / read.length;

    char *ptr = (char*)block.text;

    size_t nbytes = 0;
    size_t i = 0;

    while (fgets(ptr, BUFSIZ, block.fp)) {
        size_t length = strlen(ptr);
        assert(length == read.length);

        ptr[length - 1] = '\0'; // Chomp.

        ptr += length;

        nbytes += length;

        i++;

        if (block.count == 0 &&
            i == block.raw_nreads)
            break;

        if (i == block.nreads)
            break;
    }

    if (i == 0)
        return false;

    block.nbytes = nbytes;

    block.nreads = i;

    for (i = 0; i < block.nreads; i++) {
        encoding[i].reference = SIZE_MAX;
        encoding[i].ref_position = 0;
        encoding[i].dst_position = 0;
        encoding[i].length = 0;
        encoding[i].isrcomplement = false;
        encoding[i].nbits = ceil_log2(read.processed + 1) + (2 * (read.length - 1));
    }

    block.count++;

    if (block.count == 1)
        return true; // We not need to build index for the initial raw block.

    divsufsort(block.text, block.sa, (int32_t)block.nbytes);

    if (block.index)
        delete block.index;

    block.index = new MatchingStatistics(block.text, block.sa, block.nbytes);

    return true;
}