ARM64用气iOS上的? [英] ARM64 using gas on iOS?

查看:993
本文介绍了ARM64用气iOS上的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我已经移植到64位ARM一些汇编函数,它们做工精细Android上,但是当我试图编译在X code中的相同的文件,我发现铛使用不同语法(从官方文档ARM不同)。

I've got some assembly functions I've ported to 64-bit ARM, and they work fine on Android, but when I tried to compile the same files in Xcode, I discovered that clang uses a different syntax (different from the official ARM documentation).

我已经找到了一些脚本从一种格式转换为另转换的源文件,但这并不是理想的解决方案(它似乎在源文件中包含preprocessor定义这些脚本不工作)。

I've found some scripts which convert a source file from one format to the other, but this is not the ideal solution (and it seems these scripts don't work when the source files contain preprocessor defines).

我可以简单地使用天然气X code,或配置铛接受气体语法?如果没有,哪里是铛汇编文件?
结果
结果

Can I simply use gas in Xcode, or configure clang to accept the gas syntax? If not, where is the clang assembler documentation?

更新 - 2015年9月

看来,问题是用X code解决7(新铛版本?):现在我可以导入为Android编写的汇编源文件,并将它们没有任何改变编译

It seems that the issue is solved by XCode 7 (new clang version?): now I can import the assembly source files written for Android, and they are compiled without any change.

推荐答案

让我们用我的答案作为一般的指导,在Android和iOS编写ARM64 code。开始,我们将用挥发性和非挥发性寄存器启动:

Let's use my answer as a general guide to writing ARM64 code on Android and iOS. to begin, we'll start with the volatile and non-volatile registers:

X0-X7 - 参数和返回值(波动)结果
X8 =间接结果(结构)的位置(或临时REG)结果
X9-X15 =临时(挥发性)结果
X16-X17 - 介绍呼叫使用的寄存器(PLT,连接器)或临时结果
X18 - 平台特定的使用(TLS)结果
X19-X28 - 被调用函数保存寄存器(非易失性)结果
X29 - 帧指针结果
X30 - 链接寄存器(LR)结果
SP - 堆栈指针和零(XZR)结果
V0-V7,V16-V31 - 挥发性NEON和FP注册结果
V8-V15 - 被调用函数保存寄存器(非易失性的,由编译器用于临时瓦尔)结果

X0-X7 - arguments and return value (volatile)
X8 = indirect result (struct) location (or temp reg)
X9-X15 = temporary (volatile)
X16-X17 - intro-call-use registers (PLT, Linker) or temp
X18 - platform specific use (TLS)
X19-X28 - callee saved registers (non-volatile)
X29 - frame pointer
X30 - link register (LR)
SP - stack pointer and zero (XZR)
V0-V7, V16-V31 - volatile NEON and FP registers
V8-V15 - callee saved registers (non-volatile, used for temp vars by compilers)

接下来是汇编指令来正确地为您创造code中的段:

Next up is the assembler directives to correctly create the "segments" for your code:

的Andr​​oid 结果
  .CPU通用+ FP + SIMD结果
  的.text结果
每个功能,添加这些3行结果
  .section伪.text.MyFunctionName,斧头,PROGBITS%结果
  .align伪2结果
  .TYPE MyFunctionName,功能%结果

Android
.cpu generic+fp+simd
.text
for each function, add these 3 lines
.section .text.MyFunctionName,"ax",%progbits
.align 2
.type MyFunctionName, %function

的iOS (真正需要的任何除ALIGN指令)结果
  .align伪2结果

iOS (Nothing really needed except for the align directive)
.align 2

公开声明(全局)的标签

Declaring public (global) labels

的Andr​​oid 结果
 。全球MyFunctionName

Android
.global MyFunctionName

的iOS 结果
  .globl _MyFunctionName的< - 注意下划线和全局指令的不同的拼写

接下来的区别是在获得一个指向源$ C ​​$ C定义静态数据。举例来说,假设你有一个数据表格,你想加载寄存器X0的指针表。

The next difference is in getting a pointer to static data defined in your source code. For instance, let's say you have a data table and you would like to load register X0 with a pointer to the table.

的Andr​​oid 搜索

  adrp  x0, MyDataTable
  add   x0, x0, #:lo12:MyDataTable

的iOS 搜索

  adrp  x0,MyDataTable@PAGE
  add   x0,x0,MyDataTable@PAGEOFF

接下来,NEON语法。的iOS允许而Android希望看到寄存器与大小后缀大小的信息被附加到指令助记符

Next, NEON syntax. iOS allows the size information to be appended to the instruction mnemonic while Android wants to see the register with the size suffix

的Andr​​oid 结果
      LD1 {} v0.16b [X 0],#16

Android
ld1 {v0.16b},[x0],#16

的iOS 结果
      ld1.16b {V0},[X 0],#16

iOS
ld1.16b {v0},[x0],#16

嵌套循环结果
在32位ARM code这是典型的推LR堆栈preserve它当你需要从一个函数中调用的函数。由于NEON指令不再协处理器,并已合并到主指令集Aarch64的,没有惩罚移动数据来回。它在未使用的NEON寄存器现在实际的preserve X30(LR)。例如:

Nested Loops
In 32-bit ARM code it was typical to push LR on the stack to preserve it for when you need to call a function from within a function. Since NEON instructions are no longer in a co-processor and have been merged into the main instruction set of Aarch64, there's no penalty for moving data back and forth. It's now practical to preserve X30 (LR) in an unused NEON register. For example:

  fmov d0,x30   // preserve LR
  <some code which makes function calls>
  fmov x30,d0   // restore LR

这就是现在。如果有人发现那里有更多的差异特殊情况下,我会添加他们。

That's all for now. If someone finds specific cases where there are more differences, I'll add them.

这篇关于ARM64用气iOS上的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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