dnl dnl dnl @author: Michele Martone dnl include(`rsb_misc.m4')dnl include(`do_unroll.m4')dnl /* @cond INNERDOC */ /** * @file * @brief Auxiliary functions. */ RSB_M4_HEADER_MESSAGE()dnl dnl ifdef(`ONLY_WANT_HEADERS',` #ifndef RSB_MERGE_H_INCLUDED #define RSB_MERGE_H_INCLUDED ') dnl dnl #include "rsb_common.h" dnl #ifndef RSB_PS_ASSERT /*#define RSB_PS_ASSERT(e) assert(e) */ /* uncomment this to use asserts */ #define RSB_PS_ASSERT(e) /* uncomment this to avoid asserts */ #else /* RSB_PS_ASSERT */ #undef RSB_PS_ASSERT #define RSB_PS_ASSERT(e) #endif /* RSB_PS_ASSERT */ dnl dnl foreach(`mtype',RSB_M4_TYPES,`dnl dnl ifdef(`ONLY_WANT_HEADERS',`',`dnl static rsb_err_t rsb__do_util_merge_sorted_subarrays_in_place_`'RSB_M4_TYPE_CODE(mtype)`'( mtype *VA, rsb_coo_idx_t * IA, rsb_coo_idx_t * JA, rsb_char_t * W, rsb_nnz_idx_t annz, rsb_nnz_idx_t bnnz, size_t wsize, rsb_flags_t flags ) { dnl pushdef(`typecode',RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))`'dnl dnl /** * \ingroup gr_util * A B * +----------+----------+ * <- annz -> <- bnnz -> * * W * +------------+ * <- wnnz -> * * Merges an array containing two ordered subarrays A and B, * sized respectively with annz and bnnz elements, using a * swap area sized wsize bytes. * * NOTE: this is NOT an optimized code, just a naive one to have this functionality working. */ rsb_int_t wpasses; rsb_nnz_idx_t wnnz,nnz=annz+bnnz; mtype *VW=NULL; rsb_coo_idx_t * IW=NULL; rsb_coo_idx_t * JW=NULL; mtype *VB=NULL; rsb_coo_idx_t * IB=NULL; rsb_coo_idx_t * JB=NULL; size_t el_size=sizeof(mtype); int step; rsb_nnz_idx_t aoff=0,boff=0,woff=0; wnnz=wsize/(el_size+2*sizeof(rsb_coo_idx_t)); VW=(mtype*)W; W+=el_size*wnnz; IW=(rsb_coo_idx_t*)W; W+=sizeof(rsb_coo_idx_t)*wnnz; JW=(rsb_coo_idx_t*)W; VB=VA+annz; IB=IA+annz; JB=JA+annz; wpasses=(annz+bnnz+wnnz-1)/wnnz; #define RSB_COO_MOVE(VD,ID,JD,VS,IS,JS,doff,soff) \ VD[doff]=VS[soff], \ ID[doff]=IS[soff], \ JD[doff]=JS[soff],++soff,++doff #define RSB_CMP_COO_LESS_THAN(IA,JA,IB,JB,aoff,boff) \ IA[aoff]