Beispiel #1
0
bool tiling(ll n, ll m){
  int vn = __builtin_ctzll(n);
  int vm = __builtin_ctzll(m);
  if (vm == 1) return false;
  if (vn + vm <= 2) return false;
  if (vn >= 1 && vm >=2) return true;
  if (vn==0) return cancycle(n,vm);
  if (vm==0) return cancycle(m,vn);
  abort();
}
static int
rte_port_sink_tx_bulk(void *port, struct rte_mbuf **pkts,
	uint64_t pkts_mask)
{
	struct rte_port_sink *p = port;

	if ((pkts_mask & (pkts_mask + 1)) == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t i;

		RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, n_pkts);
		RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, n_pkts);

		if (p->dumper) {
			for (i = 0; i < n_pkts; i++)
				PCAP_SINK_WRITE_PKT(p, pkts[i]);
		}

		for (i = 0; i < n_pkts; i++) {
			struct rte_mbuf *pkt = pkts[i];

			rte_pktmbuf_free(pkt);
		}

	} else {
		if (p->dumper) {
			uint64_t dump_pkts_mask = pkts_mask;
			uint32_t pkt_index;

			for ( ; dump_pkts_mask; ) {
				pkt_index = __builtin_ctzll(
					dump_pkts_mask);
				PCAP_SINK_WRITE_PKT(p, pkts[pkt_index]);
				dump_pkts_mask &= ~(1LLU << pkt_index);
			}
		}

		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1);
			RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1);
			rte_pktmbuf_free(pkt);
			pkts_mask &= ~pkt_mask;
		}
	}

	return 0;
}
static int
rte_port_sink_tx_bulk(__rte_unused void *port, struct rte_mbuf **pkts,
	uint64_t pkts_mask)
{
	if ((pkts_mask & (pkts_mask + 1)) == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t i;

		for (i = 0; i < n_pkts; i++) {
			struct rte_mbuf *pkt = pkts[i];

			rte_pktmbuf_free(pkt);
		}
	} else {
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			rte_pktmbuf_free(pkt);
			pkts_mask &= ~pkt_mask;
		}
	}

	return 0;
}
Beispiel #4
0
rte_port_ring_writer_tx_bulk_internal(void *port,
		struct rte_mbuf **pkts,
		uint64_t pkts_mask,
		uint32_t is_multi)
{
	struct rte_port_ring_writer *p =
		(struct rte_port_ring_writer *) port;

	uint64_t bsz_mask = p->bsz_mask;
	uint32_t tx_buf_count = p->tx_buf_count;
	uint64_t expr = (pkts_mask & (pkts_mask + 1)) |
			((pkts_mask & bsz_mask) ^ bsz_mask);

	if (expr == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t n_pkts_ok;

		if (tx_buf_count) {
			if (is_multi)
				send_burst_mp(p);
			else
				send_burst(p);
		}

		RTE_PORT_RING_WRITER_STATS_PKTS_IN_ADD(p, n_pkts);
		if (is_multi)
			n_pkts_ok = rte_ring_mp_enqueue_burst(p->ring, (void **)pkts,
				n_pkts);
		else
			n_pkts_ok = rte_ring_sp_enqueue_burst(p->ring, (void **)pkts,
				n_pkts);

		RTE_PORT_RING_WRITER_STATS_PKTS_DROP_ADD(p, n_pkts - n_pkts_ok);
		for ( ; n_pkts_ok < n_pkts; n_pkts_ok++) {
			struct rte_mbuf *pkt = pkts[n_pkts_ok];

			rte_pktmbuf_free(pkt);
		}
	} else {
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			p->tx_buf[tx_buf_count++] = pkt;
			RTE_PORT_RING_WRITER_STATS_PKTS_IN_ADD(p, 1);
			pkts_mask &= ~pkt_mask;
		}

		p->tx_buf_count = tx_buf_count;
		if (tx_buf_count >= p->tx_burst_sz) {
			if (is_multi)
				send_burst_mp(p);
			else
				send_burst(p);
		}
	}

	return 0;
}
Beispiel #5
0
void test_i64(float P) {
  leading = __builtin_clzll(P);
  trailing = __builtin_ctzll(P);
// CHECK: @test_i64
// CHECK: call i64 @llvm.ctlz.i64(i64 {{.*}}, i1 false)
// CHECK: call i64 @llvm.cttz.i64(i64 {{.*}}, i1 false)
}
static int
rte_port_ethdev_writer_tx_bulk(void *port,
		struct rte_mbuf **pkts,
		uint64_t pkts_mask)
{
	struct rte_port_ethdev_writer *p =
		(struct rte_port_ethdev_writer *) port;

	if ((pkts_mask & (pkts_mask + 1)) == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t i;

		for (i = 0; i < n_pkts; i++) {
			struct rte_mbuf *pkt = pkts[i];

			p->tx_buf[p->tx_buf_count++] = pkt;
			if (p->tx_buf_count >= p->tx_burst_sz)
				send_burst(p);
		}
	} else {
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			p->tx_buf[p->tx_buf_count++] = pkt;
			if (p->tx_buf_count >= p->tx_burst_sz)
				send_burst(p);
			pkts_mask &= ~pkt_mask;
		}
	}

	return 0;
}
Beispiel #7
0
int square_attacked(s_board *board, uint64_t pos, int side)
{
  assert(board != NULL);
  assert(pos);
  assert(side == WHITE || side == BLACK);
  
  int sq = __builtin_ctzll(pos);
  
  // Pawns
  if(magic_moves_pawns(1-side, sq) & board->pieces[PAWNS] & board->colour[side]) {return 1;}
  
  // Knights
  if((board->colour[side] & board->pieces[KNIGHTS]) & magic_moves_knight(sq)) {return 1;}
  
  // Bishops & Queens
  if(magic_moves_bishop((board->colour[WHITE]|board->colour[BLACK]), sq) & (board->colour[side] & (board->pieces[BISHOPS] | board->pieces[QUEENS]))) {return 1;}
  
  // Rooks & Queens
  if(magic_moves_rook((board->colour[WHITE]|board->colour[BLACK]), sq) & (board->colour[side] & (board->pieces[ROOKS] | board->pieces[QUEENS]))) {return 1;}
  
  // King
  if(magic_moves_king(sq) & board->pieces[KINGS] & board->colour[side]) {return 1;}
  
  return 0;
}
Beispiel #8
0
unsigned long long gcd(unsigned long long u, unsigned long long v){
    if (!u) return v;
    if (!v) return u;
    if (u == 1 || v == 1) return 1;

    int shift = __builtin_ctzll(u | v);
    u >>= __builtin_ctzll(u);
    do{
        v >>= __builtin_ctzll(v);
        if (u > v)
            v ^= u ^= v ^= u;
        v = v - u;
    } while (v);

    return u << shift;
}
Beispiel #9
0
static int
app_install_coremask(uint64_t core_mask)
{
	uint32_t n_cores, i;

	for (n_cores = 0, i = 0; i < RTE_MAX_LCORE; i++)
		if (app.cores[i].core_type != APP_CORE_NONE)
			n_cores++;

	if (n_cores != app.n_cores) {
		rte_panic("Number of cores in COREMASK should be %u instead "
			"of %u\n", n_cores, app.n_cores);
		return -1;
	}

	for (i = 0; i < RTE_MAX_LCORE; i++) {
		uint32_t core_id;

		if (app.cores[i].core_type == APP_CORE_NONE)
			continue;

		core_id = __builtin_ctzll(core_mask);
		core_mask &= ~(1LLU << core_id);

		app.cores[i].core_id = core_id;
	}

	return 0;
}
Beispiel #10
0
static int
rte_port_fd_writer_nodrop_tx_bulk(void *port,
	struct rte_mbuf **pkts,
	uint64_t pkts_mask)
{
	struct rte_port_fd_writer_nodrop *p =
		port;
	uint32_t tx_buf_count = p->tx_buf_count;

	if ((pkts_mask & (pkts_mask + 1)) == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t i;

		for (i = 0; i < n_pkts; i++)
			p->tx_buf[tx_buf_count++] = pkts[i];
		RTE_PORT_FD_WRITER_NODROP_STATS_PKTS_IN_ADD(p, n_pkts);
	} else
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			p->tx_buf[tx_buf_count++] = pkt;
			RTE_PORT_FD_WRITER_NODROP_STATS_PKTS_IN_ADD(p, 1);
			pkts_mask &= ~pkt_mask;
		}

	p->tx_buf_count = tx_buf_count;
	if (tx_buf_count >= p->tx_burst_sz)
		send_burst_nodrop(p);

	return 0;
}
Beispiel #11
0
uint64_t calculate_attacking(s_board *board, uint64_t pos, int side)
{
  assert(board != NULL);
  assert(pos);
  assert(side == WHITE || side == BLACK);
  
  int sq = __builtin_ctzll(pos);
  uint64_t attackers = 0;
  
  // Pawns
  attackers |= board->colour[side] & board->pieces[PAWNS] & magic_moves_pawns(1-side, sq);
  
  // Knights
  attackers |= board->colour[side] & board->pieces[KNIGHTS] & magic_moves_knight(sq);
  
  // Bishops & Queens
  attackers |= magic_moves_bishop((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & (board->pieces[BISHOPS] | board->pieces[QUEENS]);
  
  // Rooks & Queens
  attackers |= magic_moves_rook((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & (board->pieces[ROOKS] | board->pieces[QUEENS]);
  
  // King
  attackers |= magic_moves_king(sq) & board->pieces[KINGS] & board->colour[side];
  
  return attackers;
}
Beispiel #12
0
StgWord
hs_ctz64(StgWord64 x)
{
#if defined(__GNUC__) && (defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH))
  /* On Linux/i386, the 64bit `__builtin_ctzll()` instrinsic doesn't
     get inlined by GCC but rather a short `__ctzdi2` runtime function
     is inserted when needed into compiled object files.

     This workaround forces GCC on 32bit x86 to express `hs_ctz64` in
     terms of the 32bit `__builtin_ctz()` (this is no loss, as there's no
     64bit BSF instruction on i686 anyway) and thus avoid the problematic
     out-of-line runtime function.
  */

  if (!x) return 64;

  return ((uint32_t)x ? __builtin_ctz((uint32_t)x)
                      : (__builtin_ctz(x >> 32) + 32));

#elif SIZEOF_UNSIGNED_LONG == 8
  return x ? __builtin_ctzl(x) : 64;
#elif SIZEOF_UNSIGNED_LONG_LONG == 8
  return x ? __builtin_ctzll(x) : 64;
#else
# error no suitable __builtin_ctz() found
#endif
}
int main(int argc, char ** argv) {
  const int N = 1024 * 32;
  int alignoffset = 0;
  if(argc>1)  {
    alignoffset = atoi(argv[1]);
    printf("alignment offset = %d \n", alignoffset);
  }
  char *origbuffer = malloc(N + alignoffset);
  char *origtmpbuffer = malloc(N + alignoffset);
  char *buffer = origbuffer + alignoffset;
  char *tmpbuffer = origtmpbuffer + alignoffset;
  printf("pointer alignment = %d bytes \n", 1<< __builtin_ctzll((uintptr_t)(const void *)(buffer)));

  int repeat = 100;
  size_t howmanywhite = fillwithtext(buffer, N);

  BEST_TIME_NOCHECK_NOPRE(memcpy(tmpbuffer,buffer,N),
                   repeat, N);
  printf("\n");
  BEST_TIME(despace(buffer, N), N - howmanywhite,
                  howmanywhite = fillwithtext(buffer, N), repeat, N);
  BEST_TIME(neon_despace(buffer, N), N - howmanywhite,
                  howmanywhite = fillwithtext(buffer, N), repeat, N);
  BEST_TIME(neon_despace_branchless(buffer, N), N - howmanywhite,
                  howmanywhite = fillwithtext(buffer, N), repeat, N);
  BEST_TIME(neontbl_despace(buffer, N), N - howmanywhite,
                  howmanywhite = fillwithtext(buffer, N), repeat, N);
  free(origbuffer);
  free(origtmpbuffer);
}
static void pointerCoordsFromNative(JNIEnv* env, const PointerCoords* rawPointerCoords,
        float xOffset, float yOffset, jobject outPointerCoordsObj) {
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.x,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset);
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.y,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset);
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.pressure,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.size,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_SIZE));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMajor,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMinor,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMajor,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMinor,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR));
    env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.orientation,
            rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));

    const uint64_t unpackedAxisBits = 0
            | (1LL << AMOTION_EVENT_AXIS_X)
            | (1LL << AMOTION_EVENT_AXIS_Y)
            | (1LL << AMOTION_EVENT_AXIS_PRESSURE)
            | (1LL << AMOTION_EVENT_AXIS_SIZE)
            | (1LL << AMOTION_EVENT_AXIS_TOUCH_MAJOR)
            | (1LL << AMOTION_EVENT_AXIS_TOUCH_MINOR)
            | (1LL << AMOTION_EVENT_AXIS_TOOL_MAJOR)
            | (1LL << AMOTION_EVENT_AXIS_TOOL_MINOR)
            | (1LL << AMOTION_EVENT_AXIS_ORIENTATION);

    uint64_t outBits = 0;
    uint64_t remainingBits = rawPointerCoords->bits & ~unpackedAxisBits;
    if (remainingBits) {
        uint32_t packedAxesCount = __builtin_popcountll(remainingBits);
        jfloatArray outValuesArray = obtainPackedAxisValuesArray(env, packedAxesCount,
                outPointerCoordsObj);
        if (!outValuesArray) {
            return; // OOM
        }

        jfloat* outValues = static_cast<jfloat*>(env->GetPrimitiveArrayCritical(
                outValuesArray, NULL));

        const float* values = rawPointerCoords->values;
        uint32_t index = 0;
        do {
            uint32_t axis = __builtin_ctzll(remainingBits);
            uint64_t axisBit = 1LL << axis;
            remainingBits &= ~axisBit;
            outBits |= axisBit;
            outValues[index++] = rawPointerCoords->getAxisValue(axis);
        } while (remainingBits);

        env->ReleasePrimitiveArrayCritical(outValuesArray, outValues, 0);
        env->DeleteLocalRef(outValuesArray);
    }
    env->SetLongField(outPointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits, outBits);
}
Beispiel #15
0
// START FUNC DECL
int 
determine_rho_loc (
		   uint64_t hash_val,
		   int m,
		   int *ptr_rho,
		   int *ptr_loc
		   )
// STOP FUNC DECL
//---------------------------------------------------------------------------
/* README: 

determine_rho_loc(hash_val,m,ptr_rho,ptr_loc): This function calculates the rho and loc value for a given hash value and number of bins. rho is the location of the least significant 1 in the binary representation of hash_val. loc is the bin id to which the input element is assigned. 

INPUTS:

hash_val: 64-bit integer produced by some hash function.

m: Number of bins used by the algorithm.

OUTPUTS: 

ptr_rho: Location where the rho value is stored. ex: if hash_val = 0b1001111000100 then rho = 3, if hash_val = 0b010101111 then rho = 1.

ptr_loc: Location where the loc value is stored. If m bins are used, this value is going to be in between 0 and m-1.

 */
//---------------------------------------------------------------------------
{
  
  int status = 0;
 
  if ( hash_val == 0 ) { go_BYE(-1); }

  *ptr_rho = -1; 
  *ptr_loc = -1; 
  
  /* Last (64-20) bits of hash_val's binary representation are used to calculate rho */
     
  int rho = __builtin_ctzll(hash_val)+1;

  /* First 20 bits of hashval's binary representation are used to calculate loc. */

  unsigned int uint_hash_val = (unsigned int) (hash_val >> (64-20));
  int loc = (int) (uint_hash_val & (m-1));

  /* Sanity checking: A rho value of greater than (64 - 20) would imply one of the two things:
(1) The odd chance that hash_val is divisible by 2^44. Just retrying might help unless the cardinality is higher than 1 trillion. 
(2) more hash bits are needed to calculate rho. Use 128 bit hashfunctions (like spooky_hash128) and change this code accordingly in that case (this won't occur unless you are dealing with data sets with greater than 100 billion unique elements, which rarely happens). 

  */

  if ( rho > (64-20) ) { go_BYE(-1); }

  *ptr_rho = rho;
  *ptr_loc = loc;
 
 BYE:
  return (status);
}
Beispiel #16
0
int eval_attackers(s_board *board, uint64_t pos, int side)
{
    assert(board != NULL);
    assert(pos);
    assert(side == WHITE || side == BLACK);

    int eval = 0;

    int sq = __builtin_ctzll(pos);
    uint64_t attackers = 0;

    // Pawns
    attackers = board->colour[side] & board->pieces[PAWNS] & magic_moves_pawns(1-side, sq);

    while(attackers)
    {
        eval += piece_value(PAWNS);
        attackers &= 1-attackers;
    }

    // Knights
    attackers = board->colour[side] & board->pieces[KNIGHTS] & magic_moves_knight(sq);

    while(attackers)
    {
        eval += piece_value(KNIGHTS);
        attackers &= 1-attackers;
    }

    // Bishops
    attackers = magic_moves_bishop((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & board->pieces[BISHOPS];

    while(attackers)
    {
        eval += piece_value(BISHOPS);
        attackers &= 1-attackers;
    }

    // Rooks
    attackers = magic_moves_rook((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & board->pieces[ROOKS];

    while(attackers)
    {
        eval += piece_value(ROOKS);
        attackers &= 1-attackers;
    }

    // Queens
    attackers =  magic_moves_bishop((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & board->pieces[QUEENS];
    attackers |= magic_moves_rook((board->colour[WHITE]|board->colour[BLACK]), sq) & board->colour[WHITE] & board->pieces[QUEENS];

    while(attackers)
    {
        eval += piece_value(QUEENS);
        attackers &= 1-attackers;
    }

    return eval;
}
Beispiel #17
0
inline size_t HailstoneSequenceLengthUnstored(size_t start, size_t maxLength)
{
  size_t val = start;
  size_t length = __builtin_ctzll(val);
  val >>= length;
  
  while (length <= maxLength && val != 1) {
    val = (val << 1) + val + 1;
    ++length;
 
    size_t numTrailingZeros = __builtin_ctzll(val);
    val >>= numTrailingZeros;
    length += numTrailingZeros;
  }

  return length + 1;
}
Beispiel #18
0
void
mpi_mul_u64(const mpi *a, uint64_t b, mpi *p)
{
    if (mpi_is_zero(a) || b == 0) {
        mpi_zero(p);
        return;
    } else if (b == 1) {
        if (a != p)
            mpi_set_mpi(p, a);
        return;
    } else if ((b & (b-1)) == 0) {	/* B is a power of 2 */
        mpi_lshift(a, __builtin_ctzll(b), p);
        return;
    } else if (b == (mp_digit)b) {	/* B fits in an mp_digit */
        if (a == p) {
            mp_digit cy = mp_dmuli(p->digits, p->size, (mp_digit)b);
            if (cy) {
                MPI_MIN_ALLOC(p, p->size + 1);
                p->digits[p->size++] = cy;
            }
        } else {
            MPI_MIN_ALLOC(p, a->size);
            mp_digit cy = mp_dmul(a->digits, a->size, (mp_digit)b, p->digits);
            if (cy) {
                MPI_MIN_ALLOC(p, a->size + 1);
                p->digits[a->size] = cy;
                p->size = a->size + 1;
            } else {
                p->size = a->size;
            }
        }
    } else {
        unsigned bits = CHAR_BIT * sizeof(uint64_t) - __builtin_clzll(b);
        mp_size size = (bits + MP_DIGIT_BITS - 1) / MP_DIGIT_BITS;
        mp_digit *bp = MP_TMP_ALLOC(size);
#if MP_DIGIT_BITS >= 64
        bp[0] = b;
#else
        for (mp_size j=0; j<size; j++) {
            bp[j] = (mp_digit)b;
            b >>= MP_DIGIT_BITS;
        }
#endif
        if (a == p) {
            mp_digit *tmp = MP_TMP_ALLOC(p->size + size);
            mp_mul(p->digits, p->size, bp, size, tmp);
            MPI_MIN_ALLOC(p, p->size + size);
            mp_copy(tmp, p->size + size, p->digits);
            p->size = mp_rsize(p->digits, p->size + size);
            MP_TMP_FREE(tmp);
        } else {
            MPI_MIN_ALLOC(p, a->size + size);
            mp_mul(a->digits, a->size, bp, size, p->digits);
            p->size = mp_rsize(p->digits, a->size + size);
        }
        MP_TMP_FREE(bp);
    }
}
Beispiel #19
0
 SumBits()
 {
   for (int i = 0; i < (1 << 16); i++)
   {
     sum_bits_[i] = 0;
     for (int j = i; j != 0; j &= j - 1)
       sum_bits_[i] += (uint8_t) (__builtin_ctzll(j) * 2);
   }
 }
int rec(const std::vector<uint64> &g, uint64 curr, uint64 pool, uint64 excl) {
  if (pool == 0 && excl == 0) {
    int res = 0, u = __builtin_ctzll(curr);
    while (u < (int)g.size()) {
      res += w[u];
      u += __builtin_ctzll(curr >> (u + 1)) + 1;
    }
    return res;
  }
Beispiel #21
0
void test_i64(float P) {
  leading = __builtin_clzll(P);
  trailing = __builtin_ctzll(P);
  pop = __builtin_popcountll(P);
// CHECK: @test_i64
// CHECK: call i64 @llvm.ctlz.i64
// CHECK: call i64 @llvm.cttz.i64
// CHECK: call i64 @llvm.ctpop.i64
}
Beispiel #22
0
constexpr inline uintptr_t count_trailing_zeros(uintptr_t x)
{
#if defined(HAVE___BUILTIN_CTZLL)
    return __builtin_ctzll(x);
#else
    /// @todo create a fallback.
    static_assert(false, "Generic count_trailing_zeros() not yet implemented.");
#endif
}
Beispiel #23
0
COMPILER_RT_ABI si_int
__ctzti2(ti_int a)
{
    twords x;
    x.all = a;
    const di_int f = -(x.s.low == 0);
    return __builtin_ctzll((x.s.high & f) | (x.s.low & ~f)) +
              ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
}
Beispiel #24
0
static int
rte_port_ethdev_writer_nodrop_tx_bulk(void *port,
		struct rte_mbuf **pkts,
		uint64_t pkts_mask)
{
	struct rte_port_ethdev_writer_nodrop *p =
		(struct rte_port_ethdev_writer_nodrop *) port;

	uint64_t bsz_mask = p->bsz_mask;
	uint32_t tx_buf_count = p->tx_buf_count;
	uint64_t expr = (pkts_mask & (pkts_mask + 1)) |
			((pkts_mask & bsz_mask) ^ bsz_mask);

	if (expr == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t n_pkts_ok;

		if (tx_buf_count)
			send_burst_nodrop(p);

		RTE_PORT_ETHDEV_WRITER_NODROP_STATS_PKTS_IN_ADD(p, n_pkts);
		n_pkts_ok = rte_eth_tx_burst(p->port_id, p->queue_id, pkts,
			n_pkts);

		if (n_pkts_ok >= n_pkts)
			return 0;

		/*
		 * If we didnt manage to send all packets in single burst, move
		 * remaining packets to the buffer and call send burst.
		 */
		for (; n_pkts_ok < n_pkts; n_pkts_ok++) {
			struct rte_mbuf *pkt = pkts[n_pkts_ok];
			p->tx_buf[p->tx_buf_count++] = pkt;
		}
		send_burst_nodrop(p);
	} else {
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			p->tx_buf[tx_buf_count++] = pkt;
			RTE_PORT_ETHDEV_WRITER_NODROP_STATS_PKTS_IN_ADD(p, 1);
			pkts_mask &= ~pkt_mask;
		}

		p->tx_buf_count = tx_buf_count;
		if (tx_buf_count >= p->tx_burst_sz)
			send_burst_nodrop(p);
	}

	return 0;
}
Beispiel #25
0
void check_ctz(int n) {
  // ABORT: builtins.cpp:[[@LINE+2]]:17: runtime error: passing zero to ctz(), which is not a valid argument
  // RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to ctz(), which is not a valid argument
  __builtin_ctz(n);

  // RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to ctz(), which is not a valid argument
  __builtin_ctzl(n);

  // RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to ctz(), which is not a valid argument
  __builtin_ctzll(n);
}
Beispiel #26
0
inline size_t HailstoneSequenceLengthStored(size_t start, size_t maxLength)
{
  size_t val = start;
  size_t length = __builtin_ctzll(val);
  val >>= length;

  while (length <= maxLength && val >= kNumStoredSequences) {
    val = (val << 1) + val + 1;
    ++length;

    size_t numTrailingZeros = __builtin_ctzll(val);
    val >>= numTrailingZeros;
    length += numTrailingZeros;
  }

  if (length <= maxLength)
    length += gSequenceLength[val];

  return length;
}
Beispiel #27
0
template<int MOD> inline long long fib(long long n) { // {0,1,1,2,...}
	if (!fib2[1][0]) generate_fib2<MOD>();
	if (!n--) return 0;
	f0 = 0, f1 = 1;
	while (n) {
		int i = __builtin_ctzll(n);
		faux = (f1*fib2[i][1] + f0*fib2[i][0]) % MOD;
		f1 = (f1*(fib2[i][0]+fib2[i][1]) + f0*fib2[i][1]) % MOD;
		f0 = faux;
		n -= 1ULL<<i;
	}
	return f1;
}
Beispiel #28
0
    __INTRIN_INLINE bool bsf64(unsigned long* const index, const uint64_t mask)
    {
#if defined(__GNUC__) || defined(__clang__)
        if (mask) {
            *index = (unsigned long)__builtin_ctzll(mask);
            return true;
        } else {
            return false;
        }
#elif defined(_MSC_VER)
        return _BitScanForward64(index, mask) != 0;
#else
#     error Unsupported platform
#endif
    }
Beispiel #29
0
constexpr T _tzcnt(T src)
{
    static_assert(binary_digits<T>::value, "");
    constexpr T digits = binary_digits<T>::value;
    T dest = 0;
    if (digits <= std::numeric_limits<unsigned int>::digits) {
        dest = src ? __builtin_ctz(src) : digits; 
    } else if (digits <= std::numeric_limits<unsigned long int>::digits) {
        dest = src ? __builtin_ctzl(src) : digits; 
    } else if (digits <= std::numeric_limits<unsigned long long int>::digits) {
        dest = src ? __builtin_ctzll(src) : digits; 
    } else {
        dest = _tzcnt(src, std::ignore);
    }
    return dest;
}
Beispiel #30
0
static int
rte_port_ethdev_writer_tx_bulk(void *port,
		struct rte_mbuf **pkts,
		uint64_t pkts_mask)
{
	struct rte_port_ethdev_writer *p =
		(struct rte_port_ethdev_writer *) port;
	uint64_t bsz_mask = p->bsz_mask;
	uint32_t tx_buf_count = p->tx_buf_count;
	uint64_t expr = (pkts_mask & (pkts_mask + 1)) |
			((pkts_mask & bsz_mask) ^ bsz_mask);

	if (expr == 0) {
		uint64_t n_pkts = __builtin_popcountll(pkts_mask);
		uint32_t n_pkts_ok;

		if (tx_buf_count)
			send_burst(p);

		RTE_PORT_ETHDEV_WRITER_STATS_PKTS_IN_ADD(p, n_pkts);
		n_pkts_ok = rte_eth_tx_burst(p->port_id, p->queue_id, pkts,
			n_pkts);

		RTE_PORT_ETHDEV_WRITER_STATS_PKTS_DROP_ADD(p, n_pkts - n_pkts_ok);
		for ( ; n_pkts_ok < n_pkts; n_pkts_ok++) {
			struct rte_mbuf *pkt = pkts[n_pkts_ok];

			rte_pktmbuf_free(pkt);
		}
	} else {
		for ( ; pkts_mask; ) {
			uint32_t pkt_index = __builtin_ctzll(pkts_mask);
			uint64_t pkt_mask = 1LLU << pkt_index;
			struct rte_mbuf *pkt = pkts[pkt_index];

			p->tx_buf[tx_buf_count++] = pkt;
			RTE_PORT_ETHDEV_WRITER_STATS_PKTS_IN_ADD(p, 1);
			pkts_mask &= ~pkt_mask;
		}

		p->tx_buf_count = tx_buf_count;
		if (tx_buf_count >= p->tx_burst_sz)
			send_burst(p);
	}

	return 0;
}