How is sin() implemented in eglibc-2.13?
c, glibc, libc, linux, math
Solution
The (e)glibc build process is black, black magic. You do not want to try to comprehend it. However, glibc adheres to a one-file-per-public-function coding style, so in general, if you have the source tree and you want to find the implementation(s) of some function, the easiest thing to do is
$ find * -name '*function*' -print
from the top level, replacing `function` with the name of the function, of course.
Talking specifically about `sin`: the generic implementations of the math functions are in the `math` directory: however, it appears that there is no generic definition of `sin`. So the next place to look is `sysdeps`. Everything that isn't generic is in `sysdeps`, and in particular, `sysdeps/ieee754` is where all the math functions that have some dependence on the IEEE 754 floating point specification, but no other system dependencies, live. This directory is organized by type: `sysdeps/ieee754/dbl-64` contains all the math functions for IEEE `double`. And here you will find `sysdeps/ieee754/dbl-64/s_sin.c`, which is the code you are looking for. (The `e_`, `s_`, `k_`, etc prefixes on all these files used to mean something but AFAIK no longer do.)
If there were an implementation of `sin` in assembly language for a particular processor, it would be in a file named `sin.S` (or possibly `s_sin.S`) somewhere else in `sysdeps`. It does not appear that there is one, though.
Problem
I need to track down how exactly is `double sin(double x)` implemented in eglibc-2.13. I downloaded the source code and the only part that made sense was __sin function, that was platform-specific. Is it the heart of what I have in /usr/lib/i386-linux-gnu/libm.a? How to track down the macrodefinitions that lead from sin() to __sin()? What I really need is the exact code (filename and the line is enough) and a way in which the build process deduces which implementation to use. The architecture's i386.