I was curious this morning to see if I could obtian and understand the machine instructions generated for calculating a mathematical function such as sin
, which as far as I am aware there is no machine instruction (in x86-64
) for computing.
I first went to Godbolt and tried to obtian the disassembly for this:
// Type your code here, or load an example.
#include <cmath>
int mysin(float num) {
float result = sin(num);
return result;
}
I found that the output sets up some registers for a function call and then does call sin
.
I then went and searched my local machine for the cmath
headers. I found one in /usr/include/c++/10/cmath.h
This header calls another function: __builtin_sin
.
My guess would be that the gcc compiler sees this identifier and substitutes it for some set of machine instructions which is somehow "baked into" the gcc compiler itself. Not sure if I am correct about that however.
I did a search of my system for the string __builtin_sinf
and it doesn't look like there is any text file on the system which contains source code (C, asm or otherwise) which might then be used by a compiler.
Can anyone offer any explaination as to what __builtin_sinf
is, where it is located if it exists in a file on my system, and finally how to obtain the disassembly of this function?