示例#1
0
文件: dbask.c 项目: sergiy8/fsha
unsigned dbask(unsigned busy,unsigned w , unsigned d) {
	int rank = _popc(busy);
	if (w==0) return 0;
	if (_popc(w) == rank) return 1;
	if (db[rank]==NULL) error(DB_FORMAT,rank);
	uint64_t offset = (db[rank]->offsets)[(w<<rank)|d];
	if(offset==0)
		error("No file in "DB_FORMAT", should not happen",rank);
	return dbget_raw( (struct fheader*)(((unsigned char*)(db[rank])) + offset), busy);
}
示例#2
0
/**\brief acquire chip_count contiguous chips 
 * by finding adjacent bits in _usable_chips
 */
size_t block_bits::acquire_contiguous(size_t chip_count) {
    (void) chip_count; // make gcc happy...
    
    /* find the rightmost set bit.

       If the map is smaller than the word size, but logically full we
       will compute an index equal to the capacity. If the map is
       physically full (_available == 0) then we'll still compute an
       index equal to capacity because 0-1 will underflow to all set
       bits. Therefore the check for full is the same whether the
       bitmap can use all its bits or not.
     */
    bitmap one_bit = _usable_chips &- _usable_chips;
    size_t index = _popc(one_bit-1);
    if(index < 8*sizeof(bitmap)) {
        // common case: we have space
        assert(index < chip_count);
        _usable_chips ^= one_bit;
    }
    else {
        // oops... full
        assert(index == 8*sizeof(bitmap));
    }

    return index;
}
示例#3
0
文件: debut.c 项目: sergiy8/fsha
int MoveBlack(uint32_t w, uint32_t b, uint32_t d){
	if(_popc(w|b) != 24 ) return -1;
        uint32_t busy,iwhite,idamka;
        Pack(&busy,&iwhite,&idamka,_brev(w),_brev(b),_brev(d));
        db_t x = db_alloc();
        dbase[x].db = busy;
        dbase[x].dw = iwhite;
        dbase[x].dd = idamka;
        if(tsearch(x,rootp+iwhite)!=x)
                db_free();
	    return 0;
}
示例#4
0
文件: ask.c 项目: sergiy8/fsha
int main(int argc, char ** argv){
	uint32_t  x,b,w,d;
	unsigned char * array;
	int rank;
	int idx = 0;
	if(argc!=4) panic();
	b = getarg(1);
	w = getarg(2);
	d = getarg(3);
	rank = _popc(b);
        array = malloc_file(ARRAY_SIZE_S(rank),FMODE_RO,DATA_FORMAT,rank);
// search index
	for(x=ALLONE(rank);x!=b;x=_permut(x))
		idx++;
	if ( blist_get(b) != idx )
		error("What's f***a with blist\n");
//
	int res = twobit_get(array+(uint64_t)((w<<rank)|d)*cnk(32,rank)/4,idx);
	printf("%08X %X %X = %d\n",b,w,d,res);
	return 0;
}