uint64_t sieve_count(uint64_t* s, uint64_t prime_num, uint64_t first, uint64_t last, uint64_t L, uint64_t U, uint64_t* s2) { /*use Legendre sieve for 2, 3, and 5 so sieve s does not have to store numbers divisible by 2, 3, or 5*/ if (prime_num == 1) return last - (first -1); else if (prime_num == 2) return last - last/2 - (first - 1 - (first -1)/2); else if (prime_num == 3) return last - last/2 - last/3 + last/6 -((first - 1) - (first - 1)/2 - (first - 1)/3 + (first - 1)/6); uint64_t a, b, c, ans; if(first > 0) a = (first + NEXT[first % MOD])/MOD * GROUPS + POS[first % MOD]; else a = 0; if (last > 0) b = (last + PREV[last % MOD])/MOD * GROUPS + POS[last % MOD]; else b = 0; if (L > 1) c = (L-1 + PREV[(L-1) % MOD])/MOD * GROUPS + POS[(L-1) % MOD]; else c = 0; if(a - c > 0 && b - c > 0) ans = count_bits(s2, a - c, b - c); else ans = 0; // printf("L = %lu is bit %lu U is %lu\n", L, c, U); // printf("sieve count args: prime_num = %lu first = %lu last = %lu L = %lu, U = %lu\n",prime_num,first,last,L,U); //printf("a = %lu b = %lu c = %lu\n",a,b,c); // printf("start bit = %lu finish_bit = %lu\n", a-c, b-c); printf("L = %lu\ti = %lu\twheel = %lu\ttraditional = %lu\n",L, prime_num, ans, count_bits(s, first - L, last - L)); return count_bits(s, first - L, last - L); }
/* convert a netmask string (eg 255.255.255.0 or ffff:ff::) in +src+ into * the length (24) in +dst+. Return 0 if some sort of failure, or 1 on * success. */ int inet_ptom (int af, const char *src, unsigned int *dst) { union inX_addr addr; if (!empty_str(src)) { if (inet_pton (af, src, &addr) < 0) { *dst = 0; return 0; } } if (af == AF_INET) { *dst = count_bits(ntohl(addr.in4.s_addr)); return 1; } else if (af == AF_INET6) { int i, count; for (i = 0, *dst = 0; i < 4; i++) { count = count_bits(htonl(addr.in6.s6_addr32[i])); *dst += count; if (count != 32) break; /* Don't go any further if the mask has finished */ } return 1; } else { *dst = 0; return 0; } }
size_t BitMap::count() const{ size_t cnt = 0; for(auto i = array.rbegin() ; i != array.rend() ; ++i){ if (i == array.rbegin() && bitset_size % block_size){ cnt += count_bits(*i & ((1u << bitset_size % block_size) - 1)); } else { cnt += count_bits(*i); } } return cnt; }
bool LoRaPHYUS915Hybrid::validate_channel_mask(uint16_t* channel_masks) { bool mask_state = false; uint16_t block1 = 0; uint16_t block2 = 0; uint8_t index = 0; uint16_t temp_channel_masks[US915_HYBRID_CHANNEL_MASK_SIZE]; // Copy channels mask to not change the input for (uint8_t i = 0; i < 4; i++) { temp_channel_masks[i] = channel_masks[i]; } for(uint8_t i = 0; i < 4; i++) { block1 = temp_channel_masks[i] & 0x00FF; block2 = temp_channel_masks[i] & 0xFF00; if (count_bits(block1, 16) > 1) { temp_channel_masks[i] &= block1; temp_channel_masks[4] = 1 << ( i * 2 ); mask_state = true; index = i; break; } else if( count_bits( block2, 16 ) > 1 ) { temp_channel_masks[i] &= block2; temp_channel_masks[4] = 1 << ( i * 2 + 1 ); mask_state = true; index = i; break; } } // Do change the channel mask, if we have found a valid block. if (mask_state == true) { // Copy channels mask back again for (uint8_t i = 0; i < 4; i++) { channel_masks[i] = temp_channel_masks[i]; if (i != index) { channel_masks[i] = 0; } } channel_masks[4] = temp_channel_masks[4]; } return mask_state; }
TEST(BitMatrixTest, SetReset) { ocgl::BitMatrix m(4, 5); for (int i = 0; i < m.rows(); ++i) for (int j = 0; j < m.cols(); ++j) { EXPECT_EQ(0, count_bits(m)); m.set(i, j); EXPECT_EQ(1, count_bits(m)); m.reset(i, j); EXPECT_EQ(0, count_bits(m)); } }
int Scm_BitsCount0(const ScmBits *bits, int start, int end) { int sw = start / SCM_WORD_BITS; int ew = (end-1)/ SCM_WORD_BITS; int sb = start % SCM_WORD_BITS; int eb = end % SCM_WORD_BITS; if (start == end) return 0; if (sw == ew) return count_bits(~bits[sw] & SCM_BITS_MASK(sb, eb)); u_long num = count_bits(~bits[sw] & SCM_BITS_MASK(sb, 0)); for (sw++; sw < ew; sw++) num += count_bits(~bits[sw]); return num + (count_bits(~bits[ew] & SCM_BITS_MASK(0, eb))); }
int main() { std::cout << count_bits(8) << std::endl; std::cout << count_bits(15) << std::endl; std::cout << count_bits(10) << std::endl; std::cout << count_bits(100) << std::endl; std::cout << count_bits(127) << std::endl; std::cout << std::bitset<4 * 8>(182927) << std::endl; std::cout << std::bitset<4 * 8>(reverse(182927)) << std::endl; int a = 23; int b = 22; std::cout << a << " + " << b << ": " << add(a, b) << std::endl; }
bool OMXPlayerVideo::Decode(OMXPacket *pkt) { if(!pkt) return false; // some packed bitstream AVI files set almost all pts values to DVD_NOPTS_VALUE, but have a scattering of real pts values. // the valid pts values match the dts values. // if a stream has had more than 4 valid pts values in the last 16, the use UNKNOWN, otherwise use dts m_history_valid_pts = (m_history_valid_pts << 1) | (pkt->pts != DVD_NOPTS_VALUE); double pts = pkt->pts; if(pkt->pts == DVD_NOPTS_VALUE && (m_iCurrentPts == DVD_NOPTS_VALUE || count_bits(m_history_valid_pts & 0xffff) < 4)) pts = pkt->dts; if (pts != DVD_NOPTS_VALUE) pts += m_iVideoDelay; if(pts != DVD_NOPTS_VALUE) m_iCurrentPts = pts; while((int) m_decoder->GetFreeSpace() < pkt->size) { OMXClock::OMXSleep(10); if(m_flush_requested) return true; } CLog::Log(LOGINFO, "CDVDPlayerVideo::Decode dts:%.0f pts:%.0f cur:%.0f, size:%d", pkt->dts, pkt->pts, m_iCurrentPts, pkt->size); m_decoder->Decode(pkt->data, pkt->size, pts); return true; }
void COMXAudioCodecOMX::BuildChannelMap() { uint64_t layout; int bits = count_bits(m_pCodecContext->channel_layout); if (bits == m_pCodecContext->channels) layout = m_pCodecContext->channel_layout; else { CLog::Log(LOGINFO, "COMXAudioCodecOMX::GetChannelMap - FFmpeg reported %d channels, but the layout contains %d ignoring", m_pCodecContext->channels, bits); layout = av_get_default_channel_layout(m_pCodecContext->channels); } m_channelLayout.Reset(); if (layout & AV_CH_FRONT_LEFT ) m_channelLayout += AE_CH_FL ; if (layout & AV_CH_FRONT_RIGHT ) m_channelLayout += AE_CH_FR ; if (layout & AV_CH_FRONT_CENTER ) m_channelLayout += AE_CH_FC ; if (layout & AV_CH_LOW_FREQUENCY ) m_channelLayout += AE_CH_LFE ; if (layout & AV_CH_BACK_LEFT ) m_channelLayout += AE_CH_BL ; if (layout & AV_CH_BACK_RIGHT ) m_channelLayout += AE_CH_BR ; if (layout & AV_CH_FRONT_LEFT_OF_CENTER ) m_channelLayout += AE_CH_FLOC; if (layout & AV_CH_FRONT_RIGHT_OF_CENTER) m_channelLayout += AE_CH_FROC; if (layout & AV_CH_BACK_CENTER ) m_channelLayout += AE_CH_BC ; if (layout & AV_CH_SIDE_LEFT ) m_channelLayout += AE_CH_SL ; if (layout & AV_CH_SIDE_RIGHT ) m_channelLayout += AE_CH_SR ; if (layout & AV_CH_TOP_CENTER ) m_channelLayout += AE_CH_TC ; if (layout & AV_CH_TOP_FRONT_LEFT ) m_channelLayout += AE_CH_TFL ; if (layout & AV_CH_TOP_FRONT_CENTER ) m_channelLayout += AE_CH_TFC ; if (layout & AV_CH_TOP_FRONT_RIGHT ) m_channelLayout += AE_CH_TFR ; if (layout & AV_CH_TOP_BACK_LEFT ) m_channelLayout += AE_CH_BL ; if (layout & AV_CH_TOP_BACK_CENTER ) m_channelLayout += AE_CH_BC ; if (layout & AV_CH_TOP_BACK_RIGHT ) m_channelLayout += AE_CH_BR ; }
/* *************************************************************************** * Determine if a stat header line has to be displayed. * * RETURNS: * TRUE if a header line has to be displayed. *************************************************************************** */ int check_line_hdr(void) { int i, rc = FALSE; /* Get number of options entered on the command line */ if (get_activity_nr(act, AO_SELECTED, COUNT_OUTPUTS) > 1) return TRUE; for (i = 0; i < NR_ACT; i++) { if (IS_SELECTED(act[i]->options)) { /* Special processing for activities using a bitmap */ if (act[i]->bitmap) { if (count_bits(act[i]->bitmap->b_array, BITMAP_SIZE(act[i]->bitmap->b_size)) > 1) { rc = TRUE; } } else if (act[i]->nr > 1) { rc = TRUE; } /* Stop now since we have only one selected activity */ break; } } return rc; }
void main() { /* Write a case statement to select which hack it is * */ count_bits(); return; }
unsigned int get_random_number_from_candidate_list_and_remove_it(CandidateListType *list, unsigned int index) { unsigned int randomIndex; // index of the selected candidate in the list unsigned int count; // number of remaining candidates in the list unsigned int candidate; // selected candidate assert(NULL != list && index < (NROWS*NCOLS) && "get_random_number_from_candidate_list_and_remove_it(): Bad input"); // 1. count how many remaining numbers we have (how many set bits) count = count_bits(list[index]); assert(count > 0 && "get_random_number_from_candidate_list_and_remove_it(): No candidate remaining"); // 2. generate random index (will be 0 when count is 1) randomIndex = (unsigned int) arc4random() % count; // 3. get the corresponding candidate for (candidate = 0; candidate < NCOLS; ++candidate) { if (BIT_CHECK(list[index],candidate)) { if (0 == randomIndex) { break; } else { --randomIndex; } } } assert(0 <= candidate && candidate < NCOLS && 0 == randomIndex && "get_random_number_from_candidate_list_and_remove_it(): Bad index"); // 4. remove it from the candidate list BIT_CLEAR(list[index],candidate); return (unsigned int)(candidate+1); // Indices start at 0 but values start at 1, need to increase }
//done void scan_operands (operands_t operands) { printf("scan_operands() for %s\n", lc3_get_format_name(operands)); int operandCount = 0; int numOperands = count_bits(operands); int errorCount = numErrors; for (operand_t op = FMT_R1; op <= FMT_STR; op <<= 1) { //if the bits are set //printf(" "); if(op & operands){ //create a token char* token = next_token(); //get the operand of that token if(token != NULL){ get_operand(op,token); //if errorocunt is not equal return if (errorCount != numErrors) return; // error, so skip processing remainder of line //inc operand count operandCount++; //if the count is less then the operands if(operandCount < numOperands){ //get comma or error get_comma_or_error(); } //check errorcount again if (errorCount != numErrors) return; // error, so skip processing remainder of line } } } }
static int VBR_quantize_granule(lame_internal_flags * gfc, gr_info * cod_info, FLOAT8 * xr34, int gr, int ch) { int status; /* encode scalefacs */ if (gfc->is_mpeg1) status = scale_bitcount(&cod_info->scalefac, cod_info); else status = scale_bitcount_lsf(gfc, &cod_info->scalefac, cod_info); if (status != 0) { return -1; } /* quantize xr34 */ cod_info->part2_3_length = count_bits(gfc, cod_info->l3_enc, xr34, cod_info); if (cod_info->part2_3_length >= LARGE_BITS) return -2; cod_info->part2_3_length += cod_info->part2_length; if (gfc->use_best_huffman == 1) { best_huffman_divide(gfc, cod_info); } return 0; }
/* get size as unsigned char string */ static unsigned long unsigned_size(void *a) { unsigned long t; LTC_ARGCHK(a != NULL); t = count_bits(a); if (mpa_cmp_short((const mpanum)a, 0) == 0) return 0; return (t>>3) + ((t&7)?1:0); }
void create_food(ULONG f) { ULONG i; SLONG temp_segment; UWORD orig_x, x, y; UWORD form; if (f < MAX_FOODS) { form = 0; while (!form) form = (UWORD) ((rand()&rand())&0xffff); foods[f].Form = form; foods[f].Size = count_bits(form); foods[f].Effect = choose_effect(); foods[f].Colour = food_colours[foods[f].Effect]; foods[f].Timer = 2000; temp_segment = get_a_segment(); if (temp_segment == -1) return; if (assign_a_food_position(temp_segment,form)) { put_a_segment(temp_segment); return; } orig_x = x = segs[temp_segment].X; y = segs[temp_segment].Y; put_a_segment(temp_segment); for (i=0; i<16; i++) { if (form & 1) { temp_segment = get_a_segment(); if (temp_segment != -1) { foods[f].Size++; segs[temp_segment].Next = foods[f].Head; segs[temp_segment].Colour = foods[f].Colour; segs[temp_segment].X = x; segs[temp_segment].Y = y; foods[f].Head = temp_segment; } else return; } x += BLOB_SIZE; if (x - orig_x == BLOB_SIZE*4) { x = orig_x; y += BLOB_SIZE; } form >>= 1; } }
/** * Number of bits in the set (as opposed to the total size of the set) */ int bitset_count(bitset *b) { unsigned int i; int count = 0; for (i = 0; i < b->bs_size; i++) count += count_bits(b->bs_bits[i]); return count; }
int VBR_noise_shaping(lame_internal_flags * gfc, const FLOAT8 * xr34orig, int minbits, int maxbits, const III_psy_xmin * l3_xmin, int gr, int ch) { FLOAT8 xr34[576]; int ret, bits, huffbits; gr_info *cod_info = &gfc->l3_side.tt[gr][ch]; switch (cod_info->block_type) { default: ret = long_block_shaping(gfc, xr34orig, xr34, minbits, maxbits, l3_xmin, gr, ch); break; case SHORT_TYPE: ret = short_block_shaping(gfc, xr34orig, xr34, minbits, maxbits, l3_xmin, gr, ch); break; } if (ret == -1) /* Houston, we have a problem */ return -1; if (cod_info->part2_3_length < minbits) { huffbits = minbits - cod_info->part2_length; bits = bin_search_StepSize(gfc, cod_info, huffbits, gfc->OldValue[ch], xr34); gfc->OldValue[ch] = cod_info->global_gain; cod_info->part2_3_length = bits + cod_info->part2_length; if (gfc->use_best_huffman == 1) { best_huffman_divide(gfc, cod_info); } } if (cod_info->part2_3_length > maxbits) { huffbits = maxbits - cod_info->part2_length; if (huffbits < 0) huffbits = 0; bits = bin_search_StepSize(gfc, cod_info, huffbits, gfc->OldValue[ch], xr34); gfc->OldValue[ch] = cod_info->global_gain; while (bits > huffbits) { ++cod_info->global_gain; bits = count_bits(gfc, cod_info->l3_enc, xr34, cod_info); } cod_info->part2_3_length = bits; if (bits >= LARGE_BITS) /* Houston, we have a problem */ return -2; cod_info->part2_3_length += cod_info->part2_length; if (gfc->use_best_huffman == 1) { best_huffman_divide(gfc, cod_info); } } if (cod_info->part2_length >= LARGE_BITS) /* Houston, we have a problem */ return -2; assert(cod_info->global_gain < 256); return 0; }
static int bin_search_StepSize(lame_internal_flags * const gfc, gr_info * const cod_info, const int desired_rate, const int start, const FLOAT8 xrpow[576]) { int nBits; int CurrentStep; int flag_GoneOver = 0; int StepSize = start; binsearchDirection_t Direction = BINSEARCH_NONE; assert(gfc->CurrentStep); CurrentStep = gfc->CurrentStep; do { cod_info->global_gain = StepSize; nBits = count_bits(gfc, cod_info->l3_enc, xrpow, cod_info); if (CurrentStep == 1) break; /* nothing to adjust anymore */ if (flag_GoneOver) CurrentStep /= 2; if (nBits > desired_rate) { /* increase Quantize_StepSize */ if (Direction == BINSEARCH_DOWN && !flag_GoneOver) { flag_GoneOver = 1; CurrentStep /= 2; /* late adjust */ } Direction = BINSEARCH_UP; StepSize += CurrentStep; if (StepSize > 255) break; } else if (nBits < desired_rate) { /* decrease Quantize_StepSize */ if (Direction == BINSEARCH_UP && !flag_GoneOver) { flag_GoneOver = 1; CurrentStep /= 2; /* late adjust */ } Direction = BINSEARCH_DOWN; StepSize -= CurrentStep; if (StepSize < 0) break; } else break; /* nBits == desired_rate;; most unlikely to happen. */ } while (1); /* For-ever, break is adjusted. */ CurrentStep = start - StepSize; gfc->CurrentStep = CurrentStep / 4 != 0 ? 4 : 2; return nBits; }
constexpr inline size_t count_bits( T val, size_t count= 0 ) noexcept { return ( val == T(0) ) ? count : count_bits( T(val & T( val - T(1) )), // clears lowest set bit count + 1 ); }
static size_t count_bits (uint64_t bitmap) { size_t c; if (bitmap == 0) return 0; c = bitmap & 1 ? 1 : 0; bitmap >>= 1; return c + count_bits (bitmap); }
int Evaluator::evaluate(const Board& b, bool max_player, bool no_children) { MoveGenerator mgen; bool playing_white = b.is_whites_turn() == max_player; if (no_children) { if (playing_white && b.is_black_in_check()) { return INT_MAX; } else if (!playing_white && b.is_white_in_check()) { return INT_MAX; } else { return -INT_MAX; } } int material_score = + PAWN_VALUE * (count_pieces(b, WHITE_PAWNS) - count_pieces(b, BLACK_PAWNS)) + KNIGHT_VALUE * (count_pieces(b, WHITE_KNIGHTS) - count_pieces(b, BLACK_KNIGHTS)) + BISHOP_VALUE * (count_pieces(b, WHITE_BISHOPS) - count_pieces(b, BLACK_BISHOPS)) + ROOK_VALUE * (count_pieces(b, WHITE_ROOKS) - count_pieces(b, BLACK_ROOKS)) + QUEEN_VALUE * (count_pieces(b, WHITE_QUEEN) - count_pieces(b, BLACK_QUEEN)) + KING_VALUE * (count_pieces(b, WHITE_KING) - count_pieces(b, BLACK_KING)); // TODO: This one isn't good. Can we store the value on board? // Currently it only counts squares that can be moved to, not actual moves. // Generating moves here takes far to long to do, esp. generating moves // for both players. int mobility_score = MOBILITY_VALUE * ( count_bits(b.get_white_control() ^ b.get_pieces_for(ALL_WHITE_PIECES)) - count_bits(b.get_black_control() ^ b.get_pieces_for(ALL_BLACK_PIECES)) ); int total_score = material_score + mobility_score; if(playing_white) { return total_score; } else { return total_score * -1; } }
uint64_t COMXAudioCodecOMX::GetChannelMap() { uint64_t layout; int bits = count_bits(m_pCodecContext->channel_layout); if (bits == m_pCodecContext->channels) layout = m_pCodecContext->channel_layout; else { CLog::Log(LOGINFO, "COMXAudioCodecOMX::GetChannelMap - FFmpeg reported %d channels, but the layout contains %d ignoring", m_pCodecContext->channels, bits); layout = av_get_default_channel_layout(m_pCodecContext->channels); } return layout; }
void subrange(unsigned char *sin, unsigned char *ein) // recursive function to divide ip range { unsigned char nets[4], nete[4]; int bitlen, nextlen; bitlen = count_bits(sin, ein); if (bitlen == 32) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/32 ", sin[0], sin[1], sin[2], sin[3]); cprintf("%u.%u.%u.%u/32\n", sin[0], sin[1], sin[2], sin[3]); return; } else if (bitlen == 31) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/31 ", sin[0], sin[1], sin[2], sin[3]); cprintf("%u.%u.%u.%u/31\n", sin[0], sin[1], sin[2], sin[3]); return; } nextlen = bitlen + 1; getse(sin, nets, nete, bitlen); if (sameaddr(sin, nets) && sameaddr(ein, nete)) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/%d ", nets[0], nets[1], nets[2], nets[3], bitlen); cprintf("%u.%u.%u.%u/%d\n", nets[0], nets[1], nets[2], nets[3], bitlen); return; } getse(sin, nets, nete, nextlen); if (sameaddr(sin, nete)) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/32 ", sin[0], sin[1], sin[2], sin[3]); cprintf("%u.%u.%u.%u/32\n", sin[0], sin[1], sin[2], sin[3]); } else if (sameaddr(sin, nets)) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/%d ", nets[0], nets[1], nets[2], nets[3], nextlen); cprintf("%u.%u.%u.%u/%d\n", nets[0], nets[1], nets[2], nets[3], nextlen); } else // continue check subrange(sin, nete); getse(ein, nets, nete, nextlen); if (sameaddr(ein, nets)) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/32 ", ein[0], ein[1], ein[2], ein[3]); cprintf("%u.%u.%u.%u/32\n", ein[0], ein[1], ein[2], ein[3]); } else if (sameaddr(ein, nete)) { sprintf(range_buf + strlen(range_buf), "%u.%u.%u.%u/%d ", nets[0], nets[1], nets[2], nets[3], nextlen); cprintf("%u.%u.%u.%u/%d\n", nets[0], nets[1], nets[2], nets[3], nextlen); } else // continue check subrange(nets, ein); }
static int setget_prop(int types, const char *object, const char *name, const char *value) { int ret; const struct prop_handler *prop = NULL; ret = parse_prop(name, prop_handlers, &prop); if (ret == -1) { fprintf(stderr, "ERROR: property is unknown\n"); ret = 40; goto out; } else if (ret) { fprintf(stderr, "ERROR: parse_prop reported unknown error\n"); ret = 42; goto out; } types &= prop->types; if (!types) { fprintf(stderr, "ERROR: object is not compatible with property\n"); ret = 47; goto out; } if (count_bits(types) > 1) { fprintf(stderr, "ERROR: type of object is ambiguous. Please specify a type by hand.\n"); ret = 48; goto out; } if (value && prop->read_only) { fprintf(stderr, "ERROR: %s is a read-only property.\n", prop->name); ret = 51; goto out; } ret = prop->handler(types, object, name, value); if (ret < 0) ret = 50; else ret = 0; out: return ret; }
/* setup */ static int montgomery_setup(void *a, void **b) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(b != NULL); mpa_word_t len = mpa_fmm_context_size_in_U32(count_bits(a)); *b = malloc(len * sizeof(mpa_word_t)); if (*b == NULL) { return CRYPT_MEM; } mpa_fmm_context_base * b_tmp = (mpa_fmm_context_base *) *b; mpa_init_static_fmm_context(b_tmp, len); mpa_compute_fmm_context((const mpanum) a, b_tmp->r_ptr, b_tmp->r2_ptr, &(b_tmp->n_inv), external_mem_pool); return CRYPT_OK; }
uint8_t LoRaPHY::num_active_channels(uint16_t *channel_mask, uint8_t start_idx, uint8_t stop_idx) { uint8_t nb_channels = 0; if (channel_mask == NULL) { return 0; } for (uint8_t i = start_idx; i < stop_idx; i++) { nb_channels += count_bits(channel_mask[i], 16); } return nb_channels; }
uint64_t COMXAudioCodecOMX::GetChannelMap() { uint64_t layout; int bits = count_bits(m_pCodecContext->channel_layout); if (bits == m_pCodecContext->channels) layout = m_pCodecContext->channel_layout; else { LOG_TRACE_2 << "COMXAudioCodecOMX::GetChannelMap - FFmpeg reported" << m_pCodecContext->channels << " channels, but the layout contains " << bits << "ignoring"; layout = av_get_default_channel_layout(m_pCodecContext->channels); } return layout; }
static int eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) { xXIRawEvent* raw; int vallen, nvals; int i, len = sizeof(xXIRawEvent); char *ptr; FP3232 *axisval, *axisval_raw; nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)); len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once raw, once processed */ vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); len += vallen * 4; /* valuators mask */ *xi = calloc(1, len); raw = (xXIRawEvent*)*xi; raw->type = GenericEvent; raw->extension = IReqCode; raw->evtype = GetXI2Type(ev->type); raw->time = ev->time; raw->length = bytes_to_int32(len - sizeof(xEvent)); raw->detail = ev->detail.button; raw->deviceid = ev->deviceid; raw->sourceid = ev->sourceid; raw->valuators_len = vallen; raw->flags = ev->flags; ptr = (char*)&raw[1]; axisval = (FP3232*)(ptr + raw->valuators_len * 4); axisval_raw = axisval + nvals; for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++) { if (BitIsOn(ev->valuators.mask, i)) { SetBit(ptr, i); *axisval = double_to_fp3232(ev->valuators.data[i]); *axisval_raw = double_to_fp3232(ev->valuators.data_raw[i]); axisval++; axisval_raw++; } } return Success; }
/* Perform first time initialization of the given register class. */ static void initialize(struct v_reg_class *r, uint32 mask) { int i, reg; r->members = r->perm_members = mask; r->n = count_bits(r->members); /* setup the register vector. */ for(reg = i = 0; i < MAX_REGS; i++) if(SET_P(r->members, i)) r->initial[reg++] = i; demand(reg == r->n, disagreement); r->initial[r->n] = V_REG_SENTINAL; r->rp = &r->available[0]; r->iter_state = ITER_INITIAL; }