static void generate_id_shading_table(struct ia_css_shading_table **target_table, const struct sh_css_binary *binary) { /* initialize table with ones, shift becomes zero */ unsigned int i, j, table_width, table_height; struct ia_css_shading_table *result; assert_exit(target_table != NULL); assert_exit(binary != NULL); table_width = binary->sctbl_width_per_color; table_height = binary->sctbl_height; result = ia_css_shading_table_alloc(table_width, table_height); if (result == NULL) { *target_table = NULL; return; } for (i = 0; i < IA_CSS_SC_NUM_COLORS; i++) { for (j = 0; j < table_height * table_width; j++) result->data[i][j] = 1; } result->fraction_bits = 0; *target_table = result; }
static inline void heap_sort_percolate_down(void *base, uint32 size, uint32 csize, uint32 index, sint32 (*compare)(const void *, const void *)) { uint32 i; void *tmp; uint32 child; assert_exit(sort_parameters_legal_p(base, size, csize, compare)); assert_exit(index < size); tmp = memory_cache_allocate(csize); sort_cell_copy(tmp, base + index * csize, csize); i = index; while (HEAP_LEFT(i) < size) { child = HEAP_LEFT(i); if (child != size - 1 && compare(base + child * csize, base + (child + 1) * csize) < 0) { child++; } if (compare(tmp, base + child * csize) < 0) { sort_cell_copy(base + i * csize, base + child * csize, csize); } else { break; } i = child; } sort_cell_copy(base + i * csize, tmp, csize); memory_cache_free(tmp); }
static inline bool splay_tree_contains_ip(s_splay_tree_t *tree, s_splay_tree_t *node) { sint64 nice; s_splay_tree_t *splay_node; assert_exit(splay_tree_structure_legal_ip(tree)); assert_exit(splay_tree_structure_legal_ip(node)); splay_node = tree; nice = node->nice; while (splay_node) { if (splay_node == node) { return true; } else if (splay_node->nice < nice) { splay_node = splay_node->right; } else if (splay_node->nice > nice) { splay_node = splay_node->left; } else { return false; } } return false; }
static inline void tkz_file_tk_io_buffer_process(s_tkz_io_buffer_t *tkz_io_buf, s_tkz_lang_t *tkz_lang, s_tk_t *tk_head) { bool is_string; s_io_block_t *io_block; assert_exit(tk_structure_legal_p(tk_head)); assert_exit(tkz_io_buf_structure_legal_p(tkz_io_buf)); is_string = false; io_block = tkz_io_block_create(); while (tkz_io_buf_fill_p(tkz_io_buf)) { if (tkz_io_buf_double_quote_p(tkz_io_buf)) { is_string = !is_string; tkz_io_block_char_fill(io_block, tkz_io_buf); } else if (is_string) { tkz_io_block_char_fill(io_block, tkz_io_buf); } else if (tkz_io_buf_comment_p(tkz_io_buf, tkz_lang->type)) { tkz_io_buf_skip_comment(tkz_io_buf, tkz_lang->type); } else if (!tkz_io_buf_char_space_p(tkz_io_buf)) { tkz_io_block_char_fill(io_block, tkz_io_buf); } else { tkz_io_block_fill(io_block, tkz_io_buf); tkz_file_tk_io_block_process(io_block, tk_head, tkz_lang); } } tkz_io_block_destroy(io_block); }
static inline void splay_tree_doubly_child_right_strip(s_splay_tree_t **splay_node) { s_splay_tree_t *splay; s_splay_tree_t *max; s_splay_tree_t **max_node; assert_exit(NON_NULL_PTR_P(splay_node)); assert_exit(splay_tree_structure_legal_ip(*splay_node)); assert_exit(splay_tree_doubly_child_p(*splay_node)); splay = *splay_node; if (splay->left->right == NULL) { /* short cut here */ *splay_node = splay->left; splay->left->right = splay->right; splay->left = splay->right = NULL; } else { max_node = splay_tree_find_ptr_to_max(&splay->left); max = *max_node; splay_tree_swap_child(splay, max); *max_node = splay; *splay_node = max; splay_tree_lt_doubly_child_strip(max_node); } }
static inline s_trie_tree_t * trie_tree_sub_queue_find(s_trie_tree_t *trie, uint32 val) { s_trie_tree_t *sub_node; s_array_queue_t *sub_queue; s_array_iterator_t *iterator; assert_exit(val != TRIE_TREE_ROOT); assert_exit(trie_tree_structure_legal_p(trie)); sub_queue = trie->sub_queue; iterator = array_queue_iterator_obtain(sub_queue); assert_exit(iterator != PTR_INVALID); iterator->fp_index_initial(sub_queue); while (iterator->fp_next_exist_p(sub_queue)) { sub_node = iterator->fp_next_obtain(sub_queue); if (sub_node->val == val && !sub_node->is_deleted) { return sub_node; } } return NULL; }
static inline bool trie_tree_sequence_matched_ip(s_trie_tree_t *trie, uint32 *sequence, uint32 len) { uint32 i; s_trie_tree_t *trie_node; assert_exit(!complain_zero_size_p(len)); assert_exit(trie_tree_root_node_p(trie)); assert_exit(trie_tree_structure_legal_p(trie)); assert_exit(!NULL_PTR_P(sequence)); trie_node = trie; i = 0; while (i < len) { trie_node = trie_tree_sub_queue_find(trie_node, sequence[i]); if (trie_node == NULL) { return false; } i++; } return trie_node->is_terminal; }
static inline void splay_tree_iterate_i(s_splay_tree_t *tree, void (*handler)(void *)) { s_array_queue_t *queue; s_splay_tree_t *splay_node; assert_exit(NON_NULL_PTR_P(handler)); assert_exit(splay_tree_structure_legal_ip(tree)); queue = array_queue_create(); array_queue_enter(queue, tree); while (!array_queue_empty_p(queue)) { splay_node = array_queue_leave(queue); handler(splay_node); if (splay_node->left) { array_queue_enter(queue, splay_node->left); } if (splay_node->right) { array_queue_enter(queue, splay_node->right); } } array_queue_destroy(&queue); }
static inline s_splay_tree_t * splay_tree_find_i(s_splay_tree_t **tree, sint64 nice) { s_splay_tree_t **iterator; s_splay_tree_t *splay_node; s_array_stack_t *path_stack; assert_exit(NON_NULL_PTR_P(tree)); assert_exit(splay_tree_structure_legal_ip(*tree)); iterator = tree; splay_node = *tree; path_stack = array_stack_create(); while (splay_node) { if (nice < splay_node->nice) { array_stack_push(path_stack, TREE_PATH_L_ENCODE(iterator)); iterator = &splay_node->left; } else if (nice > splay_node->nice) { array_stack_push(path_stack, TREE_PATH_R_ENCODE(iterator)); iterator = &splay_node->right; } else { splay_tree_splaying(path_stack); assert_exit(*tree = splay_node); break; } splay_node = *iterator; } array_stack_destroy(&path_stack); return splay_node; }
static inline s_splay_tree_t * splay_tree_find_max_i(s_splay_tree_t **tree) { s_splay_tree_t *max_node; s_splay_tree_t **iterator; s_array_stack_t *path_stack; assert_exit(NON_NULL_PTR_P(tree)); assert_exit(splay_tree_structure_legal_ip(*tree)); iterator = tree; max_node = *tree; path_stack = array_stack_create(); while (max_node->right) { array_stack_push(path_stack, TREE_PATH_R_ENCODE(iterator)); iterator = &max_node->right; max_node = *iterator; } splay_tree_splaying(path_stack); array_stack_destroy(&path_stack); assert_exit(*tree == max_node); return max_node; }
void sh_css_refcount_clear(int32_t id, void (*clear_func)(hrt_vaddress ptr)) { struct sh_css_refcount_entry *entry; uint32_t i; uint32_t count = 0; assert_exit(clear_func != NULL); sh_css_dtrace(SH_DBG_TRACE, "sh_css_refcount_clear(%x)\n", id); for (i = 0; i < myrefcount.size; i++) { entry = &myrefcount.items[i]; if ((entry->data != mmgr_NULL) && (entry->id == id)) { sh_css_dtrace(SH_DBG_TRACE, "sh_css_refcount_clear:" " %x: 0x%x\n", id, entry->data); if (clear_func) { /* clear using provided function */ clear_func(entry->data); } else { sh_css_dtrace(SH_DBG_TRACE, "sh_css_refcount_clear: " "using mmgr_free: no clear_func\n"); mmgr_free(entry->data); } assert_exit(entry->count == 0); entry->data = mmgr_NULL; entry->count = 0; entry->id = 0; count++; } } sh_css_dtrace(SH_DBG_TRACE, "sh_css_refcount_clear(%x): cleared %d\n", id, count); }
static inline void splay_tree_swap_child(s_splay_tree_t *a, s_splay_tree_t *b) { assert_exit(splay_tree_structure_legal_ip(a)); assert_exit(splay_tree_structure_legal_ip(b)); SWAP(a->left, b->left); SWAP(a->right, b->right); }
static inline void stacked_queue_resize_i(s_stacked_queue_t *queue, uint32 dim) { assert_exit(!complain_zero_size_p(dim)); assert_exit(stacked_queue_structure_legal_p(queue)); array_stack_resize(queue->enter, dim); array_stack_resize(queue->leave, dim); queue->dim = array_stack_capacity(queue->enter); }
static inline void nfa_closure_init(s_nfa_t *nfa, s_fa_closure_t *closure) { assert_exit(nfa_engine_structure_legal_p(nfa)); assert_exit(nfa_engine_graph_legal_p(nfa)); assert_exit(nfa_closure_structure_legal_p(closure)); array_queue_enter(closure->collection, nfa->start); nfa_closure_null_seek(closure); }
/* * Seek the collection set of nfa engine in 1 step move with char c or NULL_CHAR. * 1. Found all status in 1 step move with char c * 2. Base on step 1, Merge all status in 1 or more step with NULL_CHAR */ static inline void nfa_closure_seek(s_fa_closure_t *closure, char c) { assert_exit(nfa_closure_structure_legal_p(closure)); assert_exit(array_queue_empty_p(closure->path_queue)); bitmap_map_cleanup(closure->bitmap); nfa_closure_char_seek(closure, c); // Seek all status of moving 1 step with c nfa_closure_null_seek(closure); // Seek and Merge all status of moving NULL_CHAR }
static inline void splay_tree_child_strip(s_splay_tree_t **splay_node, sint32 direction) { assert_exit(NON_NULL_PTR_P(splay_node)); assert_exit(splay_tree_structure_legal_ip(*splay_node)); if (splay_tree_doubly_child_p(*splay_node)) { splay_tree_doubly_child_strip(splay_node, direction); } else { splay_tree_lt_doubly_child_strip(splay_node); } }
static inline void stacked_queue_stack_dump(s_array_stack_t *from, s_array_stack_t *to) { assert_exit(array_stack_structure_legal_p(to)); assert_exit(array_stack_structure_legal_p(from)); assert_exit(array_stack_empty_p(to)); assert_exit(array_stack_capacity(from) == array_stack_capacity(to)); while (!array_stack_empty_p(from)) { array_stack_push(to, array_stack_pop(from)); } }
static void insert_binary_metrics(struct sh_css_binary_metrics **l, struct sh_css_binary_metrics *metrics) { assert_exit(l != NULL); assert_exit(*l != NULL); assert_exit(metrics != NULL); for (; *l; l = &(*l)->next) if (*l == metrics) return; *l = metrics; metrics->next = NULL; }
int main() { #if XAPI_MODE_STACKTRACE_CHECKS // verify NOFATAL xapi exit = test_nofatal(); assert_exit(XAPI_NOFATAL, exit); // verify ILLFATAL exit = test_illfatal(); assert_exit(XAPI_ILLFATAL, exit); #endif // victory succeed; }
static inline void nfa_closure_match_dp_destroy(s_fa_match_dp_t **match_dp) { s_fa_match_dp_t *match_dp_tmp; assert_exit(match_dp != NULL); assert_exit(nfa_closure_match_dp_structure_legal_p(*match_dp)); match_dp_tmp = *match_dp; dp_free(match_dp_tmp->dp); dp_free(match_dp_tmp); *match_dp = NULL; }
static inline void * quick_sort_obtain_median(void *base, uint32 left, uint32 right, uint32 csize, sint32 (*compare)(const void *, const void *)) { void *ptr_l; void *ptr_r; void *ptr_m; assert_exit(sort_parameters_legal_p(base, csize, csize, compare)); ptr_l = base + left * csize; ptr_r = base + right * csize; ptr_m = base + ((left + right) / 2) * csize; if (compare(ptr_l, ptr_m) > 0) { sort_cell_swap(ptr_l, ptr_m, csize); } if (compare(ptr_l, ptr_r) > 0) { sort_cell_swap(ptr_l, ptr_r, csize); } if (compare(ptr_m, ptr_r) > 0) { sort_cell_swap(ptr_m, ptr_r, csize); } return ptr_m; }
s_tkz_file_t * tkz_file_create(char *fname) { s_tkz_file_t *tkz_file; assert_exit(fname); if (!fname) { return NULL; } else { tkz_file = dp_malloc(sizeof(*tkz_file)); tkz_file->filename = dp_malloc(dp_strlen(fname) + 1); dp_strcpy(tkz_file->filename, fname); tkz_file->tk_list = dp_malloc(sizeof(s_tk_t)); tkz_file->tk_list->data = dp_malloc(dp_strlen(fname) + 1); tkz_file->tk_list->type = TK_LEX_HEAD; dp_strcpy(tkz_file->tk_list->data, fname); doubly_linked_list_initial(&tkz_file->tk_list->list); tkz_file->tkz_language = tkz_lang_obtain(fname); tkz_file->tkz_io_buffer = tkz_io_buf_create(fname); dp_printf("[TKZ]: Analysis '%s'\n", tkz_file->filename); return tkz_file; } }
static inline void leftist_heap_destroy_i(s_leftist_heap_t *heap) { s_array_queue_t *queue; s_leftist_heap_t *node; assert_exit(leftist_heap_legal_ip(heap)); queue = array_queue_create(); array_queue_enter(queue, heap); while (!array_queue_empty_p(queue)) { node = array_queue_leave(queue); if (LEFTIST_LEFT(node) != NULL) { array_queue_enter(queue, LEFTIST_LEFT(node)); } if (LEFTIST_RIGHT(node) != NULL) { array_queue_enter(queue, LEFTIST_RIGHT(node)); } leftist_heap_node_destroy(node); } array_queue_destroy(&queue); }
static inline bool nfa_closure_empty_p(s_fa_closure_t *closure) { assert_exit(nfa_closure_structure_legal_p(closure)); return array_queue_empty_p(closure->collection); }
static inline void * leftist_heap_get_min_i(s_leftist_heap_t *heap) { assert_exit(leftist_heap_legal_p(heap)); return LEFTIST_VAL(heap); }
static inline void nfa_closure_char_seek(s_fa_closure_t *closure, char c) { s_fa_status_t *status; assert_exit(c != NULL_CHAR); assert_exit(nfa_closure_structure_legal_p(closure)); closure->c = c; swap_pointer((void *)&closure->path_queue, (void *)&closure->collection); while (!array_queue_empty_p(closure->path_queue)) { status = array_queue_leave(closure->path_queue); nfa_closure_char_status_seek(closure, status, c); } }
static inline void splay_tree_destroy_i(s_splay_tree_t *tree) { s_array_queue_t *queue; s_splay_tree_t *splay_node; assert_exit(splay_tree_structure_legal_ip(tree)); queue = array_queue_create(); array_queue_enter(queue, tree); while (!array_queue_empty_p(queue)) { splay_node = array_queue_leave(queue); if (splay_node->left != NULL) { array_queue_enter(queue, splay_node->left); } if (splay_node->right != NULL) { array_queue_enter(queue, splay_node->right); } doubly_linked_list_destroy(&splay_node->list); memory_cache_free(splay_node); } array_queue_destroy(&queue); }
static inline s_doubly_linked_list_t * splay_tree_val_list_i(s_splay_tree_t *tree) { assert_exit(splay_tree_structure_legal_ip(tree)); return tree->list; }
static inline void leftist_heap_node_destroy(s_leftist_heap_t *heap) { assert_exit(leftist_heap_legal_ip(heap)); memory_cache_free(heap); }
static inline void splay_tree_splaying(s_array_stack_t *path_stack) { uint32 path_mask; s_splay_tree_t **iterator; assert_exit(array_stack_structure_legal_p(path_stack)); while (array_stack_size(path_stack) >= 2) { iterator = array_stack_pop(path_stack); path_mask = TREE_PATH_TYPE(iterator); iterator = array_stack_pop(path_stack); path_mask = path_mask + (TREE_PATH_TYPE(iterator) << 1); iterator = TREE_PATH_DECODE(iterator); splay_tree_splaying_i(iterator, path_mask); } if (array_stack_size(path_stack) == 1) { iterator = array_stack_pop(path_stack); path_mask = TREE_PATH_TYPE(iterator); iterator = TREE_PATH_DECODE(iterator); splay_tree_splaying_root(iterator, path_mask); } }