avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] far addresses


From: Rogier Wolff
Subject: Re: [avr-chat] far addresses
Date: Tue, 29 Aug 2017 12:52:41 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Aug 29, 2017 at 11:54:24AM +0200, Bob von Knobloch wrote:

> I wouldn't call it a bug as the compiler is constructed for
> processors with a 16-bit address space.

Nononono! no! The compiler (gcc) is constructed for devices with a
32-bit address space. It has been quite reasonably hacked to work for
the 16-bit address space that the AVR has....

But I remember the days when my co-students were swearing at gcc
because it was not easy to get it to cooperate with a 16-bit address
space.... (and there are bugs you are way more likely to encounter 
in a 64 k address space than in 4G. For example, what happens
when you have: 
   print_bytes (char *p, int len)
   {
     char *q; 
     for (q=p+len;p < q;p++)
        putchar (*p);
   }

Works, right? Now have p point at just below halfway your addressing
space (say 0x7ff0) and q after (say 0x8010).... IIRC the above is
gcc's own idea for an optimization when you actually write
      for (i=0;i<len;i++,p++)
        putchar (*p);
Has this bug been fixed? It's been about 25 years since I reported
it....)

For AVR there is a big penalty when you are say indexing an array
where both the base address and the index are 16-bit numbers as
opposed to one of them only 8-bit.

You might use a trick: just store the upper 16 bits, the bottom bit is
always zero. This way you can have pointers across the whole 17-bit
progrmem. But you expect things like: 

  print_nibble (uint8_t b)
  {
    char digits="0123456789abcdef";
    putchar (digits[b]);
  }

to work. Or stuff where you walk a string one byte at a time: 
  print_string (/*progmem*/char *p)
  {
  while (*p)
    putchar (*p++);
  }

So to make stuff like that work, the only opption is to use 24-bit
progmem pointers. Again a big penalty for MOST operations.

        Roger. 

-- 
** address@hidden ** http://www.BitWizard.nl/ ** +31-15-2600998 **
**    Delftechpark 26 2628 XH  Delft, The Netherlands. KVK: 27239233    **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.



reply via email to

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