Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Macro To Ge...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 18 Topic 9553 of 9775
Post > Topic >>

Re: Macro To Generate Inline Assembly

by Tony Delroy <tony_in_da_uk@[EMAIL PROTECTED] > Apr 28, 2008 at 02:13 AM

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! ]
 




 18 Posts in Topic:
Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-27 07:29:36 
Re: Macro To Generate Inline Assembly
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-27 12:39:09 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-27 12:39:05 
Re: Macro To Generate Inline Assembly
Tony Delroy <tony_in_d  2008-04-28 02:13:23 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-28 16:06:49 
Re: Macro To Generate Inline Assembly
Mathias Gaunard <loufo  2008-04-28 20:34:54 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-28 23:23:12 
Re: Macro To Generate Inline Assembly
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-29 10:35:49 
Re: Macro To Generate Inline Assembly
Francis Glassborow <fr  2008-04-29 10:43:23 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-29 17:38:48 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-29 17:42:22 
Re: Macro To Generate Inline Assembly
galathaea <galathaea@[  2008-04-29 18:29:42 
Re: Macro To Generate Inline Assembly
Carl Barron <cbarron41  2008-04-30 04:13:23 
Re: Macro To Generate Inline Assembly
Mathias Gaunard <loufo  2008-04-30 04:13:22 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-04-30 10:42:39 
Re: Macro To Generate Inline Assembly
John Nagle <nagle@[EMA  2008-05-03 06:13:27 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-05-03 16:10:43 
Re: Macro To Generate Inline Assembly
Le Chaud Lapin <jaibud  2008-05-03 16:13:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:33:49 CDT 2008.