Pointer Autodecrement

Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Pointer Autodecrement

 · 
Posted: 26.05.2011 - 18:23  ·  #1
The opertors ^++ and ++ are useful in speed sensitive applications. It would be good to have the decrement counterpart ^-- and -- too.

Regards

Merlin.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Pointer Autodecrement

 · 
Posted: 26.05.2011 - 18:37  ·  #2
Hello Merlin,

nice to have. But there is a small problem.
The auto-increment of pointer accesses is build-in with some AVR opcodes. It uses post-increment.
The auto-decrement feature is somewhat more difficult to handle because it uses pre-decrement.
If this is implemented with AVRco then the user must do some precautions:
Code
var
  ar      : array[0..10] of byte;
  p       : pointer;
  bb     : byte;
...
  p:= @ar + size(ar); // +1 ???
  bb:= p^--;

rolf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Re: Pointer Autodecrement

 · 
Posted: 27.05.2011 - 12:46  ·  #3
Hi Rolf.

A good point. The intention (at pascal level) was post-decrement, not pre-decrement. So this is what I would want to do (and nearly can). (I know it is buggy - it is just to give an idea...)
Code

var
  ar : array[1..10] of byte;
  pa, pb : pointer to byte;
  br : array[1..9] of byte;
  carry : boolean;

...
  pa := @ar[10];
  pb := @br[9];
  carry := FALSE;
  for i := 1 to 9 
    if carry then
      dec( pa^);
   endif;
   carry := pb^ > pa^;
   pa^-- := pa^ - pb^--;  // not pa^ := pa^-- - pb^--; !!!
  endfor;


But yes, at assembler level efficiency will be reduced because of pre-decrement, so maybe the produced code would be no more efficient than I already have...

Code

var
  ar : array[1..10] of byte;
  pa, pb : pointer to byte;
  br : array[1..9] of byte;
  carry : boolean;

...
  pa := @ar[10];
  pb := @br[9];
  carry := FALSE;
  for i := 1 to 9 
    if carry then
      dec( pa^);
    endif;
    carry := pb^ > pa^;
    dec( pa^, pb^ );
    dec( pa );
    dec( pb );
  endfor;


Thanks for insight.

Regards

Merlin.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   64   78 · Page-Gen-Time: 0.043001s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI