Beispiel #1
0
static void
llshft(NODE *p)
{
	NODE *r = p->n_right;
	/* FIXME: we have sal/shl/sar/shr but we are limited to
	   shift right or left 1
	   shift right or left by CL */
	char *d[3];
	/* We ought to shortcut this earlier but it's not obivous how
	   to do a match and say 'any old register pair' FIXME */
	if (r->n_op == ICON) {
		/* FIXME: we need different versions of this for signed right
		   shifting. Just test code - register setup needs checking
		   for ordering etc yet */
		if (getrval(r) == 16) {
			if (p->n_op == RS)
				printf("\tmov ax, dx\n\txor dx,dx\n");
			else
				printf("\tmov dx, ax\n\txor ax,ax\n");
			return;
		}
		if (getrval(r) == 8) {
			if (p->n_op == RS)
				printf("\tmov al, ah\n\tmov ah, dl\n\tmov dl, dh\n\txor dh,dh\n");
			else
				printf("\tmov ah, al\n\tmov dl, ah\n\tmov dh, dl\n\txor al, al\n");
			return;
		} 
		if (getrval(r) == 24) {
			if (p->n_op == RS)
				printf("\txor dx,dx\n\tmov al, dh\n\txor ax,ax\n");
			else
				printf("\txor ax,ax\n\tmov dh, al\n\txor dx,dx\n");
			return;
		}
	}
	if (p->n_op == LS) {
		d[0] = "l", d[1] = "ax", d[2] = "dx";
	} else
		d[0] = "r", d[1] = "dx", d[2] = "ax";

	printf("\tsh%sdl %s,%s\n",d[0], d[1], d[2]);
	printf("\ts%s%sl %%cl,%s\n", p->n_op == RS &&
	    (p->n_left->n_type == ULONG || p->n_left->n_type == ULONGLONG) ?
	    				"h" : "a", d[0], d[1]);
	printf("\ttestb $16,%%cl\n");
	printf("\tje 1f\n");
	printf("\tmov %s,%s\n", d[1], d[2]);
	if (p->n_op == RS && (p->n_left->n_type == LONGLONG|| p->n_left->n_type == LONG))
		printf("\tsarl $31,%%edx\n");
	else
		printf("\txor %s,%s\n",d[1],d[1]);
	printf("1:\n");
}
Beispiel #2
0
struct lledge * kminstree ( struct lledge *root, int n )
{
	struct lledge *temp = NULL ;
	struct lledge *p, *q ;
	int noofedges = 0 ;
	int i, p1, p2 ;

	for ( i = 0 ; i < n ; i++ )
		stree[i] = i ;
	for ( i = 0 ; i < n ; i++ )
		count[i] = 0 ;

	while ( ( noofedges < ( n - 1 ) ) && ( root != NULL ) )
	{
		p = root ;

		root = root -> next ;

		p1 = getrval ( p -> v1 ) ;
		p2 = getrval ( p -> v2 ) ;

		if ( p1 != p2 )
		{
			combine ( p -> v1, p -> v2 ) ;
			noofedges++ ;
			mincost += p -> cost ;
			if ( temp == NULL )
			{
				temp = p ;
				q = temp ;
			}
			else
			{
				q -> next = p ;
				q = q -> next ;
			}
			q -> next = NULL ;
		}
	}
	return temp ;
}