背景
在Windows上使用64位Steel Bank Common Lisp实现一个简单的身份函数时:
(defun a (x)
(declare (fixnum x))
(declare (optimize (speed 3) (safety 0)))
(the fixnum x))
我的发现,拆卸的步骤如下:
* (disassemble 'a)
; disassembly for A
; Size: 13 bytes
; 02D7DFA6: 84042500000F20 TEST AL, [#x200F0000] ; safepoint
; no-arg-parsing entry point
; AD: 488BE5 MOV RSP, RBP
; B0: F8 CLC
; B1: 5D POP RBP
; B2: C3 RET
我理解这个句子的意思:
mov rsp, rbp
pop rbp
ret
执行函数的标准返回操作,但我不明白为什么会有这些代码行:
TEST AL, [#x200F0000] // My understanding is that this sets flags based on bitwise and of AL and contents of memory 0x200F0000
以及
CLC // My understanding is that this clears the carry flag.
问题
- 为什么SBCL会生成测试指令,却从未使用过标志位?
- 为什么SBCL在从函数返回之前清除进位标志?