Subject: Re: why no shared math library?
To: Charles Hannum <mycroft@duality.gnu.ai.mit.edu>
From: Thomas Eberhardt <thomas@mathematik.uni-Bremen.de>
List: current-users
Date: 11/22/1993 03:01:30
> 
> 
>    Is there any particular reason why libm.a isn't compiled and
>    installed as a shared library?
> 
> Applications tend to use only a subset of libm.  It's not very big.
> It doesn't really change.  Making it a shared library would slow down
> numeric applications significantly.
> 

Here some data points:

#include <math.h>

main ()
{
  double x, y, t, t1, t2;
  int i;

  t = 0.499975;
  t1 = 0.50025;
  t2 = 2.0;

  x = y = 0.5;
  for (i = 0; i < 30000; i++)
    {
      x = t * atan (t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
      y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
    }

  x = 0.75;
  for (i = 0; i < 30000; i++)
    x = sqrt(exp(log(x)/t1));
}

cc -o x-dyn x.c -lm	# i've installed a shared math library on my system.
cc -o x-stat x.c /usr/lib/libm.a

time ./x-stat
9.400u 0.060s 0:09.42 100.4% 0+0k 0+2io 0pf+0w
9.420u 0.070s 0:09.44 100.5% 0+0k 0+2io 0pf+0w
9.400u 0.070s 0:09.42 100.5% 0+0k 0+2io 0pf+0w

time ./x-dyn
9.730u 0.050s 0:09.77 100.1% 0+0k 1+2io 0pf+0w
9.700u 0.060s 0:09.72 100.4% 0+0k 0+2io 0pf+0w
9.710u 0.040s 0:09.72 100.3% 0+0k 0+2io 0pf+0w

This gives a 3.26% performance penalty. Not that significant I would say.
And if one wants real fp performance the way to go would be inline
code.

I brought up this point since I'm currently playing around with Khoros on
my system.  I've compiled everything with shared libraries (the whole
bin & lib dirs are just 10MB total).  When I use a static math library
the whole library is brought into every binary since the shared
khoros libraries reference all functions from it.  This is a 30KB difference
per file (i.e. 30KB * 273 = 8190KB).


>    And perhaps also librpsvc.a?
> 
> I don't see what it would gain you, but I also don't see any
> particular reason not to.

Just because it's the only other C library that not shared (-ll and -ly don't
count).

-- 
thomas@mathematik.uni-Bremen.de | Centrum für Complexe Systeme & Visualisierung
Thomas Eberhardt                | Universität Bremen, FB 3, Bibliothekstr. 1
Kölner Str. 4, D-28327 Bremen   | D-28359 Bremen, Germany
Home Phone: +49 421 472527      | FAX: +49 421 218-4236, Office: 218-4823

------------------------------------------------------------------------------