[comp.lang.pascal] Sorting with 80x87

mglacy@lamar.ColoState.EDU (05/10/91)

Sender: 
Reply-To: mglacy@lamar.ColoState.EDU ()
Followup-To: 
Distribution: 
Organization: Colorado State University, Fort Collins, CO  80523
Keywords:  Sorting, 80287, 80387 

I revised a program to take advantage of my 80287 co-processor.
The program generates some 10,000 values of a random variable, then sorts
them and outputs a frequency distribution for the variable. I find
that, in the {$N+} mode, the program is only marginally faster in overall
exec. time.  Everything except the sort seems to run MUCH faster, but
the sort is now a real dog.  Sorting in {N+} mode is so slow that it negates 
the time saved elsewhere in the program.

I'm using a plain-vanilla Quick Sort, which in the {$N-} state sorted
the array[1..10000] of real in a couple of seconds; when I changed to
the {$N+} state (and changed all the reals to  extended),
the sort portion of the program was MUCH slower.

I'm using TP4.0, but writing essentially standard Pascal code.

1.  Why is the sort so slow?    I wouldn't think that sorting extended values,
even though they are 10 bytes long (vs. 6 bytes for ordinary software reals),
would make so much difference.

2.  Can anyone think of a way to get around this slowdown?

Thanks,

Mike Lacy

bb16@prism.gatech.EDU (Scott Bostater) (05/10/91)

In article <14826@ccncsu.ColoState.EDU> mglacy@lamar.ColoState.EDU writes:
>
>I revised a program to take advantage of my 80287 co-processor.
>The program generates some 10,000 values of a random variable, then sorts
>them and outputs a frequency distribution for the variable. I find
>that, in the {$N+} mode, the program is only marginally faster in overall
>exec. time.  Everything except the sort seems to run MUCH faster, but
>the sort is now a real dog.  Sorting in {N+} mode is so slow that it negates 
>the time saved elsewhere in the program.
>

Are you still using REAL as your data type?   If so, change to either SINGLE
or DOUBLE.  What happens when you use REAL with {$N+} is as follows:

    1)  convert 1st 6 byte real to 8 byte double
    2)  load 8087 with double
    3)  convert 2nd 6 byte real to 8 byte double
    4)  load 8087 with double
    5)  have 8087 to compare function
    6)  *If* swap necessary
        6.1) Pop 8 byte double off 8087
        6.2) convert 8 byte double to 6 byte real
        6.3) Pop 8 byte double off 8087
        6.4) convert 8 byte double to 6 byte real

Needless to say there's a whole lot of converting going on and slowing you down

If you want a quick test just put the following at the begining of your program
(for purposes of readability and maintainabiliy I don't recommend this as a
permanent fix!)

type
  Real = Double;

This will change all your REAL's to DOUBLEs and you should notice a signifigant
speed up.
-- 
Scott Bostater      Georgia Tech Research Institute - Radar Systems Analysis
"My soul finds rest in God alone; my salvation comes from Him"  -Ps 62.1
uucp:     ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!bb16
Internet: bb16@prism.gatech.edu