7

Is there a drop-in replacement to glibc's libm (and headers?) for x86_64-linux that is faster?

  • To what extent are you willing to sacrifice accuracy for speed? – Mark Dickinson Mar 08 '10 at 17:35
  • I don't know your requirements but have you checked TNT, Blitz++, Boost, etc? – amit kumar Mar 08 '10 at 17:35
  • I already have some optimized (and inlined!) versions of erf(), exp() and sincos(). But the goal would be to have all (or most) of them in a drop-in replacement, and not to worry about it... Especially some using nice SSE2 instructions, which could be *way* faster... –  Mar 08 '10 at 17:36
  • 3
    I might be mistaken, but afaik, gcc will use SSE2 by default on x86-64; perhaps all you're missing is the right optimization flags - try `-ffast-math` or look for specifics in the manual, especially http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Optimize-Options.html#Optimize-Options and http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options – Christoph Mar 08 '10 at 18:02
  • Even if GCC generates SSE2 code, it will still call libm's functions, which are not SSE2-optimized. –  Mar 08 '10 at 18:05
  • @www: well, `-ffast-math` sets `-fno-math-errno`, which directly affects the math functions' implementation; if all gcc did was stupidly link against them, the option would be pretty useless, but I'm not on a 64bit (or even *nix) machine, ie I can't look at the generated code to see what and how gcc interacts with libm – Christoph Mar 08 '10 at 18:08
  • You really need to be more specific - single/double precision ? which functions ? how much accuracy do you need ? how much faster do you need these functions to be ? – Paul R Mar 08 '10 at 18:51
  • I don't see how being more specific would help, as apparently there are no good suggestions anyway :( –  Mar 10 '10 at 11:14
  • @wwww: You asked for a faster replacement for the glibc libm. I named one for you. What more do you want? – Stephen Canon Mar 15 '10 at 16:47

3 Answers3

2

The math library distributed with ICC is substantially faster for many of the libm functions, but does require purchasing ICC. I believe you can download a free trial version if you're curious about it. I know that they support Linux, and believe that they try to be drop-in compatible with the GCC library. ICC also includes vectorized implementations of many of the libm functions in the Math Kernel Library, which may be useful to you.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
1

Both AMD and Intel have heavily optimized math libraries available for their CPUs. They are not free.

They don't implement simple stuff. These libraries are for fast Fourier transforms, huge matrix problems and other things.

The fast-math compiler option will speed up floating point math a lot. However, you will be responsible for your own error checking.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
-1

Depending on what exact math functions you are wanting to run and how large of a data set you will be running them on, you may want to take a look at something like CUDA which will let you use the speedy mathematical capabilities of your graphics chip to do your processing.

bta
  • 43,959
  • 6
  • 69
  • 99