コード例 #1
0
ファイル: memxor.c プロジェクト: randombit/hacrypto
static void
memxor3_different_alignment_b (word_t *dst,
                               const word_t *a, const uint8_t *b, unsigned offset, size_t n)
{
    int shl, shr;
    const word_t *b_word;

    word_t s0, s1;

    shl = CHAR_BIT * offset;
    shr = CHAR_BIT * (sizeof(word_t) - offset);

    b_word = (const word_t *) ((uintptr_t) b & -SIZEOF_LONG);

    if (n & 1)
    {
        n--;
        s1 = b_word[n];
        s0 = b_word[n+1];
        dst[n] = a[n] ^ MERGE (s1, shl, s0, shr);
    }
    else
        s1 = b_word[n];

    while (n > 0)
    {
        n -= 2;
        s0 = b_word[n+1];
        dst[n+1] = a[n+1] ^ MERGE(s0, shl, s1, shr);
        s1 = b_word[n];
        dst[n] = a[n] ^ MERGE(s1, shl, s0, shr);
    }
}
コード例 #2
0
ファイル: 14IE10028.c プロジェクト: hardik-tharad/Algo-Lab-1
node* MERGE(node *T,int l,int u)
{
    if(T==NULL)
        return NULL;
    if(T->lower>u)
    {
        T->lChild=MERGE(T->lChild,l,u);
        return T;
    }
    if(T->upper<l)
    {
        T->rChild=MERGE(T->rChild,l,u);
        return T;
    }
    node *N = (node*)malloc(sizeof(node));
    N->lower=l;
    N->upper=u;
    list *templist = (list*)malloc(sizeof(list));
    templist->next=NULL;
    templist->data=0;
    N->listptr=templist;
    N->lChild=NULL;
    N->rChild=NULL;
    eat(T,N,2,0);
    return N;
}
コード例 #3
0
ファイル: memxor.c プロジェクト: randombit/hacrypto
/* XOR *un-aligned* src-area onto aligned dst area. n is number of
   words, not bytes. Assumes we can read complete words at the start
   and end of the src operand. */
static void
memxor_different_alignment (word_t *dst, const uint8_t *src, size_t n)
{
    size_t i;
    int shl, shr;
    const word_t *src_word;
    unsigned offset = ALIGN_OFFSET (src);
    word_t s0, s1;

    shl = CHAR_BIT * offset;
    shr = CHAR_BIT * (sizeof(word_t) - offset);

    src_word = (const word_t *) ((uintptr_t) src & -SIZEOF_LONG);

    /* FIXME: Unroll four times, like memcmp? */
    i = n & 1;
    s0 = src_word[i];
    if (i)
    {
        s1 = src_word[0];
        dst[0] ^= MERGE (s1, shl, s0, shr);
    }

    for (; i < n; i += 2)
    {
        s1 = src_word[i+1];
        dst[i] ^= MERGE(s0, shl, s1, shr);
        s0 = src_word[i+2];
        dst[i+1] ^= MERGE(s1, shl, s0, shr);
    }
}
コード例 #4
0
ファイル: wordcopy.c プロジェクト: JamesLinus/glibc-mips
void
WORDCOPY_BWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
{
  op_t a0, a1, a2;
  int sh_1, sh_2;
  int align;

  /* Calculate how to shift a word read at the memory operation
     aligned srcp to make it aligned for copy.  */

  align = srcp % OPSIZ;
  sh_1 = 8 * (srcp % OPSIZ);
  sh_2 = 8 * OPSIZ - sh_1;

  /* Make srcp aligned by rounding it down to the beginning of the op_t
     it points in the middle of.  */
  srcp &= -OPSIZ;
  a2 = ((op_t *) srcp)[0];

  if (len & 1)
  {
    srcp -= OPSIZ;
    dstp -= OPSIZ;
    a1 = ((op_t *) srcp)[0];
    ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);

    if (len == 1)
      return;

    a2 = a1;
    len -= 1;
  }

  bwd_align_merge (align);
}
コード例 #5
0
ファイル: 14IE10028.c プロジェクト: hardik-tharad/Algo-Lab-1
int main()
{
    srand(time(NULL));
    int l,u,n,i,loop;
    l=1;u=100;n=15;i=30;
    /*
    printf("Enter l : ");
    scanf("%d",&l);
    printf("Enter u : ");
    scanf("%d",&u);
    printf("Enter n : ");
    scanf("%d",&n);
    printf("Enter i : ");
    scanf("%d",&i);
    */
    interval=(u-l+1)/n;
    node *root = (node*)malloc(sizeof(node));
    root = CREATE_INTERVAL_TREE(l, u, n);
    for(loop=1;loop<=i;loop++)
    {
        int k=l+rand()%(u-l+1);
        INSERT(root,k);
    }
    PRETTY_PRINT(root, maxDepth(root));
    printf("\n");
    MERGE(root,2,10);
    PRETTY_PRINT(root, maxDepth(root));
    printf("\n");
}
コード例 #6
0
ファイル: vrp68.c プロジェクト: AlexMioMio/gcc
void test1 (int i, int j, int b)
{
  RANGE(i, 2, 6);
  ANTI_RANGE(j, 1, 7);
  MERGE(b, i, j);
  CHECK_ANTI_RANGE(i, 1, 1);
}
コード例 #7
0
ファイル: memcpy.c プロジェクト: 0-T-0/ps4-linux
/* stream-lined (read x4 + write x4) */
static void _wordcopy_fwd_dest_aligned(long int dstp, long int srcp,
					size_t len)
{
	op_t ap;
	int sh_1, sh_2;

	/* Calculate how to shift a word read at the memory operation
	aligned srcp to make it aligned for copy. */

	sh_1 = 8 * (srcp % OPSIZ);
	sh_2 = 8 * OPSIZ - sh_1;

	/* Make SRCP aligned by rounding it down to the beginning of the `op_t'
	it points in the middle of. */
	srcp &= -OPSIZ;
	ap = ((op_t *) srcp)[0];
	srcp += OPSIZ;

	while (len > 3) {
		op_t a0, a1, a2, a3;

		a0 = ((op_t *) srcp)[0];
		a1 = ((op_t *) srcp)[1];
		a2 = ((op_t *) srcp)[2];
		a3 = ((op_t *) srcp)[3];
		((op_t *) dstp)[0] = MERGE(ap, sh_1, a0, sh_2);
		((op_t *) dstp)[1] = MERGE(a0, sh_1, a1, sh_2);
		((op_t *) dstp)[2] = MERGE(a1, sh_1, a2, sh_2);
		((op_t *) dstp)[3] = MERGE(a2, sh_1, a3, sh_2);

		ap = a3;
		srcp += 4 * OPSIZ;
		dstp += 4 * OPSIZ;
		len -= 4;
	}
	while (len > 0) {
		register op_t a0;

		a0 = ((op_t *) srcp)[0];
		((op_t *) dstp)[0] = MERGE(ap, sh_1, a0, sh_2);

		ap = a0;
		srcp += OPSIZ;
		dstp += OPSIZ;
		len -= 1;
	}
}
// 归并排序
void MERGE_SORT(int* A, int p, int r) {
    if (p < r) {
        int q = (p + r)/2;
        MERGE_SORT(A, p, q);
        MERGE_SORT(A, q+1, r);
        MERGE(A, p, q, r);
    }
}
コード例 #9
0
ファイル: mergeSort.c プロジェクト: qeesung/algorithm
//归并排序的核心操作
//输入一个子数组,具有左边界left以及右边界right
void MERGE(int subArray[],const int left, const int right)
{
	if(left >= right)
		return;
	int center = (left+right)/2;
	MERGE(subArray,left,center);
	MERGE(subArray,center+1,right);
	//创建两个子数组
	int leftArrayLength = center-left+2;
	int rightArrayLength = right-center+1;
	int leftSubArray[leftArrayLength];//这里需要添加一个无穷大的哨兵,避免每次的边界检测
	int rightSubArray[rightArrayLength];
	int i,j;
	int k;
/*	printf("%d+++%d\n",leftArrayLength,rightArrayLength );
	printf("%s+++++++center:%d++++left:%d+++++right:%d+++\n","left",center,left,right );
*/	for(i=0;i<leftArrayLength-1;++i)
	{
		leftSubArray[i]=subArray[i+left];
	}
/*	printf("\n");
	printf("%s+++++++center:%d++++left:%d+++++right:%d+++\n","right",center,left,right );
*/	for(j=0;j<rightArrayLength-1;++j)
	{
		rightSubArray[j]=subArray[j+center+1];
	}
	leftSubArray[leftArrayLength-1]=INT_MAX;//哨兵
	rightSubArray[rightArrayLength-1]=INT_MAX;

	//开始归并,依次取出最小的放入到目标数组里面
	i=0;
	j=0;
	for(k=left;k<=right;++k)
	{
		if(leftSubArray[i] >= rightSubArray[j])
		{
			subArray[k]=rightSubArray[j];
			++j;
		}
		else
		{
			subArray[k]=leftSubArray[i];
			++i;
		}
	}
}
コード例 #10
0
ファイル: wordcopy.c プロジェクト: riscv/riscv-glibc
void
WORDCOPY_FWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
{
  op_t a0, a1, a2;
  int sh_1, sh_2;

  /* Calculate how to shift a word read at the memory operation
     aligned srcp to make it aligned for copy.  */

  sh_1 = 8 * (srcp % OPSIZ);
  sh_2 = 8 * OPSIZ - sh_1;

  /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
     it points in the middle of.  */
  srcp &= -OPSIZ;
  a0 = ((op_t *) srcp)[0];

  if (len & 1)
  {
    a1 = ((op_t *) srcp)[1];
    ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);

    if (len == 1)
      return;

    a0 = a1;
    srcp += OPSIZ;
    dstp += OPSIZ;
    len -= 1;
  }

  do
    {
      a1 = ((op_t *) srcp)[1];
      a2 = ((op_t *) srcp)[2];
      ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
      ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
      a0 = a2;

      srcp += 2 * OPSIZ;
      dstp += 2 * OPSIZ;
      len -= 2;
    }
  while (len != 0);
}
コード例 #11
0
ファイル: 2-3.c プロジェクト: Chu2015/CLRS
void MERGESORT(int A[], int p, int r)
{
    int q = 0;
    if (p < r) {
        q = (p + r) / 2;
        MERGESORT(A, p, q);
        MERGESORT(A, q + 1, r);
        MERGE(A, p, q, r);
    }
}
コード例 #12
0
ファイル: Sort.cpp プロジェクト: ToFind1991/Algorithm
void MERGE_SORT_PART(int *a, int left, int right)
{
    if (left == right) {
        return;
    }
    int middle = (left+right)/2;
    MERGE_SORT_PART(a, left, middle);
    MERGE_SORT_PART(a, middle+1, right);
    MERGE(a, left, middle, right);
}
コード例 #13
0
ファイル: MERGE_SORT_2.cpp プロジェクト: huanle543/Algorithms
void MERGE_SORT(int a[], int p, int r)
{
    if (p<r)
    {
        int q = (p + r) / 2;                   //直接强制转换到int取整
        MERGE_SORT(a, p, q);
        MERGE_SORT(a, q + 1, r);
        MERGE(a, p, q, r);
    }
}
コード例 #14
0
ファイル: MERGE.c プロジェクト: JiangTao11/Practice
int main(void)
{
	int A[7] = { 1, 3, 6, 2, 4, 5, 8 };
	int p = 0;
	int q = 3;
	int r = 7;
	MERGE(A, p, q, r);
	return 0;


}
コード例 #15
0
ファイル: merge_sort.c プロジェクト: morgengc/algorithm
void MERGE_SORT(int A[], const unsigned int p, const unsigned int r) 
{ 
	if(p < r) 
	{ 
		int q = (p + r) / 2; 
		MERGE_SORT(A, p, q); 
		MERGE_SORT(A, q + 1, r);

		MERGE(A, p, q, r); 
	} 
} 
コード例 #16
0
ファイル: text_style.c プロジェクト: RamSwaroopK/vlc
void text_style_Merge( text_style_t *p_dst, const text_style_t *p_src, bool b_override )
{
    if( p_src->psz_fontname && (!p_dst->psz_fontname || b_override) )
    {
        free( p_dst->psz_fontname );
        p_dst->psz_fontname = strdup( p_src->psz_fontname );
    }

    if( p_src->psz_monofontname && (!p_dst->psz_monofontname || b_override) )
    {
        free( p_dst->psz_monofontname );
        p_dst->psz_monofontname = strdup( p_src->psz_monofontname );
    }

    if( p_src->i_features != STYLE_NO_DEFAULTS )
    {
        MERGE(i_font_color,         STYLE_HAS_FONT_COLOR);
        MERGE(i_font_alpha,         STYLE_HAS_FONT_ALPHA);
        MERGE(i_outline_color,      STYLE_HAS_OUTLINE_COLOR);
        MERGE(i_outline_alpha,      STYLE_HAS_OUTLINE_ALPHA);
        MERGE(i_shadow_color,       STYLE_HAS_SHADOW_COLOR);
        MERGE(i_shadow_alpha,       STYLE_HAS_SHADOW_ALPHA);
        MERGE(i_background_color,   STYLE_HAS_BACKGROUND_COLOR);
        MERGE(i_background_alpha,   STYLE_HAS_BACKGROUND_ALPHA);
        MERGE(i_karaoke_background_color, STYLE_HAS_K_BACKGROUND_COLOR);
        MERGE(i_karaoke_background_alpha, STYLE_HAS_K_BACKGROUND_ALPHA);
        p_dst->i_features |= p_src->i_features;
        p_dst->i_style_flags |= p_src->i_style_flags;
    }

    MERGE_SIZE(f_font_relsize);
    MERGE_SIZE(i_font_size);
    MERGE_SIZE(i_outline_width);
    MERGE_SIZE(i_shadow_width);
    MERGE_SIZE(i_spacing);
}
コード例 #17
0
ファイル: Mergesort.c プロジェクト: Aries0331/cmput379
void MERGE_SORT(int array[], int begin, int end)
{
    int mid;
    int lpid, rpid;
    
    if(begin < end) {
        mid = (begin + end) / 2;
        
        /* create the first child */
        lpid = fork();
        if(lpid < 0) {
            perror("fork");
            exit(1);
        }
        else if(lpid == 0) {
            MERGE_SORT(array,begin,mid);
            shmdt(shmem_array);
            exit(0);
        }
        else {
            waitpid(lpid,NULL,0);
            /* create the second child */
            rpid = fork();
            if(rpid < 0) {
                perror("fork");
                exit(1);
            }
            else if(rpid == 0) {
                MERGE_SORT(array,mid+1,end);
                shmdt(shmem_array);
                exit(0);
            }
        }
        
        /* The parent process has to wait for both children to finish their work */
        waitpid(rpid,NULL,0);
        
        MERGE(array,begin,mid,end);
    }

}
コード例 #18
0
ファイル: memxor.c プロジェクト: randombit/hacrypto
static void
memxor3_different_alignment_all (word_t *dst,
                                 const uint8_t *a, const uint8_t *b,
                                 unsigned a_offset, unsigned b_offset,
                                 size_t n)
{
    int al, ar, bl, br;
    const word_t *a_word;
    const word_t *b_word;

    word_t a0, a1, b0, b1;

    al = CHAR_BIT * a_offset;
    ar = CHAR_BIT * (sizeof(word_t) - a_offset);
    bl = CHAR_BIT * b_offset;
    br = CHAR_BIT * (sizeof(word_t) - b_offset);

    a_word = (const word_t *) ((uintptr_t) a & -SIZEOF_LONG);
    b_word = (const word_t *) ((uintptr_t) b & -SIZEOF_LONG);

    if (n & 1)
    {
        n--;
        a1 = a_word[n];
        a0 = a_word[n+1];
        b1 = b_word[n];
        b0 = b_word[n+1];

        dst[n] = MERGE (a1, al, a0, ar) ^ MERGE (b1, bl, b0, br);
    }
    else
    {
        a1 = a_word[n];
        b1 = b_word[n];
    }

    while (n > 0)
    {
        n -= 2;
        a0 = a_word[n+1];
        b0 = b_word[n+1];
        dst[n+1] = MERGE(a0, al, a1, ar) ^ MERGE(b0, bl, b1, br);
        a1 = a_word[n];
        b1 = b_word[n];
        dst[n] = MERGE(a1, al, a0, ar) ^ MERGE(b1, bl, b0, br);
    }
}
コード例 #19
0
ファイル: setmode.c プロジェクト: nidheeshdas/Algosim
static int buildframedriver(GrVideoMode *mp,GrFrameDriver *drv)
{
    GrFrameDriver *d1, *d2;
    int res = TRUE;
    GRX_ENTER();
    res = TRUE;
    d1 = _GrFindFrameDriver(mp->extinfo->mode);
    d2 = mp->extinfo->drv;
    if(d1) sttcopy(drv,d1);
    if(d2) {
        int compl = TRUE;
#           define MERGE(F) if(d2->F) drv->F = d2->F; else compl = FALSE;
        MERGE(readpixel);
        MERGE(drawpixel);
        MERGE(drawhline);
        MERGE(drawvline);
        MERGE(drawblock);
        MERGE(drawline);
        MERGE(drawbitmap);
        MERGE(drawpattern);
        MERGE(bitblt);
        MERGE(bltv2r);
        MERGE(bltr2v);
        MERGE(getindexedscanline);
        MERGE(putscanline);
        if(compl) {
            memcpy(drv,d2,offsetof(GrFrameDriver,readpixel));
            goto done; /* TRUE */
        }
        if(!d1) {
            res = FALSE;
            goto done;
        }
        if((d2->mode == d1->mode) &&
                (d2->rmode == d1->rmode) &&
                (d1->is_video ? d2->is_video : !d2->is_video) &&
                (d2->row_align <= d1->row_align) && !(d1->row_align % d2->row_align) &&
                (d2->num_planes == d1->num_planes) &&
                (d2->max_plane_size >= d1->max_plane_size) &&
                (d2->bits_per_pixel == d1->bits_per_pixel)) {
            drv->init = d2->init ? d2->init : d1->init;
            goto done; /* TRUE */
        }
    }
    if(!d1) {
        res = FALSE;
        goto done;
    }
    sttcopy(drv,d1);
done:
    GRX_RETURN(res);
}
コード例 #20
0
ファイル: memcopy.c プロジェクト: 12rafael/jellytimekernel
/*
 * _wordcopy_bwd_dest_aligned -- Copy block finishing right before SRCP to
 * block finishing right before DSTP with LEN `op_t' words (not LEN bytes!).
 * DSTP should be aligned for memory operations on `op_t', but SRCP must *not*
 * be aligned.
 */
void _wordcopy_bwd_dest_aligned (long int dstp, long int srcp, size_t len)
{
	op_t a0, a1, a2, a3;
	int sh_1, sh_2;

	/*
	 * Calculate how to shift a word read at the memory operation aligned
	 * srcp to make it aligned for copy.
	 */

	sh_1 = 8 * (srcp % OPSIZ);
	sh_2 = 8 * OPSIZ - sh_1;

	/*
	 * Make srcp aligned by rounding it down to the beginning of the op_t
	 * it points in the middle of.
	 */
	srcp &= -OPSIZ;
	srcp += OPSIZ;

	switch (len % 4) {
	case 2:
		srcp -= 3 * OPSIZ;
		dstp -= 1 * OPSIZ;
		a2 = ((op_t *) srcp)[2];
		a1 = ((op_t *) srcp)[1];
		len += 2;
		goto do1;
	case 3:
		srcp -= 4 * OPSIZ;
		dstp -= 2 * OPSIZ;
		a3 = ((op_t *) srcp)[3];
		a2 = ((op_t *) srcp)[2];
		len += 1;
		goto do2;
	case 0:
		if (OP_T_THRESHOLD <= 3 * OPSIZ && len == 0)
			return;
		srcp -= 5 * OPSIZ;
		dstp -= 3 * OPSIZ;
		a0 = ((op_t *) srcp)[4];
		a3 = ((op_t *) srcp)[3];
		goto do3;
	case 1:
		srcp -= 6 * OPSIZ;
		dstp -= 4 * OPSIZ;
		a1 = ((op_t *) srcp)[5];
		a0 = ((op_t *) srcp)[4];
		len -= 1;
		if (OP_T_THRESHOLD <= 3 * OPSIZ && len == 0)
			goto do0;
		goto do4;			/* No-op.  */
	}

	do {
do4:
		a3 = ((op_t *) srcp)[3];
		((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
do3:
		a2 = ((op_t *) srcp)[2];
		((op_t *) dstp)[2] = MERGE (a3, sh_1, a0, sh_2);
do2:
		a1 = ((op_t *) srcp)[1];
		((op_t *) dstp)[1] = MERGE (a2, sh_1, a3, sh_2);
do1:
		a0 = ((op_t *) srcp)[0];
		((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);

		srcp -= 4 * OPSIZ;
		dstp -= 4 * OPSIZ;
		len -= 4;
	} while (len != 0);

	/*
	 * This is the right position for do0.  Please don't move it into
	 * the loop.
	 */
do0:
	((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
}
コード例 #21
0
ファイル: memcmp.c プロジェクト: brianmcgillion/graphene
/* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN
   `op_t' objects (not LEN bytes!).  SRCP2 should be aligned for memory
   operations on `op_t', but SRCP1 *should be unaligned*.  */
static int memcmp_not_common_alignment (long srcp1, long srcp2, int len)
{
    op_t a0, a1, a2, a3;
    op_t b0, b1, b2, b3;
    op_t x;
    int shl, shr;

    /* Calculate how to shift a word read at the memory operation
       aligned srcp1 to make it aligned for comparison.  */
    shl = 8 * (srcp1 % OPSIZ);
    shr = 8 * OPSIZ - shl;

    /* Make SRCP1 aligned by rounding it down to the beginning of the `op_t'
       it points in the middle of.  */
    srcp1 &= -OPSIZ;

    switch (len % 4) {
        default: /* Avoid warning about uninitialized local variables.  */
        case 2:
            a1 = ((op_t *) srcp1)[0];
            a2 = ((op_t *) srcp1)[1];
            b2 = ((op_t *) srcp2)[0];
            srcp1 -= 1 * OPSIZ;
            srcp2 -= 2 * OPSIZ;
            len += 2;
            goto do1;
        case 3:
            a0 = ((op_t *) srcp1)[0];
            a1 = ((op_t *) srcp1)[1];
            b1 = ((op_t *) srcp2)[0];
            srcp2 -= 1 * OPSIZ;
            len += 1;
            goto do2;
        case 0:
            if (OP_T_THRES <= 3 * OPSIZ && len == 0)
                return 0;
            a3 = ((op_t *) srcp1)[0];
            a0 = ((op_t *) srcp1)[1];
            b0 = ((op_t *) srcp2)[0];
            srcp1 += 1 * OPSIZ;
            goto do3;
        case 1:
            a2 = ((op_t *) srcp1)[0];
            a3 = ((op_t *) srcp1)[1];
            b3 = ((op_t *) srcp2)[0];
            srcp1 += 2 * OPSIZ;
            srcp2 += 1 * OPSIZ;
            len -= 1;
            if (OP_T_THRES <= 3 * OPSIZ && len == 0)
                goto do0;
            /* Fall through.  */
    }

    do {
        a0 = ((op_t *) srcp1)[0];
        b0 = ((op_t *) srcp2)[0];
        x = MERGE(a2, shl, a3, shr);
        if (x != b3)
            return CMP_LT_OR_GT (x, b3);

do3:
        a1 = ((op_t *) srcp1)[1];
        b1 = ((op_t *) srcp2)[1];
        x = MERGE(a3, shl, a0, shr);
        if (x != b0)
            return CMP_LT_OR_GT (x, b0);

do2:
        a2 = ((op_t *) srcp1)[2];
        b2 = ((op_t *) srcp2)[2];
        x = MERGE(a0, shl, a1, shr);
        if (x != b1)
            return CMP_LT_OR_GT (x, b1);

do1:
        a3 = ((op_t *) srcp1)[3];
        b3 = ((op_t *) srcp2)[3];
        x = MERGE(a1, shl, a2, shr);
        if (x != b2)
            return CMP_LT_OR_GT (x, b2);

        srcp1 += 4 * OPSIZ;
        srcp2 += 4 * OPSIZ;
        len -= 4;
    } while (len != 0);

    /* This is the right position for do0.  Please don't move
       it into the loop.  */
do0:
    x = MERGE(a2, shl, a3, shr);
    if (x != b3)
        return CMP_LT_OR_GT (x, b3);
    return 0;
}
コード例 #22
0
ファイル: memcmp.c プロジェクト: berkus/nemesis
static op_t
memcmp_not_common_alignment (long int srcp1, long int srcp2, size_t len)
 
{
  op_t a0, a1, a2, a3;
  op_t b0, b1, b2, b3;
  op_t res;
  op_t x;
  int shl, shr;

  /* Calculate how to shift a word read at the memory operation
     aligned srcp1 to make it aligned for comparison.  */

  shl = 8 * (srcp1 % OPSIZ);
  shr = 8 * OPSIZ - shl;

  /* Make SRCP1 aligned by rounding it down to the beginning of the `op_t'
     it points in the middle of.  */
  srcp1 &= -OPSIZ;

  switch (len % 4)
    {
    case 2:
      a1 = ((op_t *) srcp1)[0];
      a2 = ((op_t *) srcp1)[1];
      b2 = ((op_t *) srcp2)[0];
      srcp1 -= 1 * OPSIZ;
      srcp2 -= 2 * OPSIZ;
      len += 2;
      goto do1;
    case 3:
      a0 = ((op_t *) srcp1)[0];
      a1 = ((op_t *) srcp1)[1];
      b1 = ((op_t *) srcp2)[0];
      srcp2 -= 1 * OPSIZ;
      len += 1;
      goto do2;
    case 0:
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
	return 0;
      a3 = ((op_t *) srcp1)[0];
      a0 = ((op_t *) srcp1)[1];
      b0 = ((op_t *) srcp2)[0];
      srcp1 += 1 * OPSIZ;
      goto do3;
    case 1:
      a2 = ((op_t *) srcp1)[0];
      a3 = ((op_t *) srcp1)[1];
      b3 = ((op_t *) srcp2)[0];
      srcp1 += 2 * OPSIZ;
      srcp2 += 1 * OPSIZ;
      len -= 1;
      if (OP_T_THRES <= 3 * OPSIZ && len == 0)
	goto do0;
      /* Fall through.  */
    }

  do
    {
      a0 = ((op_t *) srcp1)[0];
      b0 = ((op_t *) srcp2)[0];
      x = MERGE(a2, shl, a3, shr);
      res = x - b3;
      if (res != 0)
	return res;
    do3:
      a1 = ((op_t *) srcp1)[1];
      b1 = ((op_t *) srcp2)[1];
      x = MERGE(a3, shl, a0, shr);
      res = x - b0;
      if (res != 0)
	return res;
    do2:
      a2 = ((op_t *) srcp1)[2];
      b2 = ((op_t *) srcp2)[2];
      x = MERGE(a0, shl, a1, shr);
      res = x - b1;
      if (res != 0)
	return res;
    do1:
      a3 = ((op_t *) srcp1)[3];
      b3 = ((op_t *) srcp2)[3];
      x = MERGE(a1, shl, a2, shr);
      res = x - b2;
      if (res != 0)
	return res;

      srcp1 += 4 * OPSIZ;
      srcp2 += 4 * OPSIZ;
      len -= 4;
    }
  while (len != 0);

  /* This is the right position for do0.  Please don't move
     it into the loop.  */
 do0:
  x = MERGE(a2, shl, a3, shr);
  return x - b3;
}
コード例 #23
0
ファイル: mlib_v_VectorMerge.c プロジェクト: Aries85/mediaLib
mlib_status
__mlib_VectorMerge_S32C_S32(
	mlib_s32 *z,
	const mlib_s32 *rr,
	const mlib_s32 *ii,
	mlib_s32 n)
{
/* pointer to real source vector */
	mlib_u32 *src_r = (mlib_u32 *)rr;

/* pointer to imaginary source vector */
	mlib_u32 *src_i = (mlib_u32 *)ii;

/* pointer to resultant complex vector */
	mlib_u32 *dst = (mlib_u32 *)z;
	mlib_s32 len = n + n, odd = 0, i;
	mlib_d64 d1, d2, d3, d4;

	vis_write_bmask(0x012389ab, 0);

	if (n < 4) {
		MERGE(mlib_s32,
			rr,
			ii,
			n,
			z);
	}

	if (((mlib_addr)dst) & 7) {
		(*dst++) = (*src_r++);
		len--;
		odd = 1;
	}

	if (!(((mlib_addr)src_r ^ (mlib_addr)src_i) & 7)) {

		if (odd) {

			if (((mlib_addr)src_i & 7) && (len >= 2)) {
				(*dst++) = (*src_i++);
				(*dst++) = (*src_r++);
				len -= 2;
			}
#pragma pipeloop(0)
			for (i = 0; i <= (len - 4); i += 4) {
				d1 = *((mlib_d64 *)src_i);
				src_i += 2;
				d2 = *((mlib_d64 *)src_r);
				src_r += 2;
				MERGE32;
				((mlib_d64 *)dst)[0] = d3;
				((mlib_d64 *)dst)[1] = d4;
				dst += 4;
			}

			if (i <= len - 2) {
				(*dst++) = (*src_i++);
				(*dst++) = (*src_r++);
			}

			(*dst++) = (*src_i++);
		} else {
			if ((mlib_addr)src_i & 7) {
				(*dst++) = (*src_r++);
				(*dst++) = (*src_i++);
				len -= 2;
			}
#pragma pipeloop(0)
			for (i = 0; i <= (len - 4); i += 4) {
				d1 = *((mlib_d64 *)src_r);
				src_r += 2;
				d2 = *((mlib_d64 *)src_i);
				src_i += 2;
				MERGE32;
				((mlib_d64 *)dst)[0] = d3;
				((mlib_d64 *)dst)[1] = d4;
				dst += 4;
			}

			if (i <= len - 2) {
				(*dst++) = (*src_r++);
				(*dst++) = (*src_i++);
			}
		}
	} else {
		mlib_f32 fsrc_r, fsrc_i;

		if (odd) {
#pragma pipeloop(0)
			for (i = 0; i <= (len - 2); i += 2) {
				fsrc_r = *((mlib_f32 *)src_r);
				src_r++;
				fsrc_i = *((mlib_f32 *)src_i);
				src_i++;
				d1 = vis_freg_pair(fsrc_i, fsrc_r);
				((mlib_d64 *)dst)[0] = d1;
				dst += 2;
			}

			(*dst++) = (*src_i++);
		} else {
			mlib_f32 fsrc_r, fsrc_i;

#pragma pipeloop(0)
			for (i = 0; i < len; i += 2) {
				fsrc_r = *((mlib_f32 *)src_r);
				src_r++;
				fsrc_i = *((mlib_f32 *)src_i);
				src_i++;
				d1 = vis_freg_pair(fsrc_r, fsrc_i);
				((mlib_d64 *)dst)[0] = d1;
				dst += 2;
			}
		}
	}

	return ((n > 0) ? MLIB_SUCCESS : MLIB_FAILURE);
}
コード例 #24
0
ファイル: mlib_v_VectorMerge.c プロジェクト: Aries85/mediaLib
mlib_status
__mlib_VectorMerge_S16C_S16(
	mlib_s16 *z,
	const mlib_s16 *rr,
	const mlib_s16 *ii,
	mlib_s32 n)
{
/* pointer to real source vector */
	mlib_s16 *src_r = (void *)rr;

/* pointer to imaginary source vector */
	mlib_s16 *src_i = (void *)ii;

/* pointer to resultant complex vector */
	mlib_s16 *dst = z;

/* mlib_d64 pointer to real source vector */
	mlib_d64 *dsrc_r;

/* mlib_d64 pointer to imaginary source vector */
	mlib_d64 *dsrc_i;

/* mlib_d64 pointer to resultant complex vector */
	mlib_d64 *ddst;
	mlib_s32 len_64, even_length, rest_64, length = n, i;
	mlib_s32 odd = 0;
	mlib_d64 d1, d2, d1_r, d1_i, d2_r, d2_i;
	mlib_d64 d3, d4, d31, d41;

	if (n < 8) {
		MERGE(mlib_s16,
			rr,
			ii,
			n,
			z);
	}

/*
 * First, try to align destination address for 8 bytes .
 */

	while ((mlib_addr)dst & 7) {
		(*dst++) = (*src_r++);
		length--;

		if (!((mlib_addr)dst & 7)) {
			odd = 1;
			break;
		}

		(*dst++) = (*src_i++);
	}

	len_64 = length >> 2;
	rest_64 = length & 3;
	even_length = len_64 << 2;
	ddst = (mlib_d64 *)dst;

	vis_write_bmask(0x13025746, 0);

/*
 * Now analyze the alignments of source vectors.
 */

	if ((!((mlib_addr)src_r & 7)) && (!((mlib_addr)src_i & 7))) {

/*
 * Both input vectors are 8-byte aligned.
 */
		dsrc_r = (mlib_d64 *)src_r;
		dsrc_i = (mlib_d64 *)src_i;

		if (!odd) {

/*
 * First "alignment" loop finished with imaginary part.
 * Start the next merge with real part.
 */
			for (i = 0; i < len_64; i++) {
				d1 = (*dsrc_r++);
				d2 = (*dsrc_i++);
				MERGE16;
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		} else {

/*
 * First "alignment" loop finished with real part.
 * Start the next merge with imaginary part.
 */
			for (i = 0; i < len_64; i++) {
				d2 = (*dsrc_r++);
				d1 = (*dsrc_i++);
				MERGE16;
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		}
	} else if (((mlib_addr)src_r & 7) == ((mlib_addr)src_i & 7)) {

/*
 * Both input vectors have the same address alignment.
 * We cam use only 1 vis_faligndata inside loop.
 */
		dsrc_r = (mlib_d64 *)vis_alignaddr((void *)src_r, 0);
		dsrc_i = (mlib_d64 *)vis_alignaddr((void *)src_i, 0);
		d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
		d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;

		if (!odd) {

/*
 * First "alignment" loop finished with imaginary part.
 * Start the next merge with real part.
 */
#pragma pipeloop(0)
			for (i = 0; i < len_64; i++) {
				d1_r = d2_r;
				d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
				d1 = vis_faligndata(d1_r, d2_r);
				d1_i = d2_i;
				d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;
				d2 = vis_faligndata(d1_i, d2_i);
				MERGE16;
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		} else {

/*
 * First "alignment" loop finished with real part.
 * Start the next merge with imaginary part.
 */
#pragma pipeloop(0)
			for (i = 0; i < len_64; i++) {
				d1_r = d2_r;
				d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
				d2 = vis_faligndata(d1_r, d2_r);
				d1_i = d2_i;
				d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;
				d1 = vis_faligndata(d1_i, d2_i);
				MERGE16;
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		}
	} else {

/*
 * Input vectors have different arbitrary alignments.
 * We have to use vis_alignaddr() and vis_faligndata() on
 * each loop iteration.
 */

		dsrc_i = (mlib_d64 *)vis_alignaddr((void *)src_i, 0);
		dsrc_r = (mlib_d64 *)vis_alignaddr((void *)src_r, 0);
		d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
		d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;

		if (!odd) {

/*
 * First "alignment" loop finished with imaginary part.
 * Start the next merge with real part.
 */
#pragma pipeloop(0)
			for (i = 0; i < len_64; i++) {
				d1_r = d2_r;
				d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
				d1 = vis_faligndata(d1_r, d2_r);
				d1_i = d2_i;
				vis_alignaddr((void *)src_i, 0);
				d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;
				d2 = vis_faligndata(d1_i, d2_i);
				MERGE16;
				vis_alignaddr((void *)src_r, 0);
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		} else {
#pragma pipeloop(0)
			for (i = 0; i < len_64; i++) {
				d1_r = d2_r;
				d2_r = vis_ld_d64_nf(dsrc_r); dsrc_r++;
				d2 = vis_faligndata(d1_r, d2_r);
				vis_alignaddr((void *)src_i, 0);
				d1_i = d2_i;
				d2_i = vis_ld_d64_nf(dsrc_i); dsrc_i++;
				d1 = vis_faligndata(d1_i, d2_i);
				MERGE16;
				vis_alignaddr((void *)src_r, 0);
				ddst[0] = d3;
				ddst[1] = d4;
				ddst += 2;
			}
		}
	}

	dst += (even_length << 1);
	src_r += even_length;
	src_i += even_length;

	if (odd) {
		(*dst++) = (*src_i++);
	}

	for (i = 0; i < rest_64; i++) {
		(*dst++) = (*src_r++);
		(*dst++) = (*src_i++);
	}

	return (MLIB_SUCCESS);
}
コード例 #25
0
ファイル: assn5.c プロジェクト: greptruth/algo_lab
int MERGE(Node* root,int l,int u,Node* node,Node* pare)
{

	int overlap=0;
	if(root==NULL)
		return 0;
	//printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%d %d \n",root->l,root->u);
	/*if(pare==NULL)
		printf("Here if it %d %d \n\n",root->l,root->u);
	else
		printf("Here if it none %d %d %d %d \n\n",root->l,root->u,pare->l,pare->u);
*/
	//printf("YET TO BE SUPER CASE %d %d \n\n",root->l,root->u);
	if((root->u >= l && root->u <= u)||(root->l < u && root->l > l))//upper of interval is inside range or lower of interval is inside range
	{
		//printf("SUPER CASE %d %d \n\n",root->l,root->u);
		overlap=1;
		//printf("Satya %d %d \n",root->l,root->u);
			
		//ADD_MERGE(root,l,u,node);

		if((root->l >= l) && (root->u<= u))
		{
			if(node==NULL)
			{
				node=root;
				pare = root;
				//printf("\n\n\nHolster\n\n\n");
			}


			//parent = root;
			printf("1>>>>>>> %d %d \n",root->l,root->u);
			LIST_MERGE(root->list,l,u,node->list);
			node->l=min(root->l,node->l);
			node->u=max(root->u,node->u);
			root->l=0;
			root->u=0;
		}	
		else if(root->u >=l && root->u <= u)//upper of root is inside range LEFT CASE
		{
			overlap=0;
			if(node==NULL)
			{
				node=root;
				pare = root;
				//printf("\n\n\nHolster\n\n\n");
			}


			Node* tempNode = malloc(sizeof(Node));
			printf("2>>>>>>> %d %d \n",root->l,root->u);
			printf("******%d %d \n",root->u,node->u);
			LIST_MERGE(root->list,l,u,node->list);
			node->l=l;

			//new node things
			tempNode->u=l;
			tempNode->l=root->l;
			tempNode->list=NULL;
			tempNode->left=root->left;
			tempNode->right = NULL;
			tempNode->parent= pare;
			pare->left = tempNode;
			if(tempNode->left!=NULL)
				tempNode->left->parent = tempNode;

			printf("~~~~~~~~~~######### %d %d ~~~~~~~~~pare %d %d %d %d\n\n",tempNode->l,tempNode->u,pare->l,pare->u,pare->left->l,pare->left->u);
			
		}
		else if(root->l < u && root->l > l)//lower of root is inside range RIGHT CASE
		{
			overlap=0;

			if(node==NULL)
			{
				node=root;
				pare = root;
				//printf("\n\n\nHolster\n\n\n");
			}


			Node* tempNode = malloc(sizeof(Node));
			printf("3>>>>>>> %d %d \n",root->l,root->u);
			printf("******%d %d \n",root->u,node->u);
			LIST_MERGE(root->list,l,u,node->list);
			//printf("^^^^%d %d %d %d \n",root->l,root->u,tempNode->l,tempNode->u);

			
			//printf("^^^^%d %d %d %d \n",root->l,root->u,tempNode->l,tempNode->u);
			//new node things
			tempNode->l=u;
			tempNode->u=root->u;
			node->u=u;
			tempNode->list=NULL;
			tempNode->left=NULL;
			tempNode->right = root->right;
			if(tempNode->right!=NULL)
				tempNode->right->parent = tempNode;
			pare->right = tempNode;

			// tempNode->l=777;
			// tempNode->u=999;

			printf("~~~~~~~~~~&&&&&&&&&&%d %d %d %d ~~~~~~~~~pare %d %d %d %d \n\n",tempNode->l,tempNode->u,root->l,root->u,pare->l,pare->u,pare->right->l,pare->right->u);
			
		}
	}
	int ret1,ret2;
	//printf("right called \n");
	ret2 = MERGE(root->right,l,u,node,pare);
	//printf("left called \n");
	ret1 = MERGE(root->left,l,u,node,pare);
	
	//printf("Gargantuan ");
	
	/*if(!ret1 && pare!=NULL)
	{
		//printf("%d %d \n",root->l,root->u);
		//if(pare==NULL)
			//printf("misery all around \n");
		pare->left = root->left;
	}
	
	if(!ret2 && pare!=NULL)
	{
		// printf("%d %d \n",root->l,root->u);
		// if(pare==NULL)
		// 	printf("misery all around \n");
		pare->right = root->right;
	}
	//printf("gone \n");*/
	//printf("------------------------------------------------------------------------------------------%d %d \n",root->l,root->u);

	/*if(ret1==1 && ret2==1)
	{
		overlap = 1;
	}*/

	/*if(root->right!=NULL)
		if(root->right->l==0&&root->right->u==0)
			root->right=NULL;
	if(root->left!=NULL)
		if(root->left->l==0&&root->left->u==0)
			root->left=NULL;*/

	/*if(ret1==1 && ret2==1)//(overlap==1)
	{
		if(root->parent!=NULL)
			root->parent->
		//printf("%d((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( %d %d\n",overlap,root->l,root->u);
		root->right=NULL;
		root->left=NULL;
		if(overlap==1)
			return 1;
	}*/
	
	return 0;
	
}
コード例 #26
0
ファイル: mergeSort.c プロジェクト: qeesung/algorithm
void mergeSort(int inputArray[] ,const int arrayLength)
{
	MERGE(inputArray,0,arrayLength-1);
}
コード例 #27
0
ファイル: compar.c プロジェクト: 8l/CompCert
unsigned int g(int x, unsigned int y, char * z)
{
  unsigned int r = 0;

#define MERGE(tst) r = (r << 1) | (tst)

  /* Without explicit comparison */
  MERGE((_Bool) x);
  MERGE((_Bool) y);
  MERGE((_Bool) z);

  /* Negated comparisons */
  MERGE((_Bool) !x);
  MERGE((_Bool) !y);
  MERGE((_Bool) !z);

  /* Explicit comparisons against 0 */
  MERGE(x == 0);
  MERGE(y == 0);
  MERGE(z == 0);

  MERGE(x != 0);
  MERGE(y != 0);
  MERGE(z != 0);

  /* With masks */
  MERGE((_Bool) (x & 1));
  MERGE(! (x & 2));
  MERGE((x & 4) == 0);
  MERGE((x & 8) != 0);

  return r;
}