2011/6/27 Georg-Johann Lay <a...@gjlay.de>:
> Denis Chertykov wrote:
>> 2011/6/26 Georg-Johann Lay <a...@gjlay.de>:
>>> Denis Chertykov schrieb:
>>>> 2011/6/24 Richard Henderson <r...@redhat.com>:
>>>>
>>>>> On 06/23/2011 01:15 PM, Denis Chertykov wrote:
>>>>>
>>>>>>>  text    data     bss     dec     hex filename
>>>>>>> 10032      25       0   10057    2749 bld-avr-orig/gcc/z.o
>>>>>>>  5816      25       0    5841    16d1 bld-avr-new/gcc/z.o
>>>>>> Richard, can you send me this z.c file ?
>>>>>> Right now I'm notice that new code is worse.
>>>>> That's gcc.c-torture/compile/950612-1.c.
>>>> I have founded that postreload optimizations can't handle results of
>>>> new L_R_A code.
>>>> I think that it's can be handled by CSE (postreload).
>>> Did you try to add constraint alternative to *addhi3?
>>> Like "*!d,d,n" or even "*!r,r,n"
>>>
>>> I saw some code improvement with that alternative.
>>
>> I'm trying:
>>
>> (define_insn "*addhi3"
>>   [(set (match_operand:HI 0 "register_operand" "=r,!w,!w,d,r,r,!d")
>>       (plus:HI
>>        (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0,!r")
>>        (match_operand:HI 2 "nonmemory_operand" "r,I,J,i,P,N,!ri")))]
>>   ""
>>   "@
>>       add %A0,%A2\;adc %B0,%B2
>>       adiw %A0,%2
>>       sbiw %A0,%n2
>>       subi %A0,lo8(-(%2))\;sbci %B0,hi8(-(%2))
>>       sec\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__
>>       sec\;sbc %A0,__zero_reg__\;sbc %B0,__zero_reg__
>>         #"
>>   [(set_attr "length" "2,1,1,2,3,3,4")
>>    (set_attr "cc" "set_n,set_czn,set_czn,set_czn,set_n,set_n,set_n")])
>>
>
> That split will split always:
>
>> ;; Special split three addressing addhi3
>> ;; to make postreload optimization possible
>> (define_split ; addhi3 !d,!r,!ri
>>   [(set (match_operand:HI 0 "d_register_operand" "")
>>       (plus:HI (match_operand:HI 1 "register_operand" "")
>>                (match_operand:HI 2 "nonmemory_operand" "")))]
>>   "reload_completed"
>     && REGNO(operands[0]) != REGNO(operands[1])"
>>   [(set (match_dup 0) (match_dup 2))
>>    (set (match_dup 0) (plus:HI (match_dup 0) (match_dup 1)))]
>>   "")
> Maybe it can also restrict to const_int_operand in #2 and then it's
> best to
>    (set (match_dup 0)
>         (match_dup 1))
>    (set (match_dup 0)
>         (plus:HI (match_dup 0)
>                  (match_dup 2)))

Thanks for suggestions.

>> The main problem for me is that the new addressing mode produce a
>> worse code in many tests.
>
> You have an example source?

In attachment.

Denis.
#include <stdarg.h>
#include <string.h>
#include <stdio.h>

#if 0
unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
{
	unsigned long result = 0,value;

	if (!base) {
		base = 10;
		if (*cp == '0') {
			base = 8;
			cp++;
			if ((*cp == 'x') && isxdigit(cp[1])) {
				cp++;
				base = 16;
			}
		}
	}
	while (isxdigit(*cp) && (value = is_digit(*cp) ? *cp-'0' : (islower(*cp)
	    ? toupper(*cp) : *cp)-'A'+10) < base) {
		result = result*base + value;
		cp++;
	}
	if (endp)
		*endp = (char *)cp;
	return result;
}
#endif

/* we use this so that we can do without the ctype library */

static int skip_atoi(const char **s)
{
	int i=0;

	while (is_digit(**s))
		i = i*10 + *((*s)++) - '0';
	return i;
}

#define ZEROPAD	1		/* pad with zero */
#define SIGN	2		/* unsigned/signed long */
#define PLUS	4		/* show plus */
#define SPACE	8		/* space if plus */
#define LEFT	16		/* left justified */
#define SPECIAL	32		/* 0x */
#define LARGE	64		/* use 'ABCDEF' instead of 'abcdef' */

#define do_div(n,base) ({ \
int __res; \
__res = ((unsigned long long) n) % (unsigned) base; \
n = ((unsigned long long) n) / (unsigned) base; \
__res; })
     
static char * number(char * str, long long num, int base, int size, int precision
	,int type)
{
	char c,sign,tmp[20];
	const char *digits="0123456789abcdef";
	int i;
	/*
	if (type & LARGE)
		digits = "0123456789ABCDEF";
	*/
	if (type & LEFT)
		type &= ~ZEROPAD;
	if (base < 2 || base > 36)
		return 0;
	c = (type & ZEROPAD) ? '0' : ' ';
	sign = 0;

	if (type & SIGN) {
		if (num < 0) {
			sign = '-';
			num = -num;
			size--;
		} else if (type & PLUS) {
			sign = '+';
			size--;
		} else if (type & SPACE) {
			sign = ' ';
			size--;
		}
	}
	if (type & SPECIAL) {
		if (base == 16)
			size -= 2;
		else if (base == 8)
			size--;
	}
	i = 0;
	if (num == 0)
		tmp[i++]='0';
	else while (num != 0)
	            tmp[i++] = digits[do_div(num,base)];
	if (i > precision)
		precision = i;
	size -= precision;
	if (!(type&(ZEROPAD+LEFT)))
		while(size-->0)
			*str++ = ' ';
	if (sign)
		*str++ = sign;
	if (type & SPECIAL) {
		if (base==8)
			*str++ = '0';
		else if (base==16) {
			*str++ = '0';
			*str++ = 'x';
		}
	}
	if (!(type & LEFT))
		while (size-- > 0)
			*str++ = c;
	while (i < precision--)
		*str++ = '0';
	while (i-- > 0)
		*str++ = tmp[i];
	while (size-- > 0)
		*str++ = ' ';
	return str;
}

static int vsprintf(char *buf, const char *fmt, va_list args)
{
	int len;
	unsigned long long num;
	int i, base;
	char * str;
	const char *s;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	for (str=buf ; *fmt ; ++fmt) {
		if (*fmt != '%') {
			*str++ = *fmt;
			continue;
		}
			
		/* process flags */
		flags = 0;
		repeat:
			++fmt;		/* this also skips first '%' */
			switch (*fmt) {
				case '-': flags |= LEFT; goto repeat;
				case '+': flags |= PLUS; goto repeat;
				case ' ': flags |= SPACE; goto repeat;
				case '#': flags |= SPECIAL; goto repeat;
				case '0': flags |= ZEROPAD; goto repeat;
				}
		
		/* get field width */
		field_width = -1;
		if (is_digit(*fmt))
			field_width = skip_atoi(&fmt);
		else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
#if 0
		if (*fmt == '.') {
			++fmt;	
			if (is_digit(*fmt))
				precision = skip_atoi(&fmt);
			else if (*fmt == '*') {
				++fmt;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
			if (precision < 0)
				precision = 0;
		}
#endif
		/* get the conversion qualifier */
		qualifier = -1;
		if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
			qualifier = *fmt;
			++fmt;
		}

		/* default base */
		base = 10;

		switch (*fmt) {
		  /*
		case 'c':
			if (!(flags & LEFT))
				while (--field_width > 0)
					*str++ = ' ';
			*str++ = (unsigned char) va_arg(args, int);
			while (--field_width > 0)
				*str++ = ' ';
			continue;
		  */
		case 's':
			s = va_arg(args, char *);
			if (!s)
				s = "<NULL>";

			len = strnlen(s, precision);

			if (!(flags & LEFT))
				while (len < field_width--)
					*str++ = ' ';
			for (i = 0; i < len; ++i)
				*str++ = *s++;
			while (len < field_width--)
				*str++ = ' ';
			continue;
			/*
		case 'p':
			if (field_width == -1) {
				field_width = 2*sizeof(void *);
				flags |= ZEROPAD;
			}
			str = number(str,
				(unsigned long) va_arg(args, void *), 16,
				field_width, precision, flags);
			continue;
			*/
			/*
		case 'n':
			if (qualifier == 'l') {
				long * ip = va_arg(args, long *);
				*ip = (str - buf);
			} else {
				int * ip = va_arg(args, int *);
				*ip = (str - buf);
			}
			continue;
			*/
		/* integer number formats - set up the flags and "break" */
			/*
		case 'o':
			base = 8;
			break;
			*/
			/*
		case 'X':
			flags |= LARGE;
			*/
		case 'x':
			base = 16;
			break;

		case 'd':
		case 'i':
			flags |= SIGN;
		case 'u':
			break;

		default:
			if (*fmt != '%')
				*str++ = '%';
			if (*fmt)
				*str++ = *fmt;
			else
				--fmt;
			continue;
		}
		if (qualifier == 'L')
		  num = va_arg(args, unsigned long long);
		else if (qualifier == 'l')
			if (flags & SIGN)
				num = va_arg(args, long);
			else
				num = va_arg(args, unsigned long);
		else if (qualifier == 'h') {
			if (flags & SIGN)
				num = va_arg(args, short);
			else
				num = va_arg(args, unsigned short);
		} else if (flags & SIGN)
			num = va_arg(args, int);
		else
			num = va_arg(args, unsigned int);
		str = number(str, num, base, field_width, precision, flags);
	}
	*str = '\0';
	return str-buf;
}

/*
int sprintf(char * buf, const char *fmt, ...)
{
	va_list args;
	int i;

	va_start(args, fmt);
	i=vsprintf(buf,fmt,args);
	va_end(args);
	return i;
}
*/

int printf(const char *fmt, ...)
{
  char buf[100];
  va_list args;
  int i;

  va_start(args, fmt);
  i=vsprintf(buf,fmt,args);
  send_str (buf);
  va_end(args);
  return i;
}

/* This demonstrates some of the compiler's common-subexpression*/
/* elimination capabilities.  For example, inspect the code */
/* generated for procedure Sort_array.  See the Programmer's    */
/* Guide for how to request an assembly listing on your host.   */

typedef unsigned char boolean;

void Sort_array();
long Tab[100];

main () {
   long I,J,K,L;

for (L = 0; L < 1000; L++) {
   /* Initialize the table that will be sorted. */
   K = 0;
   for (I = 9; I >= 0; I--)
      for (J = I*10; J < (I+1)*10; J++)
     Tab[K++] = J&1 ? J+1 : J-1;

/*   Print_array(); */
   Sort_array(Tab,99);     /* Sort it. */
/*   Print_array(); */
}
/* */ exit(0); /* */
}

void
Sort_array (Tab,Last)
     int Tab[];
     long Last;
{
   boolean Swap;
   int Temp,I;

   do
     {
       Swap = 0;
       for (I = 0; I < Last; I++)
	 if (Tab[I] > Tab[I+1])
	   {
	     Temp = Tab[I];
	     Tab[I] = Tab[I+1];
	     Tab[I+1] = Temp;
	     Swap = 1;
	   }
     } while (Swap);
}

void Print_array() {
   int I,J;
   /*printf("\nArray Contents:\n");*/
   for (I=0; I<=9; I++) {
      /*printf("%5d:",10*I); */
      for (J=0; J<=9; J++); /*printf("%5d",Tab[10*I+J]); */
      /* printf("\n");*/
      }
}

Reply via email to