void test(void *arg) { int val = *(int*)arg; while (val--) { #if TEST_TYPE == COUNTER_T counter_increment(t); #elif TEST_TYPE == LIST_T list_insert(t, val); #else hash_insert(t, val); #endif } }
/* * Get current value, request timeout for next value, increment counter, check * notified correctly. */ static void test03(void) { uint32_t cur_value; L4_Word_t result; L4_Word_t notifybits = 0x1; L4_MsgTag_t tag; L4_Word_t mask; printf("%s: ", __func__); result = counter_current_value(&cur_value); if (result == 0) { FAILED(); return; } result = counter_request(cur_value + 1, main_tid, notifybits); if (result == 0) { FAILED(); return; } result = counter_increment(1); if (result == 0) { FAILED(); return; } L4_Set_NotifyMask(notifybits); L4_Accept(L4_NotifyMsgAcceptor); tag = L4_WaitNotify(&mask); if (L4_IpcFailed(tag)) { FAILED(); return; } PASSED(); }
int arithmetic_decoding(const char* encoded_file, const char* decoded_file) { FILE* fout; uint8_t byte; int i; int i_ss; int i_d; int n; int bitc = 0; uint64_t tmp, mask, stream_slice; int bits_to_read; struct CST* cumulative_sums_tree_pointer; struct BitBuffer* bbp = bit_open(encoded_file, BIT_BUFFER_READ); if (bbp == NULL) { printf("%s: No such file\n", encoded_file); return -1; } cumulative_sums_tree_pointer = CST_create(NUM_CODEPOINTS); if (cumulative_sums_tree_pointer == NULL) { printf("Error: CST creation failed\n"); bit_close(bbp); return -1; } fout = fopen(decoded_file, "wb"); if (fout == NULL) { printf("Error: cannot create output file %s\n", decoded_file); return -1; } // we deal with the zero-frequency problem initializing all counters to 1 and consequently NUM_CODEPOINTS to total_count total_count = NUM_CODEPOINTS; for (i=1; i<NUM_CODEPOINTS; i++) counter_increment(cumulative_sums_tree_pointer, i); LOW = 0; HIGH = 0xFFFFFFFFFFFFFFFF; bits_to_read = sizeof(uint64_t) * 8; stream_slice = 0x0000000000000000; for (;;) { n = bit_read(bbp, &tmp, bits_to_read); if (n == -1) { printf("Error occurred!!\n"); return -1; } // here n could be zero, but this is not a concern bitc+=n; if (bits_to_read == sizeof(uint64_t) * 8) mask = 0xFFFFFFFFFFFFFFFF; else mask = ((uint64_t)1 << bits_to_read) - 1; stream_slice = ((stream_slice << bits_to_read) | (tmp & mask)); /* i = 0; mask = 0x0000000000000001; while (i < bits_to_read) { stream_slice <<= 1; if (tmp & mask) stream_slice |= 0x0000000000000001; mask <<= 1; i++; } */ n = bs(cumulative_sums_tree_pointer, stream_slice); if (n == -1) return -1; if (n == NUM_CODEPOINTS - 1) // EOF symbol received break; byte = (uint8_t)n; fwrite(&byte, 1, 1, fout); tmp = ((HIGH - LOW) / total_count); HIGH = LOW + tmp * (cumulative_sums_lookup(cumulative_sums_tree_pointer, byte + 1)); LOW = LOW + tmp * cumulative_sums_lookup(cumulative_sums_tree_pointer, byte); // deadlock resolution if ((HIGH & 0xC000000000000000) == 0x8000000000000000 && (LOW & 0xC000000000000000) == 0x4000000000000000) { i_d = 2; mask = 0x2000000000000000; while (mask && (LOW & mask) && (HIGH & mask) == 0) { i_d++; mask >>= 1; } LOW &= ~mask; HIGH |= mask; HIGH <<= i_d; LOW <<= i_d; } else
/* * One frame of Viterbi time alignment. */ int32 align_frame (int32 *senscr) { int32 i, n, scr, tmpbest, bestscore, nf, thresh; snode_t *s, *ps; slink_t *l; history_t *tmphist; snode_t **tmpswap; nf = curfrm + 1; n_active = 0; /* For each active state update state score and history */ bestscore = (int32) 0x80000000; for (i = 0; cur_active[i]; i++) { s = cur_active[i]; assert (IS_SENID(s->sen)); tmpbest = (int32) 0x80000000; for (l = s->predlist; l; l = l->next) { ps = l->node; if (ps->active_frm == curfrm) { scr = ps->score + l->prob; if (scr > tmpbest) { tmpbest = scr; tmphist = ps->hist; } } } assert (tmpbest > (int32) 0x80000000); s->newscore = tmpbest + senscr[s->sen]; s->newhist = tmphist; if (s->newscore > bestscore) bestscore = s->newscore; } counter_increment (ctr_nstate, i); if (bestscore <= LOGPROB_ZERO) E_ERROR("Bestscore= %d in frame %d\n", bestscore, curfrm); score_scale[curfrm] = bestscore; thresh = bestscore + beam; /* Update history lattice for each active state */ for (i = 0; cur_active[i]; i++) { s = cur_active[i]; if (s->newscore >= thresh) { s->newscore -= bestscore; /* Scale, to avoid underflow */ s->score = s->newscore; s->hist = lat_entry (s); activate (s, nf); /* Also activate successor nodes of s as they are reachable next frame */ for (l = s->succlist; l; l = l->next) { if (IS_SENID(l->node->sen)) activate (l->node, nf); } } else { s->score = LOGPROB_ZERO; s->hist = NULL; } } /* Update active state list */ next_active[n_active] = NULL; tmpswap = cur_active; cur_active = next_active; next_active = tmpswap; curfrm = nf; return 0; }