avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] error with optimized boolean logic in gcc


From: Sean D'Epagnier
Subject: Re: [avr-gcc-list] error with optimized boolean logic in gcc
Date: Sat, 26 Nov 2011 00:01:22 +1300
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Nov 25, 2011 at 11:18:17AM +0100, Georg-Johann Lay wrote:
> >
> >In avr.md I changed:
> >    return "sbi %i0,%2";
> >to
> >    return "sbi %i0-0x20,%2";
> >
> >It fixed the problem.  I think this needs to be done all over the place
> 
> This is an incorrect fix, the problem must be somewhere else.
> 

Indeed, I didn't like it much, but it helped me understand the problem.

> %i shall subtract avr_current_arch->sfr_offset which is 0x20 for all
> architectures.  The reason to use %i and not %m is to avoid magic
> numbers 0x20 all over the place, see top of following changeset and
> %i implementation in avr.c:print_operand()
> 
> http://gcc.gnu.org/viewcvs?view=revision&revision=181552
> 
> +      else if (code == 'i')
> +        {
> +          if (!io_address_operand (addr, GET_MODE (x)))
> +            fatal_insn ("bad address, not an I/O address:", addr);
> +
> +          switch (INTVAL (addr))
> +            {
> +            case RAMPZ_ADDR: fprintf (file, "__RAMPZ__"); break;
> +            case SREG_ADDR: fprintf (file, "__SREG__"); break;
> +            case SP_ADDR:   fprintf (file, "__SP_L__"); break;
> +            case SP_ADDR+1: fprintf (file, "__SP_H__"); break;
> +
> +            default:
> +              fprintf (file, HOST_WIDE_INT_PRINT_HEX,
> +                       UINTVAL (addr) - avr_current_arch->sfr_offset);
> +              break;
> +            }
> +        }
> 

This makes a lot more sense now, but the above code is never reached.
If you go a bit higher up in the function you will see:

  else if (GET_CODE (x) == CONST_INT)
->  fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) + abcd);
  else if (GET_CODE (x) == MEM)
    {
      ...
      bit of code from above
      ...
    }

code is indeed 'i', but GET_CODE(x) is CONST_INT not MEM, so the conversion
never takes place.

We could of course perform the conversion in both places, but I don't
really like that either.  Maybe perform the subraction earlier as for abcd?

Sean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]