News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

What are the heristics of prgram efficiency in Assembly?

Started by Shintaro, March 21, 2022, 01:09:20 PM

Previous topic - Next topic

Shintaro

Hi,
I was reading somewhere, I don't remember where, I seem to be reading a lot lately, that certain instructions are more expensive on CPU cycles than others, on certain CPU's.
For example some instructions are expensive on say a 286, but not on 386 and vise-versa.
Is there a heuristic that people know or know of, for example try not to use memory to register instructions, try to use register to register instructions.

I suppose, at a basic level they are coding tips?
Regards,Craig
"Wyrd bið ful āræd. Fate is inexorable."

FORTRANS

Hi,

Quote from: Shintaro on March 21, 2022, 01:09:20 PM
Hi,
I was reading somewhere, I don't remember where, I seem to be reading a lot lately, that certain instructions are more expensive on CPU cycles than others, on certain CPU's.
For example some instructions are expensive on say a 286, but not on 386 and vise-versa.

   For a good discussion of 8088, 80286, 80386, and 80486 programming
efficiency, try Abrash's "Graphic Programming Black Book".  There is a down-
loadable PDF version out there somewhere.  Not directly comparing them,
but a good read anyway.

QuoteIs there a heuristic that people know or know of, for example try not to use memory to register instructions, try to use register to register instructions.

   That used to be a good rule to follow as memory access used to be quite
a bit slower than using registers.  However newer CPU's are less affected by
that.  You should time them on you own system to see what the differences
are, and if you want to worry about it.  jj2007 has posted many timing
programs that can be used as a starting point for you.  (Or any of the other
timing programs posted to the forum.)

Regards,

Steve N.

Gunther

Shintaro,

you can download the book by Michael Abrash here. Another source is here. Both sources are legal.
You have to know the facts before you can distort them.

Greenhorn

Agner is also a reference for timings and optimization ...
https://www.agner.org/optimize/
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Gunther

Greenhorn,

Quote from: Greenhorn on March 22, 2022, 05:41:02 AM
Agner is also a reference for timings and optimization ...
https://www.agner.org/optimize/

correct, but not everything is applicable under DOS. Moreover, the DOS program must first determine whether certain instruction sets are available.
You have to know the facts before you can distort them.

Shintaro

Thanks guys, the book by Abrash's "Graphic Programming Black Book", is really good.
I tried to find a hard copy, because I prefer reading from a book, but they wanted $186 USD. Ouch!

Quote from: Gunther on March 22, 2022, 12:39:27 PM
correct, but not everything is applicable under DOS. Moreover, the DOS program must first determine whether certain instruction sets are available.

That's interesting, because if I use instructions that are known to be efficient on one architecture, they may not be as efficient on another. But I would imagine the change up to a different architecture would include a jump in speed, so the loss of efficiency would be essentially hidden?

I would think the different code paths within the binary would make it larger, just for trying to make the code path efficient.|

That is why, I suppose, that only critical sections are optimised or the sections where the code is spending a lot of time.


"Wyrd bið ful āræd. Fate is inexorable."

Gunther

Shintaro,

Quote from: Shintaro on March 23, 2022, 11:11:36 AM
But I would imagine the change up to a different architecture would include a jump in speed, so the loss of efficiency would be essentially hidden?

yes, usually it does. But what I meant is this: A DOS program must definitely test if e.g. XMM registers can be used. YMM registers cannot be used under DOS without further action. Unless you have knowledge about
system programming and know what to do. How to do that you can read here and here.
You have to know the facts before you can distort them.