Example #1
0
void vdt_move_to_value( void* dst, const p_dump_src src, const uint32_t n_bits )
{
    char *src_ptr = (char*)src->buf + BYTE_OFFSET(src->offset_in_bits);
    if ( BIT_OFFSET(src->offset_in_bits) == 0 )
    {
        memmove( dst, src_ptr, vdt_bitlength_2_bytes( n_bits ) );
    }
    else
    {
        bitcpy ( dst, 0, src_ptr, BIT_OFFSET(src->offset_in_bits), n_bits );
    }
}
Example #2
0
int SetBit(struct BitMap *psMap, int iIndex)
{
    BITCHK_INDEX(psMap->_iSize, iIndex);

    psMap->_szData[BIT_OFFSET(iIndex)] |= (0x01 << BIT_POS(iIndex));
    
    return 0;
}
Example #3
0
int bit_test(struct bitset *b, int bit)
{
	uint32_t idx;
	uint32_t off;

	idx = BIT_INDEX(bit);
	off = BIT_OFFSET(bit);
	return ((b->bits[idx] & (1 << off)) ? 1 : 0);
}
Example #4
0
 /*************************************************************************************************
 ** Function:				get_next_prime
 ** Description:			Returns the next prime in the bitmap
 *************************************************************************************************/
unsigned int get_next_prime ( unsigned int current_prime , unsigned int upper_bound ) {
	unsigned int i;
	
	for ( i = current_prime + 1 ; i <= sqrt ( upper_bound ) ; i++ ) {
		if ( ( bitmap [ WORD_OFFSET ( i ) ] & ( 1 << BIT_OFFSET ( i ) ) ) != 0 ) {
			return i;
		}
	}
	
	return 0;
}
Example #5
0
static void 
copy_bits(u_int8_t* src,		/* Base pointer to source. */
	  size_t soffs,		/* Bit offset for source relative to src. */
	  int sdir,		/* Direction: 1 (forward) or -1 (backward). */
	  u_int8_t* dst,		/* Base pointer to destination. */
	  size_t doffs,		/* Bit offset for destination relative to dst. */
	  int ddir,		/* Direction: 1 (forward) or -1 (backward). */
	  size_t n)		/* Number of bits to copy. */
{
    u_int32_t lmask;
    u_int32_t rmask;
    u_int32_t count;
    u_int32_t deoffs;

    if (n == 0) {
	return;
    }

    src += sdir*BYTE_OFFSET(soffs);
    dst += ddir*BYTE_OFFSET(doffs);
    soffs = BIT_OFFSET(soffs);
    doffs = BIT_OFFSET(doffs);
    deoffs = BIT_OFFSET(doffs+n);
    lmask = (doffs) ? MAKE_MASK(8-doffs) : 0;
    rmask = (deoffs) ? (MAKE_MASK(deoffs)<<(8-deoffs)) : 0;

    /*
     * Take care of the case that all bits are in the same byte.
     */

    if (doffs+n < 8) {		/* All bits are in the same byte */
	lmask = (lmask & rmask) ? (lmask & rmask) : (lmask | rmask);

	if (soffs == doffs) {
	    *dst = MASK_BITS(*src,*dst,lmask);
	} else if (soffs > doffs) {
	    u_int32_t bits = (*src << (soffs-doffs));
	    if (soffs+n > 8) {
		src += sdir;
		bits |= (*src >> (8-(soffs-doffs)));
	    }
Example #6
0
	void fill() {
		size_t bm_size = WORD_OFFSET(size);
		#pragma omp parallel for
		for (size_t i=0;i<bm_size;i++) {
			data[i] = 0xffffffffffffffff;
		}
		#pragma omp barrier
		data[bm_size] = 0;
		for (size_t i=(bm_size<<6);i<size;i++) {
			data[bm_size] |= 1ul << BIT_OFFSET(i);
		}
	}
Example #7
0
void bit_clear(struct bitset *b, int bit)
{
	uint32_t idx;
	uint32_t off;

	if (!b)
		return;
	idx = BIT_INDEX(bit);
	off = BIT_OFFSET(bit);
	if (idx > b->len)
		return;
	b->bits[idx] &= ~(1 << off);
}
Example #8
0
int payload_add_key(struct payload * po, char * key) {
	if(key == NULL)
		return 1;
	size_t keylen = strlen(key);
	if(po->use_hash) {
		unsigned int hashval = hash_output_key(key, keylen);
		if(!(po->hashed_keys[WORD_OFFSET(hashval)] & (1 << BIT_OFFSET(hashval))))
			return 0;
	}

	adjust_payload_len(po, keylen + sizeof("\"\": "));
	po->bufused += sprintf(po->json_buf + po->bufused,
		"\"%s\": ", key);
	return 1;
}
Example #9
0
void payload_hash_key(struct payload * po, const char * key) {
	size_t keylen = strlen(key);
	unsigned int hashval;

	if(!in_output_word_set(key, keylen))
		return;

	if(!po->use_hash) {
		memset(po->hashed_keys, 0, sizeof(po->hashed_keys));
		po->use_hash = 1;
	}

	hashval = hash_output_key(key, keylen);
	po->hashed_keys[WORD_OFFSET(hashval)] |= (1 << BIT_OFFSET(hashval));
}
Example #10
0
int BitMapExpand(struct BitMap *psMap)
{
    int    iNewSize = psMap->_iSize * 2;
    
    uchar *szData = (uchar*)realloc(psMap->_szData, iNewSize / BIT_BLOCK); 
    FAIL_CHK_EQ(szData, NULL, -1);

    // update bit map
    psMap->_szData = szData;
    memset(psMap->_szData + BIT_OFFSET(psMap->_iSize), 0, 
           psMap->_iSize / BIT_BLOCK);
    psMap->_iSize  = iNewSize;

    return 0;
}
Example #11
0
int payload_has_keys(struct payload * po, ...) {
	va_list ap;
	char * key;
	int okay = 0;

	if(!po->use_hash)
		return 1;

	va_start(ap, po);
	while((key = va_arg(ap, char*)) != NULL) {
		unsigned int keylen = strlen(key);
		unsigned int hashval = hash_output_key(key, keylen);
		if(po->hashed_keys[WORD_OFFSET(hashval)] & (1 << BIT_OFFSET(hashval)))
			okay++;
	}
    va_end(ap);
	return okay;
}
Example #12
0
 /*************************************************************************************************
 ** Function:				preload_bitmap
 ** Description:			Using the Sieve of Eratosthenes to preload the bitmap.  Adapted
 **							from http://martin-thoma.com/generating-many-prime-numbers/
 *************************************************************************************************/
float preload_bitmap ( unsigned int upper_bound ) {
	unsigned int limit = sqrt ( upper_bound );
	unsigned int i;
	unsigned int j;
	time_t preload_start;
	time_t preload_end;
	
	time ( &preload_start );			//begin timing of prime preload
	
	for ( i = 3 ; i <= sqrt ( limit ) ; i++ ) {
		if ( ( bitmap [ WORD_OFFSET ( i ) ] & ( 1 << BIT_OFFSET ( i ) ) ) != 0 ) {
			for ( j = 3 ; ( i * j ) <= limit ; j++ ) {
				mark_non_prime (i * j);
			}
		}
	}
	
	time ( &preload_end );				//end timing of prime preload
	
	return difftime ( preload_end , preload_start );
}
Example #13
0
 /*************************************************************************************************
 ** Function:				get_prime_count
 ** Description:			Counts the primes, times itself, and then prints both of those vals
 **							Also used to print twin primes if q key is not used
 *************************************************************************************************/
float get_prime_count ( unsigned int upper_bound ) {
	unsigned int i;
	unsigned int j;
	unsigned int prev = 0;
	unsigned int curr = -1;
	unsigned int prime_count = 0;
	unsigned int twin_prime_count = 0;
	time_t count_start;
	time_t count_end;

	time ( &count_start );					//begin timing of prime count
	
	for ( i = 0 ; i < ( upper_bound / BITS_PER_WORD + 1 ) ; i++ ) {
		if ( bitmap [ i ] == 0 ) {
			continue;
		}
		
		for ( j = 0 ; j < 8 ; j ++ ) {
			if ( ( bitmap [ WORD_OFFSET ( ( 8 * i ) + j ) ] & ( 1 << BIT_OFFSET ( ( 8 * i ) + j ) ) ) != 0 ) {
				prime_count++;
				
				prev = curr;
				curr = j;
				if ( curr - prev == 2 ) {
					twin_prime_count++;
				}
			}
		}
	}
	
	time ( &count_end );				//end timing of prime count
	
	if ( verb_flag == 1 )
		fprintf ( stderr , "Primes Counted:\n\tNumber of Primes: %u\n\tNumber of Twin Primes: %u\n\tTime: %.2f seconds\n" , prime_count , twin_prime_count , difftime ( count_end , count_start ) );
	
	return difftime ( count_end , count_start );
}
Example #14
0
 /*************************************************************************************************
 ** Function:				print_twin_primes
 ** Description:			...
 *************************************************************************************************/
float print_twin_primes (unsigned int upper_bound ) {
	unsigned int i;
	unsigned int prev = 0;
	unsigned int curr = -1;
	time_t count_start;
	time_t count_end;
	
	time ( &count_start );					//begin timing of prime count

	for (i = 2 ; i <= upper_bound ; i++) {
		if ( ( bitmap [ WORD_OFFSET ( i ) ] & ( 1 << BIT_OFFSET ( i ) ) ) != 0 ) {
			prev = curr;
			curr = i;
			if ( curr - prev == 2 ) {
				fprintf( stdout , "%u %u\n" , prev , curr );
				fflush( stdout );
			}
		}
	}
	
	time ( &count_end );				//end timing of prime count
	
	return difftime ( count_end , count_start );
}
Example #15
0
void set_NotPrime( unsigned int n) {
	primes[WORD_OFFSET(n)] |= (1 << BIT_OFFSET(n));
}
Example #16
0
int check_Prime(unsigned int n) {

	word_t bit = primes[WORD_OFFSET(n)] & (1 << BIT_OFFSET(n));
	return bit == 0;
}
Example #17
0
static uint32_t frame_test(uint32_t addr)
{
    uint32_t frame = addr / PAGE_SIZE;
    return TEST_BIT(frames[BIT_INDEX(frame)], BIT_OFFSET(frame));
}
Example #18
0
static void frame_clear(uint32_t addr)
{
    uint32_t frame = addr / PAGE_SIZE;
    CLEAR_BIT(frames[BIT_INDEX(frame)], BIT_OFFSET(frame));
}
Example #19
0
int GetBit(struct BitMap *psMap, int iIndex)
{
    BITCHK_INDEX(psMap->_iSize, iIndex);

    return (psMap->_szData[BIT_OFFSET(iIndex)] & (0x01 << BIT_POS(iIndex))) != 0;
}
Example #20
0
/**
* Check if frame is allocated or free
* @param paddr - physical address to check
* @return true if set false if not
*/
static bool page_check_frame(uint64 paddr){
    uint64 page = paddr / 4069;
    uint64 idx = BIT_INDEX(page);
    uint64 offset = BIT_OFFSET(page);
    return (_page_frames[idx] & (0x1 << offset));
}
Example #21
0
 /*************************************************************************************************
 ** Function:				mark_prime
 ** Description:			Mark bit 1 ( is prime )
 *************************************************************************************************/
void mark_prime ( unsigned int n ) {
	bitmap [ WORD_OFFSET ( n ) ] |= ( 1 << BIT_OFFSET ( n ) );
}
Example #22
0
 /*************************************************************************************************
 ** Function:				mark_non_prime
 ** Description:			Mark bit 0 ( is not prime )
 *************************************************************************************************/
void mark_non_prime ( unsigned int n ) {
	bitmap [ WORD_OFFSET ( n ) ] &= ~ ( 1 << BIT_OFFSET ( n ) );
}
Example #23
0
void clear_bit(u_int32_t *words, int n) {
    words[WORD_OFFSET(n)] &= ~(1 << BIT_OFFSET(n)); 
}
Example #24
0
int get_bit(u_int32_t *words, int n) {
    u_int32_t bit = words[WORD_OFFSET(n)] & (1 << BIT_OFFSET(n));
    return bit != 0; 
}
Example #25
0
void set_bit(u_int32_t *words, int n) { 
    words[WORD_OFFSET(n)] |= (1 << BIT_OFFSET(n));
}
Example #26
0
void clearBitSign(unsigned int *signStick, int signId)
{
	signStick[WORD_OFFSET(signId)] &= ~(1 << BIT_OFFSET(signId));
}
Example #27
0
int getBitSign(unsigned int *signStick, int signId)
{
	unsigned int bit = signStick[WORD_OFFSET(signId)] & (1 << BIT_OFFSET(signId));
	return bit != 0; 
}
Example #28
0
static void frame_set(uint32_t addr)
{
    uint32_t frame = addr / PAGE_SIZE;
    SET_BIT(frames[BIT_INDEX(frame)], BIT_OFFSET(frame));
}
Example #29
0
/**
* Mark frame allocated
* @param paddr - physical address to mark
*/
static void page_set_frame(uint64 paddr){
    uint64 page = paddr / 4069;
    uint64 idx = BIT_INDEX(page);
    uint64 offset = BIT_OFFSET(page);
	_page_frames[idx] |= (0x1 << offset);
}
Example #30
0
void setBitSign(unsigned int *signStick, int signId)
{
	signStick[WORD_OFFSET(signId)] |= (1 << BIT_OFFSET(signId));
}