如何获取开方内联汇编于iOS工作 [英] How to get this sqrt inline assembly working for iOS

查看:468
本文介绍了如何获取开方内联汇编于iOS工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照另一SO 发布并实施的 sqrt14 我的iOS中应用程序:

I am trying to follow another SO post and implement sqrt14 within my iOS app:

double inline __declspec (naked) __fastcall sqrt14(double n)
{
    _asm fld qword ptr [esp+4]
    _asm fsqrt
    _asm ret 8
}

我已经修改这在我的code以下内容:

I have modified this to the following in my code:

double inline __declspec (naked) sqrt14(double n)
{
    __asm__("fld qword ptr [esp+4]");
    __asm__("fsqrt");
    __asm__("ret 8");
}

在上面,我已删除从方法定义了__fastcall关键字,因为我的理解是,它仅用于x86的。以上分别给出了每个流水线以下错误:

Above, I have removed the "__fastcall" keyword from the method definition since my understanding is that it is for x86 only. The above gives the following errors for each assembly line respectively:

在参数列表中的意外标记

Unexpected token in argument list

无效指令

无效指令

我试图通过一些内嵌ASM指南与<一读HREF =htt​​p://stackoverflow.com/questions/238010/how-do-i-do-inline-assembly-on-the-iphone>其他职位的关于如何做到这一点,但我一般只是不熟悉的语言。我知道MIPS不错,但这些命令/寄存器似乎是非常不同的。例如,我不明白为什么原作者从不使用在大会codeN值的任何地方通过。

I have attempted to read through a few inline ASM guides and other posts on how to do this, but I am generally just unfamiliar with the language. I know MIPS quite well, but these commands/registers seem to be very different. For example, I don't understand why the original author never uses the passed in "n" value anywhere in the assembly code.

任何帮助得到这个工作将是极大的AP preciated!我试图做到这一点,因为我建立一个应用程序,我需要计算的sqrt(好吧,是的,我可以做一个查找表,但现在我很在意precision)在现场的每一个像素 - 视频饲料。我目前使用的标准开方,而且除了计算的其余部分,我在各地跑8FPS。希望碰到的一个框架或两个这种变化。

Any help getting this to work would be greatly appreciated! I am trying to do this because I am building an app where I need to calculate sqrt (ok, yes, I could do a lookup table, but for right now I care a lot about precision) on every pixel of a live-video feed. I am currently using the standard sqrt, and in addition to the rest of the computation, I'm running at around 8fps. Hoping to bump that up a frame or two with this change.

如果它的问题:我正在创建的应用程序与现有的任何iOS设备可以运行的iOS 7.1同样,许多感谢您的帮助,最好是兼容

If it matters: I'm building the app to ideally be compatibly with any current iOS device that can run iOS 7.1 Again, many thanks for any help.

推荐答案

编译器是完全能够产生 FSQRT 指令,你不需要为内联汇编。如果你使用,你可能会得到一些额外的速度 -ffast-数学

The compiler is perfectly capable of generating fsqrt instruction, you don't need inline asm for that. You might get some extra speed if you use -ffast-math.

有关完整起见,这里是内联汇编的版本:

For completeness' sake, here is the inline asm version:

__asm__ __volatile__ ("fsqrt" : "=t" (n) : "0" (n));

FSQRT 指令没有明确的操作数,它使用堆栈的顶部隐。在 = T 约束告诉编译器预计在FPU堆栈的顶部和 0 约束输出指示编译器将输入在同一个地方作为输出 0#(即在FPU堆栈的顶部再次)。

The fsqrt instruction has no explicit operands, it uses the top of the stack implicitly. The =t constraint tells the compiler to expect the output on the top of the fpu stack and the 0 constraint instructs the compiler to place the input in the same place as output #0 (ie. the top of the fpu stack again).

注意 FSQRT 当然86只,这意味着它不会如工作在ARM处理器。

Note that fsqrt is of course x86-only, meaning it wont work for example on ARM cpus.

这篇关于如何获取开方内联汇编于iOS工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆