🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: csugrad.programming.c
3 messages
3 total messages Started by Christian Nelson Thu, 07 Sep 1995 06:17
g++ and inlining asm code, possible?
#3
Author: Christian Nelson
Date: Thu, 07 Sep 1995 06:17
48 lines
2152 bytes
I'm currently writing a fixed point number class and I'm trying to
convince g++ (2.6.3 on a linux machine) to inline asm code for two of
the operators.  The operators in question are:

friend fixed operator * (const fixed a, const fixed b); 
friend fixed operator / (const fixed a, const fixed b);


It just doesn't seem to want to do it.  I explicitly made them
non-inlined, did some benchmarking, then tried numerous things to
force them to be inlined, including: optimizations, explicitly using
the 'inline' keyword, etc...  nothing helped.  I also wrote a function
based version of the same data type and it was at least 4-10 times
faster.  This is why I suspect that the asm code is not being inlined
for the class... and it is for the functional version.

The exact code for the * operator is as follows:

inline 
fixed operator * (const fixed A, const fixed B)
{
    fixed result;
    
    __asm__ ("imull %2\n\t"
             "shrd  $16, %%edx, %%eax\n\t"
             :"=a" (result.rep):"a" (A.rep), "d" (B.rep):"eax", "edx");
    
    return result;
}

NOTE1: rep is the data feidl which is actually a 32-bit long.
NOTE2: I've also put the code in the actual class declaration, and
       specified inline, but it didn't make any difference.  This
       declared-out-of-the-class form is this message only.


Can this actually be inlined??  How??  I'm getting frustrated because
I really don't want to give in to using functions instead of a nice
c++ class.  Also, where can I get more information on inlining asm
code in c++ classes?  I checked the man and info pages, and they were
far from informative (for c++ stuff).

If it'll help, I can put the actual code up for ftp...


Thanks...

-Christian
Re: g++ and inlining asm code, possible?
#4
Author: tran0119
Date: Fri, 08 Sep 1995 04:38
24 lines
1603 bytes
cnelson@csugrad.cs.vt.edu (Christian Nelson) writes:

>I'm currently writing a fixed point number class and I'm trying to
>convince g++ (2.6.3 on a linux machine) to inline asm code for two of
>the operators.  The operators in question are:

....
>It just doesn't seem to want to do it.  I explicitly made them
>non-inlined, did some benchmarking, then tried numerous things to
>force them to be inlined, including: optimizations, explicitly using
>the 'inline' keyword, etc...  nothing helped.  I also wrote a function
>based version of the same data type and it was at least 4-10 times
>faster.  This is why I suspect that the asm code is not being inlined
>for the class... and it is for the functional version.

...
>Can this actually be inlined??  How??  I'm getting frustrated because
>I really don't want to give in to using functions instead of a nice
>c++ class.  Also, where can I get more information on inlining asm
>code in c++ classes?  I checked the man and info pages, and they were
>far from informative (for c++ stuff).

   This ain't C++ stuff at all.  Try your function on a Sun and see if it's
going to work.  But I have a clue for you:  read the Linux hackers' guide.
Re: g++ and inlining asm code, possible?
#7
Author: Fabrizio Giudici
Date: Mon, 11 Sep 1995 12:40
25 lines
1751 bytes
Christian Nelson (cnelson@csugrad.cs.vt.edu) wrote:
: I'm currently writing a fixed point number class and I'm trying to
: convince g++ (2.6.3 on a linux machine) to inline asm code for two of
: the operators.  The operators in question are:

: friend fixed operator * (const fixed a, const fixed b); 
: friend fixed operator / (const fixed a, const fixed b);


: It just doesn't seem to want to do it.  I explicitly made them

Did you remember to disable debbugging info (i.e. to remove the -g switch)?
If I remember well, inlining is disabled with that switch...

Hope this helps...

--
.---------------------------------------------------------------------------.
| Fabrizio Giudici, PhD Student (fritz@dibe.unige.it) |                     |
|   WWW-PAGE: http://poseidon.dibe.unige.it/~fritz/   | Style distinguishes |
|          PHONE: +39 10  3532163 / 3532780           |   excellence from   |
|      Dept. of Biophys. and Elect. Eng. (DIBE)       |   accomplishment.   |
|     University of Genoa - ITALY, EUROPE, EARTH      |                     |
`---------------------------------------------------------------------------'
 All expressed opinions are personal and not of the organization I work for. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads