% From: Yuval Yarom <mmixmasters@qw...>
% Program T from Section 2.3.1  
% 2002-06-28 02:24

Hi,

Here are three possible versions of program T from section 2.3.1. 

The first version is a pretty streightforward translation of the
original program into MMIX.  The main difference is that the stack
pointer points to the first available stack entry, and not to the last
used entry.  Its running time is 4n+1 mems, and 14n+a+1 oops.

The second version is similar to the first, but the stack grows
downwards.  This reduces the running time to 4n+1 mems, and 13n+2a+1
oops. 

The third version avoids memory access by using the register stack
instead of implementing astack in the memory.  This reduces the running
time to 2n+1 mems, and 15n+9 oops.

I would appreciate your comments on these.  In particular I am wondering
if anyone thinks version 3 is suitable for inclusion in the book - I am
sure that the register stack was not designed for the purpose I use it
there, but after all, this is the most efficient version.

Thanks
Yuval

-----------------------------------------------------------------------

From: Steve Chapel <stevechapel@ea...>
RE: Program T from Section 2.3.1  
2002-06-28 22:36

I like the first version best because it"s the easiest for me to figure 
out after not seeing MMIX code for three years. It also most closely 
resembles the original MIX code. I think clearer code should be 
preferred over faster code.

Two comments:

1. Why is t $255 instead of $4?

2. The line "NEG s,0,0" was particularly confusing for me, both because 
of the strange way of setting s to 0, and because there"s no comment. 
How about substituting the line:
         SET     s,0             1       Set stack A empty
I know there"s no comment for the corresponding MIX line in the book, 
but I don"t see any reason why not.

			




-----------------------------------------------------------------------

From: Yuval Yarom <mmixmasters@qw...>
RE: Program T from Section 2.3.1  
2002-07-01 19:58

Thanks for the comments.

My preference is for the second version.  I do not find any difference
in the difficulty of the first two versions, and in such a case I would
prefer the faster.  

register $255 is used for temporary storage.  It would be a pity to
allocate a local register just for the CMP result.  Compare also wit
progarm G in section 1.3.2 (page 33).

Thanks for spotting the NEG s,0,0 command.  I will change it to SET
s,0.  It has been 3 years since I last programmed on the MMIX, and it
will take some time to become proficient with it.

Yuval