「这是我参与2022首次更文挑战的第2天,活动详情查看:2022首次更文挑战」。
BUFF加持,探索不止
1、__LP64__
-
首先,
LP64是数据模型,不是Mac架构 -
LP64中就是long integers和pointers是64 bits -
如表:除了
LP64之外,还有LLP64、ILP64、SILP64、ILP32等数据模型
| data models | |||||
|---|---|---|---|---|---|
| Data model | short | int | long | long long | pointer |
| LLP64 | 16 | 32 | 32 | 64 | 64 |
| LP64 | 16 | 32 | 64 | 64 | 64 |
| ILP64 | 16 | 64 | 64 | 64 | 64 |
| SILP64 | 64 | 64 | 64 | 64 | 64 |
| ILP32 | 16 | 32 | 32 | 64 | 32 |
注意一点:
也有在64位处理器上使用ILP32数据模型,该数据模型减小了代码大小,也减小了包含指针的数据结构的大小,所以造成的结果就是地址空间会小很多(这里应该是指操作系统给应用进程分配的虚拟内存空间)。
对于某些嵌入式系统来说,ILP32是一个不错的选择。已在Apple Watch Series 4之后使用。所以,在Objc源码中会看到这样的判断:(__ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__))
2、 __ARM_ARCH_7K__
// https://github.com/llvm/llvm-project/
// Unfortunately, __ARM_ARCH_7K__ is now more of an ABI descriptor. The CPU
// happens to be Cortex-A7 though, so it should still get __ARM_ARCH_7A__.
if (getTriple().isWatchABI())
Builder.defineMacro("__ARM_ARCH_7K__", "2");
isWatchABI同时这里有个苹果处理器参数大全的网页,也可以查看Apple设备的CPU参数,进行核对。
3、SUPPORT_INDEXED_ISA
记录完__ARM_ARCH_7K__ ,接着就该记录SUPPORT_INDEXED_ISA ,这个在探索OC底层类相关的源码时是常常见到的。
// field as an index into a class table.
// Note, keep this in sync with any .s files which also define it.
// Be sure to edit objc-abi.h as well.
#if __ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__)
# define SUPPORT_INDEXED_ISA 1
#else
# define SUPPORT_INDEXED_ISA 0
#endif
- 判断是否为Watch设备
- 根据if条件,在
iOS中即:# define SUPPORT_INDEXED_ISA 0:非Watch
注意一点:
正如开篇所记录,LP64表示的是一种数据模型,arm64才是CPU架构。
4、SUPPORT_PACKED_ISA
// Define SUPPORT_PACKED_ISA=1 on platforms that store the class in the isa
// field as a maskable pointer with other data around it.
#if (!__LP64__ || TARGET_OS_WIN32 || \
(TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST && !__arm64__))
# define SUPPORT_PACKED_ISA 0
#else
# define SUPPORT_PACKED_ISA 1
#endif
- 判断是否支持
isa优化 - 根据if条件,在
iOS中即:#define SUPPORT_PACKED_ISA 1:支持优化
在类de数据结构分析(总)中分析
isa_t数据结构时,其中的ISA_BITFIELD(isa.h) 就定义在SUPPORT_PACKED_ISA中
5、TARGET_OS_MACCATALYST
Mac Catalyst 是苹果在19年WWDC上发布的,一个“一键式的操作”帮助开发者将iPad 应用移植到macOS上的服务。介绍说“只需要稍加优化就可以完美在mac上运行”。所以这个宏的意义就是针对这项服务的。
6、SUPPORT_NONPOINTER_ISA
// Define SUPPORT_NONPOINTER_ISA=1 on any platform that may store something
// in the isa field that is not a raw pointer.
#if !SUPPORT_INDEXED_ISA && !SUPPORT_PACKED_ISA
# define SUPPORT_NONPOINTER_ISA 0
#else
# define SUPPORT_NONPOINTER_ISA 1
#endif
- 判断是否为纯指针isa
- if条件,在
iOS中SUPPORT_INDEXED_ISA==0、SUPPORT_PACKED_ISA ==1,即:# define SUPPORT_NONPOINTER_ISA 1:非纯指针isa