help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] How To Reduce Size of GNU Included Routines


From: Bob Smith
Subject: Re: [Help-gsl] How To Reduce Size of GNU Included Routines
Date: Thu, 14 Jun 2007 16:33:45 -0500
User-agent: Thunderbird 2.0.0.0 (Windows/20070326)

On 6/13/2007 1:56 PM, Kees Zeelenberg wrote:
The linker automatically links only the modules that are actually needed in the executable. So in this respect the executable is always of the smallest size possible. You might be able to reduce its size further by stripping the executable from its debug symbols etc. by using the Wl,-s option at the linking stage.

That's fine for minimizing the number of included modules, but what I am looking for is not including any routines which use (say) "complex long double" because I don't use that datatype. For example, the source file vector\vector.c compiles routines for all of the fifteen available datatypes, whereas I want just those pertaining to one.

After some research into the source, it appears that I need to surround with #ifdef/#endif the routines of a specific datatype so as to avoid compiling them in the first place.
======================
After much typing, I've accomplished this and the resulting libgsl.a (which I renamed to libgsl-double.a) and libgslcblas.a (renamed to libgslcblas-double.a) has the routines for just the datatype I want. This reduced the size of the executable by 262 KB.

I realize that few people are interested in this form of minimization, but on the unlikely chance anyone is, I'd be happy to make these changes available.

For reference, the technique I used is as follows:

1.  Moved up to GSL 1.9.

2.  New file:  <datatypes.h> with contents:

#ifndef DATATYPES_H_SEEN
#define DATATYPES_H_SEEN

#ifdef WANT_DATATYPE_ALL
#define WANT_DATATYPE_COMPLEX_LONG_DOUBLE
#define WANT_DATATYPE_COMPLEX_DOUBLE
#define WANT_DATATYPE_COMPLEX_FLOAT
#define WANT_DATATYPE_COMPLEX
#define WANT_DATATYPE_LONG_DOUBLE
#define WANT_DATATYPE_DOUBLE
#define WANT_DATATYPE_FLOAT
#define WANT_DATATYPE_ULONG
#define WANT_DATATYPE_LONG
#define WANT_DATATYPE_UINT
#define WANT_DATATYPE_INT
#define WANT_DATATYPE_USHORT
#define WANT_DATATYPE_SHORT
#define WANT_DATATYPE_UCHAR
#define WANT_DATATYPE_CHAR
#else
// Confirm that at least one of the above types is defined
...
#endif

// Avoid #include'ing if not defined
#ifndef WANT_DATATYPE_COMPLEX_LONG_DOUBLE
#define __GSL_MATRIX_COMPLEX_LONG_DOUBLE_H__
#define __GSL_VECTOR_COMPLEX_LONG_DOUBLE_H__
#define __GSL_PERMUTE_COMPLEX_LONG_DOUBLE_H__
#define __GSL_PERMUTE_VECTOR_COMPLEX_LONG_DOUBLE_H__
#define __GSL_BLOCK_COMPLEX_LONG_DOUBLE_H__
/////// __GSL_SORT_COMPLEX_LONG_DOUBLE_H__          // Doesn't exist
/////// __GSL_SORT_VECTOR_COMPLEX_LONG_DOUBLE_H__   // Doesn't exist
#endif

etc. with a similar section for each additional datatype:

"complex double", "complex float", "complex", "long double", "double", "float", "ulong", "long", "uint", "int", "ushort", "short", "uchar", and "char".

The above sections helped me determine what code was dependent on each specific datatype.

3. The above file is #included in <config.h> preceded by one or more lines declaring the datatypes in which you are interested. For example, I'm interested in "double" only, so I use

#define WANT_DATATYPE_DOUBLE
#include "datatypes.h"

I realize that <config.h> is a generated file, but I didn't want to tackle <configure.*> to figure out how to include it via that mechanism.

4.  I changed a number of source files to surround appropriate code with

#ifdef WANT_DATATYPE_xxx
...
#endif

For example, the file block\init.c now starts with

#ifdef WANT_DATATYPE_COMPLEX_LONG
#define BASE_GSL_COMPLEX_LONG
#include "templates_on.h"
#include "init_source.c"
#include "templates_off.h"
#undef  BASE_GSL_COMPLEX_LONG
#endif

#ifdef WANT_DATATYPE_COMPLEX
#define BASE_GSL_COMPLEX
#include "templates_on.h"
#include "init_source.c"
#include "templates_off.h"
#undef  BASE_GSL_COMPLEX
#endif

...

Other source files (70 or so) were changed to surround the appropriate code with #ifdef WANT_DATATYPE_xxx/#endif. Files in the directories, "block", "vector", "matrix", "permutation", "sort", "blas", "cblas", "linalg", "eigen", "specfunc", "complex", and "statistics" are affected.

I want to emphasize that no code was changed; the above modifications consist solely of inserting #ifdef/#endif pairs around the appropriate parts.
--
_______________________________________________________________
Bob Smith - address@hidden - http://www.sudleyplace.com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]