int dm_clear(matrix_t *m) { bitvector_clear(&(m->bits)); dm_clear_header(&(m->row_perm)); dm_clear_header(&(m->col_perm)); return 0; }
static uint32_t allocate_block(void) { /* EXERCISE: Your code here */ uint32_t i; for(i = 1; i < ospfs_super->os_nblocks; i++){ if(bitvector_test(ospfs_block(OSPFS_FREEMAP_BLK),i)){ bitvector_clear(ospfs_block(OSPFS_FREEMAP_BLK),i); return i; } } return 0; }
static uint32_t allocate_block(void) { void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK); int i; // iterate through bitmap vector and return first free block for (i = 0; i < ospfs_super->os_nblocks; i++) { if (bitvector_test(bitmap, i)) { bitvector_clear(bitmap, i); // mark as used (set i bit to 0) return i; } } return 0; }
static uint32_t allocate_block(void) { /* DONE: Your code here */ int bits_in_bitmap = ospfs_super->os_nblocks; // also is the number of blocks in our entire FS int x; void* bitvector = ospfs_block(OSPFS_FREEMAP_BLK); for (x = 0; x < bits_in_bitmap; x++) { if (bitvector_test(bitvector, x)) { bitvector_clear(bitvector, x); return x; } } return 0; }
static uint32_t allocate_block(void) { int i; /* EXERCISE: Your code here */ void *free_map = ospfs_block(OSPFS_FREEMAP_BLK); for (i = OSPFS_FREEMAP_BLK; i < ospfs_super->os_nblocks; i++) { if (bitvector_test(free_map, i)) { bitvector_clear(free_map, i); break; } } return (i == ospfs_super->os_nblocks) ? 0 : i; }
static uint32_t allocate_block(void) { /* EXERCISE: Your code here */ void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK); //check for free blocks. 0-2 blocks are always reserved so start at 3. int i; for(i = OSPFS_FREEMAP_BLK+1; i < ospfs_super->os_nblocks; i++){ if(bitvector_test(bitmap, i) == 1){ bitvector_clear(bitmap, i); return i; } } return 0; }
static uint32_t allocate_block(void) { /* EXERCISE: Your code here */ int i; for (i = OSPFS_FREEMAP_BLK; i < ospfs_super->os_firstinob; i++) { char *bitvector = ospfs_block(i); int j = 0; for (j = 0; j < OSPFS_BLKBITSIZE; j++) { if (bitvector_test(bitvector, j)) { bitvector_clear(bitvector, j); return (i - OSPFS_FREEMAP_BLK) * OSPFS_BLKBITSIZE + j; } } } return 0; }
static uint32_t allocate_block(void) { /* EXERCISE: Your code here */ // "First block in free block" is line 61 in ospfs.h as "OSPFS_FREEMAP_BLK 2 void* input_bitmap = ospfs_block(OSPFS_FREEMAP_BLK); //initialize blocknumber, starting at OSPFS_FREEMAP_BLK + 1 (next block after allocation) int blocknumber = OSPFS_FREEMAP_BLK+1; int upperlimit = ospfs_super->os_nblocks; //most blocks we can go //if test(blocknumber) returns 1, then clear the corresponding blocknumber //do this for every blocknumber while (blocknumber < upperlimit) { if (bitvector_test(input_bitmap, blocknumber)) { bitvector_clear(input_bitmap, blocknumber); return blocknumber; } blocknumber++; } return 0; }
int mark_inode_bitmap(ospfs_inode_t *oi, uint8_t *bitmap) { int i, j; uint32_t *ptrl1, *ptrl2; int next_block = ospfs_size2nblocks(oi->oi_size); if (next_block == 0) { return 0; } for (i = 0; (i < OSPFS_NDIRECT) && oi->oi_direct[i]; i++) { bitvector_clear(bitmap, oi->oi_direct[i]); } if (i < OSPFS_NDIRECT || !oi->oi_indirect) { return 0; } next_block -= OSPFS_NDIRECT; bitvector_clear(bitmap, oi->oi_indirect); ptrl1 = ospfs_block(oi->oi_indirect); for (i = 0; i < OSPFS_NINDIRECT && ptrl1[i]; i++) { bitvector_clear(bitmap, ptrl1[i]); } if (i < OSPFS_NINDIRECT || !oi->oi_indirect2) { return 0; } next_block -= OSPFS_NINDIRECT; bitvector_clear(bitmap, oi->oi_indirect2); ptrl1 = ospfs_block(oi->oi_indirect); for (i = 0; i < OSPFS_NINDIRECT && ptrl1[i]; i++) { ptrl2 = ospfs_block(ptrl1[i]); bitvector_clear(bitmap, ptrl1[i]); for (j = 0; j < OSPFS_NINDIRECT && ptrl2[j]; j++) { bitvector_clear(bitmap, ptrl2[j]); } if (j < OSPFS_NINDIRECT) { break; } } return 0; }
static uint32_t allocate_block(void) { void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK); /* EXERCISE: Your code here */ //void *allo_block = NULL; int i = 2; while(i<ospfs_super->os_nblocks) { // bitvector_test -- Return the value of the 'i'th bit of 'vector'. if(bitvector_test(bitmap,i)==1)//the corresponding block is free { // bitvector_clear -- Set 'i'th bit of 'vector' to 0. bitvector_clear(bitmap,i); //allo_block = ospfs_block(i); return i; //break; } i++; } return 0; }
static uint32_t allocate_block(void) { //SQ allocate void* bitmap = &ospfs_data[OSPFS_FREEMAP_BLK]; unsigned size_of_bitmap_bits = (ospfs_super->os_nblocks); //unsigned nblocks_in_bitmap = ospfs_size2nblocks(ospfs_super_t->os_nblocks/8); //offset to ignore superblock and boot sector block //OSPFS_FREEMAP_BLK= 2 where the bitmap begins uint32_t i; for(i = 0; i < size_of_bitmap_bits; i++) { if(bitvector_test(bitmap, i) == 1) { bitvector_clear(bitmap, i); return i; } } //end SQ allocate /* EXERCISE: Your code here */ return 0; }
// gcc -Wall -O3 -DTEST_BIT_VECTOR bitvector.c && ./a.out int main() { const unsigned int nbits=40; bitvector_t b=bitvector_new(nbits); if (sizeof(int)!=4) { fprintf(stderr,"Size problem in bitvector.c"); exit(1); } bitvector_show(b,nbits); printf("\n"); bitvector_set(b,0); bitvector_set(b,1); bitvector_set(b,11); bitvector_set(b,38); bitvector_show(b,nbits); printf("\n"); bitvector_clear(b,38); bitvector_show(b,nbits); printf("\n"); bitvector_flip(b,0); bitvector_show(b,nbits); printf("\n"); bitvector_flip(b,0); bitvector_show(b,nbits); printf("\n"); printf("count_slow=%u\n",bitvector_count_slow(b,nbits)); printf("count=%u\n",bitvector_count(b,nbits)); bitvector_free(b); return 0; }
void dec_viterbi_F(dvector* Metr_mem, unsigned char* history_mem, bitvector* bit_stream, const dvarray* Dist, const param_viterbi_t* param, size_t n) { size_t i_in = 0, i_punct, i, j, vote, bv = 0; double *Metr0, *Metr1, *Metr; char X0, X1, Y0, Y1; unsigned char history[MAX_Nways][MAX_history]; unsigned char history_new[MAX_Nways][MAX_history+1]; #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ double startTime, now, estTotal; #endif /* 0 */ if (bit_stream->length) { bitvector_clear(bit_stream); } if (n==0) { n = Dist->data[0].length; } bitvector_init(bit_stream, n); Metr = (double*)malloc(Metr_mem->length*sizeof(double)); Metr0 = (double*)malloc(Metr_mem->length*sizeof(double)); Metr1 = (double*)malloc(Metr_mem->length*sizeof(double)); memcpy(Metr, Metr_mem->data, Metr_mem->length*sizeof(double)); memcpy(history, history_mem, sizeof(history)); #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ startTime = sTime(); #endif /* 0 */ i_punct = 0; while (i_in<bit_stream->length) { #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ if (i_in && (i_in % 10000 == 0)) { now = sTime(); estTotal = ((double)1.02*bit_stream->length/((double)i_in))*(now-startTime); printf("Viterbi: Estimate %1.1lf%% complete (%1.1lf seconds / %1.1lf seconds)...\n", (double)100.0*i_in/(1.02*bit_stream->length), now-startTime, estTotal); fflush(stdout); } #endif /* 0 */ memcpy(Metr0, Metr, Metr_mem->length*sizeof(double)); memcpy(Metr1, Metr, Metr_mem->length*sizeof(double)); if (param->punct1[i_punct] == 1) { for (i=0; i<param->Nways; ++i) { X0 = param->Tabl_X[i]; X1 = 1 - param->Tabl_X[i]; Metr0[i] = Metr0[i] + Dist->data[X0].data[i_in]; Metr1[i] = Metr1[i] + Dist->data[X1].data[i_in]; } ++i_in; } if (param->punct2[i_punct] == 1) { if (i_in >= bit_stream->length) { assert(0 && "Synchronization in Viterbi: i_in > size(Dist,2)"); } for (i=0; i<param->Nways; ++i) { Y0 = param->Tabl_Y[i]; Y1 = 1 - param->Tabl_Y[i]; Metr0[i] = Metr0[i] + Dist->data[Y0].data[i_in]; Metr1[i] = Metr1[i] + Dist->data[Y1].data[i_in]; } ++i_in; } for (i=0; i<param->Nways/2; ++i) { if (Metr0[2*i] <= Metr0[2*i+1]) { Metr[i] = Metr0[2*i]; history_new[i][0] = 0; for (j=0; j<MAX_history; ++j) { history_new[i][j+1] = history[2*i][j]; } } else { Metr[i] = Metr0[2*i+1]; history_new[i][0] = 1; for (j=0; j<MAX_history; ++j) { history_new[i][j+1] = history[2*i+1][j]; } } if (Metr1[2*i] <= Metr1[2*i+1]) { Metr[i+param->Nways/2] = Metr1[2*i]; history_new[i+param->Nways/2][0] = 0; for (j=0; j<MAX_history; ++j) { history_new[i+param->Nways/2][j+1] = history[2*i][j]; } } else { Metr[i+param->Nways/2] = Metr1[2*i+1]; history_new[i+param->Nways/2][0] = 1; for (j=0; j<MAX_history; ++j) { history_new[i+param->Nways/2][j+1] = history[2*i+1][j]; } } } for (vote=i=0; i<param->Nways; ++i) { vote += (history_new[i][MAX_history] == 0); } if (vote >= param->Nways/2) { bit_stream->data[bv++] = 0; } else { bit_stream->data[bv++] = 1; } for (i=0; i<param->Nways; ++i) { for (j=0; j<MAX_history; ++j) { history[i][j] = history_new[i][j]; } } if (++i_punct == param->n_in) { i_punct = 0; } } bit_stream->data = (unsigned char*)realloc(bit_stream->data, bv*sizeof(unsigned char)); bit_stream->length = bv; memcpy(Metr_mem->data, Metr, Metr_mem->length*sizeof(double)); memcpy(history_mem, history, sizeof(history)); free(Metr); free(Metr0); free(Metr1); }