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 18 of 18 Topic 9553 of 9823
Post > Topic >>

Re: Macro To Generate Inline Assembly

by Le Chaud Lapin <jaibuduvin@[EMAIL PROTECTED] > May 3, 2008 at 04:13 PM

On May 3, 7:13 am, John Nagle <na...@[EMAIL PROTECTED]
> wrote:
> Mathias Gaunard wrote:
> > On 30 avr, 01:38, Le Chaud Lapin <jaibudu...@[EMAIL PROTECTED]
> wrote:
>
> >> With macros, I don't have to worry about return value, or reference
> >> indirection elimination, or prolog/epilog code that I might have to
> >> struggle to get rid of. I simply use one line of code for say,
> >> MULTIPLY, and be done with it:
>
>     Of course, you're assuming that the compiler puts the arguments
> in a standard place.  This may inhibit optimizations.

Well, technically, I do not assume anything. :) That's the point. With
the inline function method, I have to consider the possibility that
the compiler might add code before and after the inline assembly
inside the inline function.  With the macro method, I am certain that
it will not.

>     Really, unless you need to emit some instruction you can't
> express at all in C/C++, it's no longer useful to use inline assembly
code.

In this case, there is.

I have never read Knuth 4.3.1 division algorithm, but rumor has it
that he prescribes that programmers implementing a big integer class
have access two double machine-word operations. So for example, if
unsigned int is 32-bits, then...

unsigned int A = (1 << 16); // 65,536
unsigned int B = (1 << 16); // 65,536
unsigned int P = A * B; // 2 ^ 32, will not fit in 32-bit word

That sole high-order bit at position 32 of P cannot be easily captured
in straight C/C++.  Imagine trying to get at it in C++ with some
degree of efficiency compared to assembly. The difference in
performance will be dramatic.

Certainly, there is trickery to get at it, as I did to get my member
functions simply working for my big integer class.  But due to poor
choice of algorithm, and lack of the optimization, the new, optimized
implementation, soon to be completed, will be 658 times faster than
the old implementation.  I do not know how much of the 658 can be
attributed to trying to do in C/C++ what should have been done in
assembly, but my guess is that it's at least 2.5.

-Le Chaud Lapin-


-- 
      [ 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 Thu Jul 24 1:45:22 CDT 2008.