I have used gdb to step through the assembler code that implement the standard C sin() function in the standard C math library (-lm -march=pentium3 -mfpmath=387). There is a lot of stub there and I don't know why they have not simply inlined the fsin assembler instruction. The same happens with other mathematic functions. Why they don't just call the corresponding FPU instruction?
Asked
Active
Viewed 1,203 times
0
-
1Did you compile with -O2 or -O3? – joeforker Sep 15 '09 at 18:06
-
Hi, in my MacBook I use: gcc sin.c -S -mfpmath=387 -mdynamic-no-pic gcc sin.s -g -o sin I tried -O2/-O3 but later on I have realized that the optimization options do not change the content of the system libraries. – Freeman Sep 19 '09 at 10:32
2 Answers
2
Because the "lot of stub there" is both faster and more accurate than the x87 fsin
instruction. Contrary to popular belief, library writers generally know what they're doing.

Stephen Canon
- 103,815
- 19
- 183
- 269
-
1+1 a link to augment your answer. In case it goes dead, the title of the thread is “x87 FSIN/FCOS mediocre accuracy”, and that pretty much sums up the discussion: http://software.intel.com/en-us/forums/showthread.php?t=74354 – Pascal Cuoq May 12 '12 at 20:18
-
Especially for large arguments, `fsin` results are mostly random numbers – Gunther Piez May 12 '12 at 20:50
-1
You should probably enable intrinsics - the intrinsic implementation of sinf is pretty much sure to be inlined (unless, say, someone takes an address of it, or some other unusual circumstances).
On VS that amounts to compiling with /Oi.

Ofek Shilon
- 14,734
- 5
- 67
- 101