The Museum of HP Calculators

HP Forum Archive 19

[ Return to Index | Top of Index ]

Loops of addition
Message #1 Posted by Palmer O. Hanson, Jr. on 15 June 2010, 10:10 p.m.

A loop of addition is inherent in a FOR-NEXT loop. A FOR-NEXT loop typically provides a substantial increase in the accumulated count relative to that provided by an A = A + 1 function in a GOTO loop. Some examples:

TI CC-40:

Count: 12,110 where the previously reported count for a GTO loop was 9,339

Code: 10 FOR I = 1 TO 99999 20 NEXT I

Sharp EL-5500III:

Count: 9,140 where the previously reported count for a GOTO loop was 2,056 where I was surprised by the 4.5 fold increase.

Code: 10 FOR I = 1 TO 9999 : 20 NEXT I

Substantial increases in the count are also realized with the TI graphic machines using the code :For(I,1,99999) :End

TI-80: Count: 3,080

TI-83+: Count: 19,020

TI-85: Count: 15,490

TI-86: Count: 12,690

Palmer

      
Re: Loops of addition
Message #2 Posted by Don Shepherd on 16 June 2010, 9:56 a.m.,
in response to message #1 by Palmer O. Hanson, Jr.

Palmer, I suspect Gene did not take that approach because all programmable calculators do not have looping instructions like FOR/NEXT or ISG/DSZ DSE, etc. He wanted some simple method of doing addition that could be used to compare lots of calculators. For example, the 12c has no looping instructions, but you can still loop manually.

My experience with the 33s, which does have looping instructions, is that using the looping instructions takes significantly longer than just controlling the loop manually. I did some benchmarks years ago and determined that.

            
Re: Loops of addition
Message #3 Posted by Palmer O. Hanson, Jr. on 16 June 2010, 10:40 p.m.,
in response to message #2 by Don Shepherd

Don:

The introduction to Gene's Article 1002 states in part:

Quote:
... Alternative methods that count one at a time are allowed and included, such as going through an ISG/DSE loop. ...
For an example, see the entry for HP30b with TSTSYS ON.

I agree with you that the methods which use looping instructions other than a simple GOTO tend to be slower. The FOR/NEXT loop seems to be the exception.

My recollection is that Maurice Swinnen did some of this back when the TI-88 came out as a way to show that it was faster than the TI-59, but I have't been able to find the material.

Palmer

Edited: 16 June 2010, 10:51 p.m.

                  
Re: Loops of addition
Message #4 Posted by Xerxes on 17 June 2010, 2:12 a.m.,
in response to message #3 by Palmer O. Hanson, Jr.

I've found some speed comparisons of the TI-88 vs. TI-59 here: http://www.ti59.com/V7N9.pdf
Thanks to Viktor Toth, the TI-88 is also present in the n-queens benchmark.

            
Re: Loops of addition
Message #5 Posted by Palmer O. Hanson, Jr. on 18 June 2010, 10:06 p.m.,
in response to message #2 by Don Shepherd

OOPS! The numbers reported herein are with the machines operating in the APPROXIMATE mode. When the mode is changed to EXACT the count for the TI-89 for the Lbla ... Goto a changes from 6,790 to 8.860 which is substantially closer to the previously published value. Furthermore, the For ... EndFor loop increases the count instead of decreasing it as with the APPROXIMATE mode. So, I'll have to generate a new set of data for the EXACT mode and (maybe) generate a new set of data for the AUTO mode as well.

Don:

Quote:
My experience with the 33s, which does have looping instructions, is that using the looping instructions takes significantly longer than just controlling the loop manually.
I did some work with my TI-89 which is in agreement with your idea that use of looping instructions takes longer. First, I did a :Lbl a :b + 1 > b :Goto a : EndPrgm loop and got 6,790 counts which is subtantially lower than the previously published value of 9,339. I could not make the Ans + 1 method work. A For...EndFor loop gave a reduced count of 4,685 per minute. That is consistent with your comment but is not consistent with results from other TI graphic machines. A Loop...EndLoop lop gave an increased count of 7,266 counts per minute. The details are:

TI-89 Platinum: Count: 6,790: Code :Prgm :Lbl a :b + 1 > b :Goto a :EndPrgm

TI-89 Platinum: Count: 4,685: Code :Prgm : For a,1,99999 :EndFor :EndPrgm

TI-89 Platinum: Count: 7,266: Code :Prgm :Loop :a + 1 a :EndLoop :EndPrgm

I did the same tests on my TI Voyage 200 with similar results but with with counts about 3 to 4 percent higher:

TI Voyage 200: Count: 7,000: Code :Prgm :Lbl a :b + 1 > b :Goto a :EndPrgm

TI Voyage 200: Count: 4,860: Code :Prgm : For a,1,99999 :EndFor :EndPrgm

TI Voyage 200: Count: 7,546: Code :Prgm :Loop :a + 1 a :EndLoop :EndPrgm

Palmer

Edited: 18 June 2010, 11:52 p.m.

                  
Re: Loops of addition
Message #6 Posted by Don Shepherd on 19 June 2010, 3:15 a.m.,
in response to message #5 by Palmer O. Hanson, Jr.

Palmer, it is interesting that using the looping instructions sometimes takes longer than just controlling the loop index yourself on some machines; I put a yellow post-it note in my 33s manual years ago to NEVER use ISG/DSE. But it really does depend upon the individual machine. I did a benchmark on the new 30b, and on that machine it is much faster to use the looping instructions than to do it manually.

I guess it depends upon how efficiently these instructions were implemented by the OS programmer. Obviously, Tim and Cyrille did a good job on the 30b. But Katie pointed out another area in which the 30b is not nearly as efficient as, for example, the 42s and others. I believe she said that the 42s caches the physical address of each label (object of a Goto or Call), so subsequent executions do not have to search for the location to goto. The 30b does not do this, and some programs take much longer to run because of this. We created an optimized version of the prime factor program in which the most commonly used labels are located at the beginning of memory, and did some benchmarks comparing this version with the non-optimized version, and the results were striking. Let's hope that, if the 30b ROM is ever updated, this is fixed. Of course, one could argue that the 30b is not primarily a programming machine...

Don

                        
Re: Loops of addition
Message #7 Posted by Palmer O. Hanson, Jr. on 21 June 2010, 3:08 a.m.,
in response to message #6 by Don Shepherd

Don:

Quote:
I put a yellow post-it note in my 33s manual years ago to NEVER use ISG/DSE.
I admit that the ISG and DSE functions are not "speedy" when it comes to counting. But, that is not all that they do, and more importantly, they do what they do without messing with the stack.

Palmer

                              
Re: Loops of addition
Message #8 Posted by Don Shepherd on 21 June 2010, 5:26 a.m.,
in response to message #7 by Palmer O. Hanson, Jr.

True, but I value speed over stack (and number of instructions, usually). And, in almost every loop I've ever done, I want the loop index in X when I begin the loop during each iteration, so to loop from 1 to 30, for example, at the end of the loop I would do this on the 33s:

1
STO + 1
30
RCL 1
X<=Y
GOTO A01

In the benchmarks I did on the 33s, this code runs faster than ISG 1.

On the 30b, there is no X<=Y, there is ?<= (which is really Y<=X), which would require a GF 1, or ?> (which is really Y>X) with GT 1, to maintain the desired loop index in X. The ISG on the 30b is much more efficient than the ISG on the 33s, however.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall