Re: GCC bug?

"Bruce D. Lightner" <[email protected]> Fri, 17 Dec 2021 14:01:15 -0800
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------LRN0bkvvGjei5OWG569jcmpB
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Ian,

Trying again... :-)

No, the "last one" should NOT be AVR_HAVE_RAMPZ.

The Z register and the RAMPD register are used together to address 
memory in an AVR part which supports RAMPD.

Some later AVR micrcontrollers have a "Z" register (i.e., AVR_HAVE_RAMPZ 
is set).  Newer, more capable versions of those same AVR parts can ALSO 
have a "RAMPD" register (i.e., AVR_HAVE_RAMPD is set).  If the AVR part 
has a "RAMPD" register then it will ALWAYS have a "Z" register.

The code you referenced changes the behavior of "emit_push_sfr()" 
depending upon whether the AVR part has both registers or only the Z 
register.

If there is no Z register then there NEVER is a RAMPD register. In that 
case neither AVR_HAVE_RAMPZ or AVR_HAVE_RAMPD will be set and 
"emit_push_sfr()" will never be called in the context you referenced.

Best regards,

Bruce

------------------------------------------------------------------------
On 12/17/2021 1:33 PM, Ian Molton wrote:
> Ok, I don't want to sound rude, but did anyone actually *read* what I wrote?
>
> I'll highlight the parts of lines in question this time, perhaps that
> will help...
>
> if (AVR_HAVE_RAMPZ
>      ^^^^^^^^^^^^^^
>             && TEST_HARD_REG_BIT (set, REG_Z)
>             && TEST_HARD_REG_BIT (set, REG_Z + 1))
>           {
>             emit_push_sfr (rampz_rtx, false /* frame */, AVR_HAVE_RAMPD,
>                                                          ^^^^^^^^^^^^^^
>   treg);
>           }
>
> OVER HERE ------------->>>>>--------------------------^^^^^^^^^^^^^^^^^
>
>
> Either I'm missing something here, or someone needs to explain to me why
> a test for AVR_HAVE_RAMPZ preceeds the use of AVR_HAVE_RAMPD in the code.
>
> Shouldn't that last one also be RAMPZ ?
>
> If not, why?
>
> -Ian
>
>
> On 17/12/2021 16:53, Bruce D. Lightner wrote:
>> Ian,
>>
>> I apologize if I was being obtuse! :-)
>>
>> The AVR_HAVE_RAMPD #define tells the routine "emit_push_sfr()" to save
>> the RAMPD register, but only if the third parameter to the call is
>> non-zero.  The constant AVR_HAVE_RAMPD will be non-zero if the AVR
>> micro-architecture supports a RAMPD register.
>>
>> That's why you see the code you reported.  Much older versions of
>> avr-gcc have "emit_push_sfr()" source code with one less parameter
>> (i.e., no AVR_HAVE_RAMPD reference) because the RAMPD "paging" register
>> is a relatively "new" AVR feature.
>>
>> Best regards,
>>
>> Bruce
>>
>> ------------------------------------------------------------------------
>> On 12/17/2021 5:39 AM, Ian Molton wrote:
>>> I think you misunderstood me;
>>>
>>> I know this is where the compiler will save RAMPZ where needed.
>>>
>>> So why is it referencing RAMP *D* ?
>>>
>>> On 17/12/2021 00:50, Bruce D. Lightner wrote:
>>>> Ian,
>>>>
>>>> Just from a purely AVR architecture point of view, the AVR_HAVE_RAMPD
>>>> #define indicates that the AVR chip in question supports the "RAMP"
>>>> paging register, described as follows:
>>>>
>>>>     *RAMPD*
>>>>     Register concatenated with the Z-register enabling direct addressing
>>>> of the whole data space on MCUs
>>>>     with more than 64KB data space.
>>>>
>>>> Eventually the originally tiny AVR chips' addressable memory got so big
>>>> that we needed a "paging" register.  (That's a repeating theme with
>>>> every 8-bit/16-bit microcontroller family.)
>>>>
>>>> So the "RAMPD" register needs to be saved along with the X, Y and Z
>>>> "special function" registers, if it is present.
>>>>
>>>> Best regards,
>>>>
>>>> Bruce
>>>>
>>>> ------------------------------------------------------------------------
>>>> On 12/16/2021 3:46 PM, Ian Molton wrote:
>>>>> Browsing the GCC source, I found this in gcc/config/avr/avr.c
>>>>>
>>>>>   if (AVR_HAVE_RAMPZ
>>>>>            && TEST_HARD_REG_BIT (set, REG_Z)
>>>>>            && TEST_HARD_REG_BIT (set, REG_Z + 1))
>>>>>          {
>>>>>            emit_push_sfr (rampz_rtx, false /* frame */, AVR_HAVE_RAMPD,
>>>>> treg);
>>>>>          }
>>>>>
>>>>>
>>>>> I wont pretend to fully understand this part of the compiler, but that
>>>>> AVR_HAVE_RAMPD looks shady to me?
>>>>>
>>>>> Anyone with deeper knowledge want to have a look?
>>>>>
>>>>> -Ian
>>>>>
>>


-- 
*Bruce D. Lightner*
*Lightner Engineering*
La Jolla, California 92037-3044
Email: [email protected]
URL: http://www.lightner.net/lightner/bruce/
--------------LRN0bkvvGjei5OWG569jcmpB
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Ian,<br>
      <br>
      Trying again... :-)<br>
      <br>
      No, the "last one" should NOT be AVR_HAVE_RAMPZ.<br>
      <br>
      The Z register and the RAMPD register are used together to address
      memory in an AVR part which supports RAMPD. <br>
      <br>
      Some later AVR micrcontrollers have a "Z" register (i.e.,
      AVR_HAVE_RAMPZ is set).  Newer, more capable versions of those
      same AVR parts can ALSO have a "RAMPD" register (i.e.,
      AVR_HAVE_RAMPD is set).  If the AVR part has a "RAMPD" register
      then it will ALWAYS have a "Z" register.<br>
      <br>
      The code you referenced changes the behavior of "emit_push_sfr()"
      depending upon whether the AVR part has both registers or only the
      Z register.<br>
      <br>
      If there is no Z register then there NEVER is a RAMPD register. 
      In that case neither AVR_HAVE_RAMPZ or AVR_HAVE_RAMPD will be set
      and "emit_push_sfr()" will never be called in the context you
      referenced.<br>
      <br>
      Best regards,<br>
      <br>
      Bruce<br>
      <br>
      <hr width="100%" size="2">On 12/17/2021 1:33 PM, Ian Molton wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <pre class="moz-quote-pre" wrap="">Ok, I don't want to sound rude, but did anyone actually *read* what I wrote?

I'll highlight the parts of lines in question this time, perhaps that
will help...

if (AVR_HAVE_RAMPZ
    ^^^^^^^^^^^^^^
           &amp;&amp; TEST_HARD_REG_BIT (set, REG_Z)
           &amp;&amp; TEST_HARD_REG_BIT (set, REG_Z + 1))
         {
           emit_push_sfr (rampz_rtx, false /* frame */, AVR_HAVE_RAMPD,
                                                        ^^^^^^^^^^^^^^
 treg);
         }

OVER HERE -------------&gt;&gt;&gt;&gt;&gt;--------------------------^^^^^^^^^^^^^^^^^


Either I'm missing something here, or someone needs to explain to me why
a test for AVR_HAVE_RAMPZ preceeds the use of AVR_HAVE_RAMPD in the code.

Shouldn't that last one also be RAMPZ ?

If not, why?

-Ian


On 17/12/2021 16:53, Bruce D. Lightner wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Ian,

I apologize if I was being obtuse! :-)

The AVR_HAVE_RAMPD #define tells the routine "emit_push_sfr()" to save
the RAMPD register, but only if the third parameter to the call is
non-zero.  The constant AVR_HAVE_RAMPD will be non-zero if the AVR
micro-architecture supports a RAMPD register.

That's why you see the code you reported.  Much older versions of
avr-gcc have "emit_push_sfr()" source code with one less parameter
(i.e., no AVR_HAVE_RAMPD reference) because the RAMPD "paging" register
is a relatively "new" AVR feature.

Best regards,

Bruce

------------------------------------------------------------------------
On 12/17/2021 5:39 AM, Ian Molton wrote:
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">I think you misunderstood me;

I know this is where the compiler will save RAMPZ where needed.

So why is it referencing RAMP *D* ?

On 17/12/2021 00:50, Bruce D. Lightner wrote:
</pre>
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">Ian,

Just from a purely AVR architecture point of view, the AVR_HAVE_RAMPD
#define indicates that the AVR chip in question supports the "RAMP"
paging register, described as follows:

   *RAMPD*
   Register concatenated with the Z-register enabling direct addressing
of the whole data space on MCUs
   with more than 64KB data space.

Eventually the originally tiny AVR chips' addressable memory got so big
that we needed a "paging" register.  (That's a repeating theme with
every 8-bit/16-bit microcontroller family.)

So the "RAMPD" register needs to be saved along with the X, Y and Z
"special function" registers, if it is present.

Best regards,

Bruce

------------------------------------------------------------------------
On 12/16/2021 3:46 PM, Ian Molton wrote:
</pre>
            <blockquote type="cite">
              <pre class="moz-quote-pre" wrap="">Browsing the GCC source, I found this in gcc/config/avr/avr.c

 if (AVR_HAVE_RAMPZ
          &amp;&amp; TEST_HARD_REG_BIT (set, REG_Z)
          &amp;&amp; TEST_HARD_REG_BIT (set, REG_Z + 1))
        {
          emit_push_sfr (rampz_rtx, false /* frame */, AVR_HAVE_RAMPD,
treg);
        }


I wont pretend to fully understand this part of the compiler, but that
AVR_HAVE_RAMPD looks shady to me?

Anyone with deeper knowledge want to have a look?

-Ian

</pre>
            </blockquote>
            <pre class="moz-quote-pre" wrap="">
</pre>
          </blockquote>
        </blockquote>
        <br>
      </blockquote>
    </blockquote>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      <span style="font-size:9pt;font-family:sans-serif;"> <b>Bruce D.
          Lightner</b><br>
        <b>Lightner Engineering</b><br>
        La Jolla, California 92037-3044<br>
        Email: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a><br>
        URL: <a class="moz-txt-link-freetext" href="http://www.lightner.net/lightner/bruce/">http://www.lightner.net/lightner/bruce/</a><br>
      </span></div>
  </body>
</html>
--------------LRN0bkvvGjei5OWG569jcmpB--