dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (08/15/89)
I've recently spent a few hours writing assembly language routines to
speed up a TP5 program, and found that most of the time was being wasted
calculating array references in loops like
for i:=1 to 100 do
sum := sum + array[i];
My assembly language version used the 8086 string instructions to go
much faster.
I'd much prefer to have done the optimization in Pascal, as the program
would be easier to maintain, but TP offers no easy access to fast string-like
operations. Something close to what I had in mind might have been
ptr := addr(array[1]);
for i:=1 to 100 do
begin
inc(sum,ptr^);
inc(longint(ptr),sizeof(arrayelement));
end;
but dereferencing 32 bit pointers is really slow. Wouldn't it be nice if
there was a short pointer type, that always referenced the ES segment?
Then I could write
short_seg := seg(array[1]);
short_ptr := ofs(array[1]);
for i:=1 to 100 do
begin
inc(sum,short_ptr^);
inc(word(short_ptr),sizeof(arrayelement));
end;
or even
...
for word(short_ptr) := ofs(array[1]) to ofs(array[100]) do
inc(sum,short_ptr^);
if it was an array of bytes.
Implementing this would require that routines preserve ES, but that wouldn't
be too onerous, I don't think. It would even allow backwards compatibility
if the library didn't assume that the user preserved ES.
What do people think?
Duncan Murdoch