Compiler register limits.

Post Reply
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Compiler register limits.

Post by Robert »

The compiler complains that this code is too complicted, but I think it is relatively simple, and that the compiler should be able to handle it.

If you change the TYPE to POINTER TO REAL (also 64-bits) there is no problem.

Code: Select all

MODULE  PrivTest;

TYPE
  Vector*  =  POINTER  TO  ARRAY  OF  LONGINT;

PROCEDURE  Rotate* (vec : Vector; s : INTEGER) : Vector;
  VAR
    n, k  :  INTEGER;
    w     :  Vector;
  BEGIN
    IF  vec  #  NIL  THEN
      n  :=  LEN (vec); k  :=  n;
      NEW (w, n);
      WHILE  k  >  0  DO  DEC (k); w [(k + s) MOD n]  :=  vec [k]  END
    END;
    RETURN  w
  END  Rotate;

END  PrivTest.
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: Compiler register limits.

Post by Josef Templ »

This is probably because a LONGINT on a 32-bit CPU needs 2 Registers instead of 1.
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Compiler register limits.

Post by Robert »

An adequate work-around here is to replace the first line, which won't compile, with the second, which does.

But it still seems like a surprisingly severe restriction.

Code: Select all

      WHILE  k  >  0  DO  DEC (k); w [(k + s) MOD n]  :=  vec [k]  END
      WHILE  k  >  0  DO  DEC (k); w [k]  :=  vec [(k - s) MOD n]  END
Post Reply