HP Forums
HP-71 Reals Faster Than Integers - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HP-71 Reals Faster Than Integers (/thread-21978.html)



HP-71 Reals Faster Than Integers - toml_12953 - 07-01-2024 09:50 AM

On some computers, using integers not only saves space but calculations are done faster. On the HP-71B, integers do save space but are slower than reals. In the N-Queens program (below) I commented out lines 10 and 30 and the runtime dropped from 2:57 to 2:35

Code:
5 T0=TIME 
10 INTEGER R,X,S,Y,T
20 R=8                   
30 INTEGER A(R)
40 IF X=R THEN 180
50 X=X+1
60 A(X)=R
70 S=S+1
80 Y=X
90 Y=Y-1
100 IF Y=0 THEN 40
110 T=A(X)-A(Y)
120 IF T=0 THEN 140
130 IF X-Y<>ABS(T) THEN 90
140 A(X)=A(X)-1
150 IF A(X) THEN 70
160 X=X-1
170 IF X THEN 140
180 PRINT S
190 T0=TIME-T0
200 PRINT USING "'RUNTIME: ',ZZ,':',ZZ.DD";T0 DIV 60,MOD(T0,60)
210 END



RE: HP-71 Reals Faster Than Integers - RPNerd - 07-01-2024 10:21 AM

This could have something to do with the fact that the registers of the Saturn CPU are optimised for the storage and manipulation of floating point numbers.


RE: HP-71 Reals Faster Than Integers - brouhaha - 07-03-2024 03:46 AM

I haven't checked, but it's possible that all the calculations are done in floating point, and then converted to integers for storage. Float to int could perhaps be a bit slow, though int to float should be fast. But still, it's extra conversions.

The Saturn processor architecture is definitely designed to perform _reasonably_ efficient floating point, but nevertheless, it can perform arithmetic on binary integers of up to 64 bits MUCH faster than floating point. It can do a 64-bit integer (either bniary or BCD) addition or subtraction in about 30 microseconds in the 71B I haven't timed it, but floating point calculations take hundreds of instructions, so probably at least 100x slow than the 64-bit integer operatinos.

That's the raw processor capability, which is why I think the user-level slowness with integers is a result of software architecture decisions, not that the CPU is faster at floating point, since it clearly isn't.


RE: HP-71 Reals Faster Than Integers - Paul Dale - 07-03-2024 04:49 AM

I agree, my immediate suspicion was that computations were being done in floating point regardless.

The Saturn is actually pretty good with integers up to 64 bits in length.
They are much faster than floating point equivalents despite the apparent optimisations for floating point arithmetic.


RE: HP-71 Reals Faster Than Integers - J-F Garnier - 07-03-2024 07:24 AM

(07-03-2024 03:46 AM)brouhaha Wrote:  I haven't checked, but it's possible that all the calculations are done in floating point, and then converted to integers for storage. Float to int could perhaps be a bit slow, though int to float should be fast. But still, it's extra conversions.

Yes, that's exactly the reason. All calculations on the HP-71 internal "Math Stack" (in RPN form) are done on floating point numbers.

The HP-75, as I indicated several times, has a clever "fast integer processing" feature.
When a REAL-type variable holds a integer value, then the calculations are done by integer routines, about 2x faster.
Still, even on the HP-75, INTEGER- and SHORT-type variables are slower and must be used only to save RAM or disc space.

J-F