delphi - 原子内在函数的对齐要求是什么(如果有)?

标签 delphi delphi-xe7 armv7

Delphi 移动目标的原子操作构建在 AtomicXXX 系列内部函数之上。 documentation说:

Because the Delphi mobile compilers do not support a built-in assembler, the System unit provides four atomic intrinsic functions that provide a way to atomically exchange, compare and exchange, increment, and decrement memory values.

这四个函数是:

其他提供原子操作的 RTL 函数,例如TInterlocked 的静态类方法类,是建立在这四个内在函数之上的。

对于面向 ARMv7 的移动编译器,这四个原子内在函数是否有任何对齐要求?如果有,它们是什么?

文档没有列出任何此类要求。然而,众所周知,该文档是不准确的,我没有信心将没有任何规定的要求作为不存在此类要求的明确证据。

顺便说一句,XE8 documentation for intrinsic functions声明桌面编译器不支持这些原子内在函数。这是不正确的——桌面编译器支持这些内在函数。

最佳答案

XE8编译

var 
  a: integer;

AtomicIncrement(a);

3e: 2201        movs    r2, #1
40: 900c        str r0, [sp, #48]   ; 0x30
42: 910b        str r1, [sp, #44]   ; 0x2c
44: 920a        str r2, [sp, #40]   ; 0x28
46: 980b        ldr r0, [sp, #44]   ; 0x2c
48: e850 1f00   ldrex   r1, [r0]
4c: 9a0a        ldr r2, [sp, #40]   ; 0x28
4e: 4411        add r1, r2
50: e840 1300   strex   r3, r1, [r0]
54: 2b00        cmp r3, #0
56: d1f6        bne.n   46 <_NativeMain+0x46>

因此原子性是使用ldrex/strex来实现的.

如果我正在解释community.arm.com处的信息正确地,对于 4 字节操作(ldrd/strd),所需的对齐方式是 DWORD 对齐;对于 8 字节操作,所需的对齐方式是 QWORD 对齐。

其他原子函数以类似的方式实现,因此应适用相同的要求。

AtomicDecrement(a);

68: 980f        ldr r0, [sp, #60]   ; 0x3c
6a: e850 1f00   ldrex   r1, [r0]
6e: 9a0e        ldr r2, [sp, #56]   ; 0x38
70: 1a89        subs    r1, r1, r2
72: e840 1300   strex   r3, r1, [r0]
76: 2b00        cmp r3, #0
78: d1f6        bne.n   68 <_NativeMain+0x68>

AtomicExchange(a,b);

82: 990f        ldr r1, [sp, #60]   ; 0x3c
84: 6008        str r0, [r1, #0]
86: 4873        ldr r0, [pc, #460]  ; (254 <_NativeMain+0x254>)
88: 9a10        ldr r2, [sp, #64]   ; 0x40
8a: 5880        ldr r0, [r0, r2]
8c: 6800        ldr r0, [r0, #0]
8e: f3bf 8f5b   dmb ish
92: 900d        str r0, [sp, #52]   ; 0x34
94: 980f        ldr r0, [sp, #60]   ; 0x3c
96: e850 1f00   ldrex   r1, [r0]
9a: 9b0d        ldr r3, [sp, #52]   ; 0x34
9c: e840 3200   strex   r2, r3, [r0]
a0: 2a00        cmp r2, #0
a2: 910c        str r1, [sp, #48]   ; 0x30
a4: d1f6        bne.n   94 <_NativeMain+0x94>

AtomicCmpExchange(a, 42, 17);

ae: 990f        ldr r1, [sp, #60]   ; 0x3c
b0: 6008        str r0, [r1, #0]
b2: f3bf 8f5b   dmb ish
b6: 202a        movs    r0, #42 ; 0x2a
b8: 2211        movs    r2, #17
ba: 900b        str r0, [sp, #44]   ; 0x2c
bc: 920a        str r2, [sp, #40]   ; 0x28
be: 980f        ldr r0, [sp, #60]   ; 0x3c
c0: e850 1f00   ldrex   r1, [r0]
c4: 9a0a        ldr r2, [sp, #40]   ; 0x28
c6: 4291        cmp r1, r2
c8: d105        bne.n   d6 <_NativeMain+0xd6>
ca: 990b        ldr r1, [sp, #44]   ; 0x2c
cc: 9a0f        ldr r2, [sp, #60]   ; 0x3c
ce: e842 1000   strex   r0, r1, [r2]
d2: 2800        cmp r0, #0
d4: d1f3        bne.n   be <_NativeMain+0xbe>

关于delphi - 原子内在函数的对齐要求是什么(如果有)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173879/

相关文章:

ios - 架构armv7的 undefined symbol :homeViewController1

web-services - 选择 Web 服务框架时应该考虑哪些因素?

delphi - 如何使组件编辑器在双击时执行原始处理程序?

delphi - 从样式对话框/ShowMessage 边框中排除 VCL 样式

delphi - 无法从 Indy TIdCookieManager 获取 cookie

iOS6 和 Armv7 的 iOS 链接问题

ios - iPhone 5 armv7s 处理器与其前代产品有何不同?

delphi - 单个用户的多个连接

multithreading - 分析死锁时"DebugInfo for CritSec does not point back to the critical section"

delphi - 复制时如何保留控件之间的连接?