HP Forums

Full Version: Optimizing performance with loop unrolling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A few months ago, I bought a Surveying Pac for my 97. (Because I'm a sucker - I don't know anything about surveying that isn't in the HP 25 Applications Programs book!) One of the included cards was hand-labeled in pencil: "WEIGHTED AVE GRAVE - Will take 43 sets (ft)(oz) no more".

Yesterday I got my printer working, so I was curious to print out the listing from this card and see what was on it. It has some rather interesting loop-unrolling techniques. But I bet with some effort, I could optimize the program, and shorten it by at least a dozen steps. Wink

Program Listing
(05-04-2021 02:08 PM)Dave Britten Wrote: [ -> ]A few months ago, I bought a Surveying Pac for my 97. (Because I'm a sucker - I don't know anything about surveying that isn't in the HP 25 Applications Programs book!) One of the included cards was hand-labeled in pencil: "WEIGHTED AVE GRAVE - Will take 43 sets (ft)(oz) no more".

Yesterday I got my printer working, so I was curious to print out the listing from this card and see what was on it. It has some rather interesting loop-unrolling techniques. But I bet with some effort, I could optimize the program, and shorten it by at least a dozen steps. Wink

Program Listing

Doesn't unrolling a loop take more steps?
(05-04-2021 02:30 PM)toml_12953 Wrote: [ -> ]Doesn't unrolling a loop take more steps?

Yes, and this program looks like it was unrolled to the point where there's literally no loop left! It's a bit hard to read but it looks like the same five lines repeated over and over?
(05-04-2021 03:11 PM)Thomas Okken Wrote: [ -> ]
(05-04-2021 02:30 PM)toml_12953 Wrote: [ -> ]Doesn't unrolling a loop take more steps?

Yes, and this program looks like it was unrolled to the point where there's literally no loop left! It's a bit hard to read but it looks like the same five lines repeated over and over?

That was my immediate assessment of it too. It's basically the same 5 steps repeated for almost 220 steps, plus a LBL B to calculate the results. I found the "Will take 43 sets (ft)(oz) no more" note rather humorous, considering you could rewrite the whole program in about 20 steps and eliminate that limitation at the same time. Smile
The only advantage to unrolling a loop is saved time for looking up GTO targets but that can't amount to much here as the program is very short and constantly interrupted for user inputs anyway.
I wonder if someone took a program for say, a mini-computer, and slavishly copied it to the 41: optimizations that made sense on the original platform and all.
(05-04-2021 04:27 PM)Siegfried Wrote: [ -> ]The only advantage to unrolling a loop is saved time for looking up GTO targets but that can't amount to much here as the program is very short and constantly interrupted for user inputs anyway.

Yeah, that is the crux of the joke. Wink

Whoever wrote this program apparently knew just enough about HP 67 programming to have both LBL A and LBL B for two different functions, but didn't know that those 5 steps could be repeated indefinitely with a simple GTO.

I wonder if this person ever adapted the program for the greatly expanded memory of the 41!
The horror! The HORROR!!

I wonder how many data pairs one could write into Prime PPL program, using the same technique? Most likely, ones fingers would bleed before you ran out of program steps...
(05-04-2021 07:52 PM)rprosperi Wrote: [ -> ]The horror! The HORROR!!

I wonder how many data pairs one could write into Prime PPL program, using the same technique? Most likely, ones fingers would bleed before you ran out of program steps...

Well the beauty of it is you could just use repeated applications of copy/paste to double your code at each step! Work smarter, not harder!
Reference URL's