On Apr 27, 10:29 pm, Le Chaud Lapin <jaibudu...@[EMAIL PROTECTED]
> wrote:
> "Premature optimization is the root of all evil."
> So I waited until my (big) Integer class was sufficiently mature
> before optimizing it.
That may still be premature. Profiling should generally be the
trigger for optimising, though of course if your responsibility ends
at delivering a "big int" library, it's reasonable to go that bit
further and benchmark alternative implementations before waiting for
customer complaints....
> Currently, ADD, SUBTRACT, MULTIPLY, AND DIVIDE are written in C++. I
> would like to replace the C++ code with inline assembly, using a macro
> to generate the inline assembly to facilitate sup****t for as many
> CPU's as possible [Yes, I know some compilers do not sup****t inline
> assembly for some CPU's].
Not unreasonable to give it a try, but do note that the hand-written
assembly will not necessarily be faster: the compiler tracks register
usage and has more freedom without your telling it which registers it
must use. Further, when the multiplier happens to be a constant, the
compiler may look at it special case certain values like -1, 0, 1 and
powers of 2 with other operations that are faster. The only time when
it's normally necessary to use assembly is when there are some fancy
operations on your CPU that you want to use, and you know the compiler
didn't generate for you. For example, possibly MMX instructions,
atomic operations, memory barriers.
> Naturally, I would like to understand not just how to do this for
> VS2005, but for all systems/compilers, so that I am not left guessing
> whether I got it right or not.
Compilers will differ, but even more im****tantly assembly languages
will differ. Without your listing target systems/compilers, it's
impractical to offer suggestions. Anyway, it's not a C++ question per
se... so probably belongs on another newgroup (or set thereof).
Tony
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|