/** \brief One-dimensional matching. This function performs the sort matching on a single dimension. \param ep_list the endpoints list \param out the matrix that is going to keep the result of the matching \param subscr_set_before the array to be used as the the set of "before" subscriptions \param subscr_set_after the array to be used as the the set of "after" subscriptions \param size_update the number of update extents \param size_subscr the number of subscription extents */ void sort_matching_1D(const list_ptr ep_list, const bitmatrix out, const bitvector subscr_set_before, const bitvector subscr_set_after, const _UINT size_update, const _UINT size_subscr) { _UINT i; _UINT bit_pos; _UINT line_width; _UINT list_size; _UINT update_ep_count; // two endpoints for each extent list_size = (size_update + size_subscr) * 2; // number of elements on each line of the bit matrix line_width = BIT_VEC_WIDTH(size_subscr); // number of endpoints of update extents update_ep_count = size_update * 2; // sort the endpoints list sort_list(ep_list, list_size); // set no subscription extent to "before" memset(subscr_set_before, 0x00, line_width * sizeof(bitvec_elem)); // set all the subscription extents to "after" memset(subscr_set_after, 0xFF, line_width * sizeof(bitvec_elem)); // for each endpoint in the list, but stops when all update extents endpoints are processed // (only when processing update extents endpoints the algorithm writes on the matching matrix) for (i = 0; update_ep_count > 0; i++) { // if it's the endpoint of a subscription extent if (ep_list[i].id < size_subscr) { // calculate the element in the bit vector that contains the bit bit_pos = BIT_TO_POS(ep_list[i].id); // if it's the lower endpoint if (ep_list[i].is_lower_point) { // clear the bit in the bit vector (remove the subscription extent from the "after" set) BIT_CLEAR(subscr_set_after[bit_pos], DBIT(BIT_POS_IN_VEC(ep_list[i].id, bit_pos))); } else // if it's the upper endpoint { // set the bit in the bit vector (add the subscription extent to the "before" set) BIT_SET(subscr_set_before[bit_pos], DBIT(BIT_POS_IN_VEC(ep_list[i].id, bit_pos))); } } else // if it's the endpoint of an update extent { update_ep_count--; // if it's the lower endpoint if (ep_list[i].is_lower_point) { #ifdef __LOWMEM // bitwise OR (write all the subscription extents in the "before" set in the update extent's line in the bit matrix) vector_bitwise_or(out[ep_list[i].id - size_subscr], subscr_set_before, line_width); #else // __LOWMEM // the subscription extents in the "before" set don't match with this update extent // (write the bits of the "before" set in the update extent's line in the bit matrix) memcpy(out[ep_list[i].id - size_subscr], subscr_set_before, line_width * sizeof(bitvec_elem)); #endif // __LOWMEM } else // if it's the upper endpoint { // bitwise OR (write all the subscription extents in the "after" set in the update extent's line in the bit matrix) vector_bitwise_or(out[ep_list[i].id - size_subscr], subscr_set_after, line_width); } } } }
void dev_decode_regs(insn_attrs_t *ia, u1_t rw, u2_t addr, u1_t data) { int pr = (ia == 0); u4_t f; char *strs[8] = {0,0,0,0,0,0,0,0}, **s = strs, **p = strs; //printf("ARM read %s @ 0x%x 0x%x <", arm_rreg[addr - ADDR_ARM(0)], addr, data); if (rw) switch (addr) { case RREG_LDACSR: DBIT(pr, s, data, DSR_TRIG_LVL_STOP); DBIT(pr, s, data, DSR_TRIG_LVL_START); DBIT(pr, s, data, DSR_SPARE); DBIT(pr, s, data, DSR_VOK); break; case RREG_I1: DBIT(pr, s, data, I1_IRQ); DBIT(pr, s, data, I1_RTI_MASK); DBIT(pr, s, data, I1_RST_TEST); DBIT(pr, s, data, I1_SRATE); DBIT(pr, s, data, I1_LRMT); DBIT(pr, s, data, I1_LRTL); DBIT(pr, s, data, I1_MAN_ARM); DBIT(pr, s, data, I1_IO_FLO); break; case RREG_ST: DBIT(pr, s, data, ST_OVEN); DBIT(pr, s, data, ST_EXT); break; case RREG_N0ST: DBIT(pr, s, data, N0ST_N3_OVFL); DBIT(pr, s, data, N0ST_EOM); DBIT(pr, s, data, N0ST_N0_POS); DBIT(pr, s, data, N0ST_ARMED); DBIT(pr, s, data, N0ST_PLL_OOL); DBIT(pr, s, data, N0ST_N0_OVFL); DBIT(pr, s, data, N0ST_N1N2_B17); DBIT(pr, s, data, N0ST_N1N2_B16); break; default: break; } //printf("ARM write %s @ 0x%x 0x%x <", arm_wreg[addr - ADDR_ARM(0)], addr, data); if (!rw) switch (addr) { case WREG_LDACCW: DBIT(pr, s, data, DCW_START_DAC_OE_L); DBIT(pr, s, data, DCW_STOP_DAC_OE_L); DBIT(pr, s, data, DCW_RELAY); DBIT(pr, s, data, DCW_LOCK_FIX); DBIT(pr, s, data, DCW_SPARE); DBIT(pr, s, data, DCW_HRMT_SLOPE); DBIT(pr, s, data, DCW_FWD_REV_START); DBIT(pr, s, data, DCW_FWD_REV_STOP); break; case WREG_O2: DBIT(pr, s, data, O2_FLAG); DBIT(pr, s, data, O2_SRATE_EN); DBIT(pr, s, data, O2_HTOGL); DBIT(pr, s, data, O2_GATE_MODE); DBIT(pr, s, data, O2_HARMCT3); DBIT(pr, s, data, O2_ARM_MODE); DBIT(pr, s, data, O2_MAN_ARM); DBIT(pr, s, data, O2_ARM_EN); break; case WREG_O1: DBIT(pr, s, data, O1_LRM_MASK); DBIT(pr, s, data, O1_RTI_MASK); DBIT(pr, s, data, O1_LHLDEN); DBIT(pr, s, data, O1_STOPSW); DBIT(pr, s, data, O1_STARTSW); DBIT(pr, s, data, O1_HSET2); DBIT(pr, s, data, O1_HSET1); DBIT(pr, s, data, O1_HSTD); break; case WREG_O3: DBIT(pr, s, data, O3_SELF_CLR); DBIT(pr, s, data, O3_RST_TEST); DBIT(pr, s, data, O3_LARMRST); DBIT(pr, s, data, O3_LOLRST); DBIT(pr, s, data, O3_N3_OVRST); DBIT(pr, s, data, O3_N0_OVRST); DBIT(pr, s, data, O3_N3_RST); DBIT(pr, s, data, O3_N012_RST); break; default: break; } if (!*p) return; if (!pr) f = ia->flags; //if (!pr && (f & _BIT)) PF("<%s> ", *p); else if (pr || (!pr && (f & (_BIT | _AND | _OR | _XOR)))) { PF("%s<", pr? "" : "[msk] "); int first=1; for (p=strs; p!=s; first=0, p++) PF("%s%s", first? "":", ", *p); PF("> "); } else if (!pr && *p) PF("FIXME %08x <%s> ", f, *p); }
/** \brief One-dimensional matching. This function performs the sort matching on a single dimension. It's the start routine of the threads created by the function sort_matching(). \remarks This is the Linux version of the function. \param pVoid a void pointer to the structure containing the parameters \retval a pointer to the error code, or NULL if an error happened during the allocation of the return code memory */ void *sort_matching_1D(void *pVoid) #endif // _MSC_VER { _UINT i; _UINT bit_pos; _UINT line; _UINT line_width; _UINT list_size; _UINT update_ep_count; thread_params params; list_ptr ep_list; bitvector subscr_set_before; bitvector subscr_set_after; #ifndef _MSC_VER _ERR_CODE *err; // allocate the memory for the return value err = (_ERR_CODE *)malloc(sizeof(_ERR_CODE)); if (err == NULL) return NULL; #endif // _MSC_VER params = *(thread_params *)pVoid; line_width = BIT_VEC_WIDTH(params.data.size_subscr); // two endpoints for each extent list_size = (params.data.size_update + params.data.size_subscr) * 2; // allocate the "list" ep_list = (list_ptr)malloc(list_size * sizeof(list_t)); // allocate the two subscription extents sets (setting no subscription extent to "before" with calloc) subscr_set_before = (bitvector)calloc(line_width, sizeof(bitvec_elem)); subscr_set_after = (bitvector)malloc(line_width * sizeof(bitvec_elem)); if (ep_list == NULL || subscr_set_before == NULL || subscr_set_after == NULL) { #ifdef _MSC_VER _endthreadex((unsigned int)err_alloc); return (unsigned int)err_alloc; #else // _MSC_VER *err = err_alloc; pthread_exit((void *)err); return (void *)err; #endif // _MSC_VER } // fill the endpoints "list" with the data of the dimension to be processed set_endpoints_list(params.data, ep_list, params.dimension); // number of elements on each line of the bit matrix line_width = BIT_VEC_WIDTH(params.data.size_subscr); // number of endpoints of update extents update_ep_count = params.data.size_update * 2; // sort the endpoints list sort_list(ep_list, list_size); // set all the subscription extents to "after" memset(subscr_set_after, 0xFF, line_width * sizeof(bitvec_elem)); // for each endpoint in the list, but stops when all update extents endpoints are processed // (only when processing update extents endpoints the algorithm writes on the matching matrix) for (i = 0; update_ep_count > 0; i++) { // if it's the endpoint of a subscription extent if (ep_list[i].id < params.data.size_subscr) { // calculate the element in the bit vector that contains the bit bit_pos = BIT_TO_POS(ep_list[i].id); // if it's the lower endpoint if (ep_list[i].is_lower_point) { // clear the bit in the bit vector (remove the subscription extent from the "after" set) BIT_CLEAR(subscr_set_after[bit_pos], DBIT(BIT_POS_IN_VEC(ep_list[i].id, bit_pos))); } else // if it's the upper endpoint { // set the bit in the bit vector (add the subscription extent to the "before" set) BIT_SET(subscr_set_before[bit_pos], DBIT(BIT_POS_IN_VEC(ep_list[i].id, bit_pos))); } } else // if it's the endpoint of an update extent { update_ep_count--; line = ep_list[i].id - params.data.size_subscr; #ifdef _MSC_VER // wait for mutex if the line is in use from another thread if (WaitForSingleObject(params.line_mutex[line], INFINITE) != WAIT_OBJECT_0) { _endthreadex((unsigned int)err_threads); return (unsigned int)err_threads; } #else // _MSC_VER // wait for mutex if the line is in use from another thread if (pthread_mutex_lock(¶ms.line_mutex[line]) != 0) { *err = err_threads; pthread_exit((void *)err); return (void *)err; } #endif // _MSC_VER // if it's the lower endpoint if (ep_list[i].is_lower_point) { // bitwise OR (write all the subscription extents in the "before" set in the update extent's line in the bit matrix) vector_bitwise_or(params.out[line], subscr_set_before, line_width); } else // if it's the upper endpoint { // bitwise OR (write all the subscription extents in the "after" set in the update extent's line in the bit matrix) vector_bitwise_or(params.out[line], subscr_set_after, line_width); } #ifdef _MSC_VER // release mutex if (ReleaseMutex(params.line_mutex[line]) == 0) { _endthreadex((unsigned int)err_threads); return (unsigned int)err_threads; } #else // _MSC_VER // release mutex if (pthread_mutex_unlock(¶ms.line_mutex[line]) != 0) { *err = err_threads; pthread_exit((void *)err); return (void *)err; } #endif // _MSC_VER } } #ifndef __NOFREE // free memory free(ep_list); free(subscr_set_before); free(subscr_set_after); #endif // __NOFREE #ifdef _MSC_VER _endthreadex((unsigned int)err_none); return (unsigned int)err_none; #else // _MSC_VER *err = err_none; pthread_exit((void *)err); return (void *)err; #endif // _MSC_VER }