【汇编优化】之ARM32与AARCH64指令集优化总结

前文《arm64》、《arm32》已经介绍arm,aarch64优化的一些基本知识,本文着重介绍优化过程中容易混淆的点,或需注意的点。

1. 关于指令编码长度
1.1 aarch32
		A32模式(ARM instruction sets),指令固定的编码长度为32bit
		T32模式(Thumb instruction sets),指令可以编码成16bit长,也可编码成32bit长
1.2 aarch64
		指令固定的编码长度为32bit

参考https://static.docs.arm.com/ddi0487/ca/DDI0487C_a_armv8_arm.pdf A1.3.2 The ARM instruction sets

2. 关于当前指令的地址
2.1 aarch32

在ARM32状态下,当前执行指令的地址通常是pc-8,而在Thumb状态下通常是pc-4。参考地址:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0013d/index.html 程序计数器(pc)
 
  疑问?
  指令的编码长度为32位,即4字节,为什么arm模式下,当前指令是pc-8:
  拿ARMv7三级流水线做示例,如图,假设add指令fetch时,指令地址为pc1; add指令decode时,下一条指令sub又进入fetch阶段,此时pc2 = pc1 + 4; add指令execute时,sub指令后的cmp油进入fetch阶段,此时pc = pc2 + 4, 因此add指令执行时真正的pc地址pc1 = pc-8。
在这里插入图片描述
 参考https://blog.csdn.net/lee244868149/article/details/49488575/
 

2.2 aarch64

在arm64状态下,当前执行指令的地址通常是pc,英文原文:

Program counter
 The current Program Counter (PC) cannot be referred to by number as if part of the general register file and therefore cannot be used as the source or destination of arithmetic instructions, or as the base, index or transfer register of load and store instructions.
 The only instructions that read the PC are those whose function it is to compute a PC-relative address (ADR, ADRP, literal load, and direct branches), and the branch-and-link instructions that store a return address in the link register (BL and BLR). The only way to modify the program counter is using branch, exception generation and exception return instructions.
 Where the PC is read by an instruction to compute a PC-relative address, then its value is the address of that instruction. Unlike A32 and T32, there is no implied offset of 4 or 8 bytes.
参考http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/ch05s01s03.html 5.1.3. Registers

3. 关于形参超过指令个数,访问方法
3.1 aarch32

arm32下,前4个参数是通过r0~r3传递,第4个参数需要通过sp访问,第5个参数需要通过sp + 4 访问,第n个参数需要通过sp + 4*(n-4)访问。

3.2 aarch64

arm64下,前8个参数是通过x0~x7传递,第8个参数需要通过sp访问,第9个参数需要通过sp + 8 访问,第n个参数需要通过sp + 8*(n-8)访问。

4. aarch64下< Vn>.< Ts>[< index2>]的用法

示例: mov < Vd>.< Ts>[< index1>], < Vn>.< Ts>[< index2>]
其中Ts的值需要注意,只能是以下情况之一:

  • B
  • H
  • S
  • D
    不要将Ts写成8B、2s等,因为是取矢量寄存器(Vn)中的元素,所以带数字是多此一举,反而导致在ios下编译有问题。
5. aarch64下imm需注意的地方

示例:cmp < Wn|WSP>, #< imm> {, < shift>}
其中imm是无符号立即数,取值范围[0, 4095]。
此处说明的是:在使用立即数的时候,需要看指令所支持的立即数范围。

6. aarch64下v寄存器的写法

示例: add v4.4H, v4.4H, V5.4H
指令有没有问题?在Linux下编是不会提示错误的,但是在ios下(mac电脑上编)会提示指令不合法,正确的写法:
add v4.4H, v4.4H, v5.4H 注意到没?V5.4H 改成了v5.4H,大小写!!!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值