🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: csugrad.programming.c
Article #3

g++ and inlining asm code, possible?

#3
From: 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
Technical Details
Message-ID: <42m2qh$crs@csugrad.cs.vt.edu>
Path: arc1-ca.pugleaf.net!csugrad.cs.vt.edu!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!csugrad.cs.vt.edu!not-for-mail
From: cnelson@csugrad.cs.vt.edu (Christian Nelson)
Newsgroups: csugrad.programming.c,comp.lang.c++,rec.games.programmer
Subject: g++ and inlining asm code, possible?
Date: 7 Sep 1995 02:17:53 -0400
Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
Message-ID: <42m2qh$crs@csugrad.cs.vt.edu>
NNTP-Posting-Host: csugrad.cs.vt.edu