__builtin_sinf是什么?它在哪里?我如何获得它的解雇?

发布于 2025-02-04 21:54:20 字数 780 浏览 2 评论 0原文

今天早上,我很好奇,看看我是否可以使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似梦非梦 2025-02-11 21:54:20

如果您没有系统上的编译器的源代码,那么您可能没有__内置_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 a sin routine. It tells the compiler that the operation of the standard C library sin function is desired, with all the semantics of the sin function defined by the C standard. This means the compiler does not have to replace a use of __builtin_sin with a call to sin 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 of x during compilation, it can calculate sin(x) itself and replace __builtin_sin(x) with that value. Alternatively, the compiler can compile __builtin_sin(x) into assembly language that computes sin. Or it can compile __builtin_sin(x) into a call to the sin routine. It could also compile __builtin_sin(x) to a single machine instruction, such as fsin. (However, fsin is a primitive instruction with some limitations, particularly on argument domain, and is generally not suitable to serve as a sin 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 of sin 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 calculate sin. (This is called an intermediate representation.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文