🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.soft-sys.matlab
Article #203

Re: g++: Shared library, mapfiles, execution speed

#203
From: Bart Smaalders
Date: Sun, 16 Mar 2003 20:33
82 lines
4567 bytes
Typically, the performance overheads associated with PIC
code will manifest itself in the following areas (on SPARC):

1) The increased number of instructions can be seen
   in very simple programs that fit in I & D caches
   since E$ and memory latencies don't hide anything.

2) Very simple leaf routines that access global data will
   now require a register window as a result of how they
   find the GOT (global offset table).  This can increase
   register window spill fill traps in some cases; typically
   seen with C++ "data hiding" functions that insist on
   using global flags to control their behavior. If the data
   objects being used are large, including a pointer to a structure
   containing important global state can significantly improve
   performance of trivial functions.  In C:

   Rather than

   int
   get_count(myobj_t * foo)
   {
         if (debug_flag) {
                 ...
         }
         return (foo->count);
   }   


   add a pointer to myobj_t to point to global state and get

   int
   get_count(myobj_t * foo)
   {
         if (foo->global_data->debug_flag) {
                 ...
         }
         return (foo->count);
   }   

   Where possible, one can of course inline the accessor functions,
   but this eliminates some of the advantages of using them in the
   first place.

3) In PIC code, all calls to non-local functions must be done
   through a PLT (procedure linkage table), as the address of
   the target function is not known at compile time.  These PLT entries
   initially point into the dynamic linker, and are then resolved
   the first time they're called and the code in the PLT is updated
   to call the function directly.  However, calling global functions
   outside the shared library will always involve 2 function calls,
   so we end up w/ a few more cycles _and_ more itlb pressure.
   Note that we can optimize the number of global symbols by scoping
   the library so that only externally used symbols remain global
   (see Linker and Library Manual at http://docs.sun.com).  If you're
   not interposing on symbols in the library, the library may also be
   linked w/ -Bsymbolic, although this can cause problems w/ some C++
   environments (sigh)).


In most cases, these effects are not significant. Sometimes, however,
they can cause a lot of head scratching.

- Bart 

Fred Ma <fma@doe.carleton.ca> wrote in message 
> 
> Yes, I was thinking of PIC and shared libraries as synonymous,
> even though I am told that they are not.  I'm not too interested in
> their differences, I was just curious about whether my code will
> run any slower when compiled via the mex way, but I'll find out
> once I've finished recoding (getting familiar with passing/returning
> structs and extracting parameters, changing all references to
> cout and cerr to use matlab printing functions, changing all
> exit(EXIT_FAILURES) to throws that are caught by my toplevel
> function, etc..).  I was hoping to get an idea of whether the interfacing
> was all worth it, since my matlab modules only do graphing to
> monitor progress, and digesting results returned by many runs of
> my C++ number cruncher.  Responses in the other newsgroups
> seem to indicate that PIC doesn't adversely affect speed.
> 
> Fred
Technical Details
Message-ID: <5bd8e3f5.0303161233.20d25923@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <3E70F170.B4EE8B07@doe.carleton.ca> <3E71FA77.7050803@mathworks.com> <3E72008C.278477DD@doe.carleton.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e2dd6c17ce56ca38
X-Google-Attributes: gid11318c,public
X-Google-Thread: 106e3f,e2dd6c17ce56ca38
X-Google-Attributes: gid106e3f,public
X-Google-Thread: fc89c,e2dd6c17ce56ca38
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 11035d,e2dd6c17ce56ca38
X-Google-Attributes: gid11035d,public
X-Google-ArrivalTime: 2003-03-16 12:33:23 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: barts@smaalders.net (Bart Smaalders)
Newsgroups: comp.soft-sys.matlab,gnu.gcc.help,comp.unix.programmer,comp.unix.solaris
Subject: Re: g++: Shared library, mapfiles, execution speed
Date: 16 Mar 2003 12:33:23 -0800
Organization: http://groups.google.com/
Lines: 82
Message-ID: <5bd8e3f5.0303161233.20d25923@posting.google.com>
References: <3E70F170.B4EE8B07@doe.carleton.ca> <3E71FA77.7050803@mathworks.com> <3E72008C.278477DD@doe.carleton.ca>
NNTP-Posting-Host: 216.103.214.41
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1047846803 1202 127.0.0.1 (16 Mar 2003 20:33:23 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 16 Mar 2003 20:33:23 GMT