在汇编器中实现 math.h 函数
我已使用 gdb 逐步执行在标准 C 数学库 (-lm -march=pentium3 -mfpmath=387) 中实现标准 C sin() 函数的汇编代码。那里有很多存根,我不知道为什么他们不简单地内联 fsin 汇编器指令。其他数学函数也会发生同样的情况。为什么他们不直接调用相应的FPU指令呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为“那里有很多存根”比 x87
fsin
指令更快、更准确。与普遍的看法相反,图书馆作者通常知道他们在做什么。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.您可能应该 启用内在函数 - 内在实现sinf 几乎肯定会被内联(除非,比如说,有人获取了它的地址,或者其他一些不寻常的情况)。
在 VS 上,这相当于用 /Oi 编译。
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.