__builtin_sinf是什么?它在哪里?我如何获得它的解雇?
今天早上,我很好奇,看看我是否可以使用sin
等用于计算数学功能的机器说明,据我所知,没有机器指令(in
in
x86-64
)用于计算。
我首先去了Godbolt,并试图为此进行拆卸:
// Type your code here, or load an example.
#include <cmath>
int mysin(float num) {
float result = sin(num);
return result;
}
我发现输出为函数调用设置了一些寄存器,然后进行call call sin
。
然后,我去了我的本地计算机以查找cmath
标题。我在/usr/include/c ++/10/cmath.h
中找到了一个标题
,该标头调用另一个函数:__ bentain_sin_sin
。
我的猜测是GCC编译器看到此标识符并将其替换为某些机器指令,这些机器指令以某种方式“烘烤”到GCC编译器本身。不知道我是否对此有正确的态度。
我对系统进行了搜索字符串__内置
,看起来系统上没有任何文本文件,其中包含源代码(C,ASM或其他),然后可以通过编译器。
谁能提供有关__内置
的任何解释,如果它存在于我的系统上的文件中,以及最后如何获得此功能的拆卸?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有系统上的编译器的源代码,那么您可能没有
__内置_sin
的源代码,因为在_________edin_sin_sin
中构建了什么。编译器。__内置
不是编译器的指令,将其替换为sin
例程的调用。它告诉编译器,需要标准C库的操作sin
函数,其中所有sin
函数的语义由C标准定义。这意味着编译器不必用
本身并用该值替换sin
的呼叫或对任何其他功能的调用来替换_____en_sin
的使用。它可以用任何适当的代码替换。例如,给定一些__内置_sin(x)
,如果编译器可以在编译过程中确定x
的值,则可以计算sin(x)
__ benterin_sin(x)
。另外,编译器可以编译__内置in_sin(x)
纳入计算sin
的汇编语言。否则它可以将______SIN(x)
编译成sin
例程的调用。它还可以将_______SIN(x)
编译到单个机器指令,例如fsin
。 (但是,fsin
是一种具有某些限制的原始指令,尤其是在参数域上,通常不适合用作sin
函数。)因此没有除编译器的源代码外,包含
__endin_sin
的实现的源文件。而且,尽管该源代码可能包含有关编译器使用的sin
内联实现的信息,但该信息可能不以目标处理器的汇编语言形式;它可能是内部编译器语言的形式,指定要执行的操作来计算sin
。 (这称为 InterMediate表示。If you do not have the source code for the compiler on your system, then you probably do not have the source code for
__builtin_sin
because what to do for__builtin_sin
is built into the compiler.__builtin_sin
is not an instruction to the compiler to replace it with a call to asin
routine. It tells the compiler that the operation of the standard C librarysin
function is desired, with all the semantics of thesin
function defined by the C standard. This means the compiler does not have to replace a use of__builtin_sin
with a call tosin
or a call to any other function. It may replace it with whatever code is appropriate. For example, given some__builtin_sin(x)
, if the compiler can determine the value ofx
during compilation, it can calculatesin(x)
itself and replace__builtin_sin(x)
with that value. Alternatively, the compiler can compile__builtin_sin(x)
into assembly language that computessin
. Or it can compile__builtin_sin(x)
into a call to thesin
routine. It could also compile__builtin_sin(x)
to a single machine instruction, such asfsin
. (However,fsin
is a primitive instruction with some limitations, particularly on argument domain, and is generally not suitable to serve as asin
function by itself.)So there is no source file that contains the implementation of
__builtin_sin
other than the compiler’s source code. And, while that source code might contain information about an inline implementation ofsin
that the compiler uses, that information might not be in the form of assembly language for your target processor; it might be in the form of an internal compiler language specifying what operations to perform to calculatesin
. (This is called an intermediate representation.)