[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

conditional move

zoav1602

6/14/2015 10:19:00 AM

Hello, group!

Just out of curiousity, when does SBCL generate a CMOV assembler instruction? I expected to see it in the disiassembly of the following function:

(lambda (x)
(declare (type (simple-array fixnum (10)) x)
(optimize speed (debug 0) (safety 0)))
(let ((v (aref x 9)))
(declare (type fixnum v))
(dotimes (i 9 v)
(declare (type fixnum i))
(if (< v (aref x i))
(setf v (aref x i)))))

But I see only ordinary MOV instructions in the output:

; disassembly for (LAMBDA (X))
; Size: 48 bytes. Origin: #x100935F0C2
; C2: 488B4B49 MOV RCX, [RBX+73] ; no-arg-parsing entry point
; C6: 31C0 XOR EAX, EAX
; C8: EB19 JMP L2
; CA: 660F1F440000 NOP
; D0: L0: 488B548301 MOV RDX, [RBX+RAX*4+1]
; D5: 4839D1 CMP RCX, RDX
; D8: 7D05 JNL L1
; DA: 488B4C8301 MOV RCX, [RBX+RAX*4+1]
; DF: L1: 4883C002 ADD RAX, 2
; E3: L2: 4883F812 CMP RAX, 18
; E7: 7CE7 JL L0
; E9: 488BD1 MOV RDX, RCX
; EC: 488BE5 MOV RSP, RBP
; EF: F8 CLC
; F0: 5D POP RBP
; F1: C3 RET

My platform is x86-64. What should I change in the code to obtain CMOV?

Sincerely yours,
A.Z.
2 Answers

Pascal J. Bourguignon

6/14/2015 11:19:00 AM

0

Andrei Zorine <zoav1602@gmail.com> writes:

> Hello, group!
>
> Just out of curiousity, when does SBCL generate a CMOV assembler
> instruction? I expected to see it in the disiassembly of the following
> function:
>
> (lambda (x)
> (declare (type (simple-array fixnum (10)) x)
> (optimize speed (debug 0) (safety 0)))
> (let ((v (aref x 9)))
> (declare (type fixnum v))
> (dotimes (i 9 v)
> (declare (type fixnum i))
> (if (< v (aref x i))
> (setf v (aref x i)))))
>
> But I see only ordinary MOV instructions in the output:
>
> ; disassembly for (LAMBDA (X))
> ; Size: 48 bytes. Origin: #x100935F0C2
> ; C2: 488B4B49 MOV RCX, [RBX+73] ; no-arg-parsing entry point
> ; C6: 31C0 XOR EAX, EAX
> ; C8: EB19 JMP L2
> ; CA: 660F1F440000 NOP
> ; D0: L0: 488B548301 MOV RDX, [RBX+RAX*4+1]
> ; D5: 4839D1 CMP RCX, RDX
> ; D8: 7D05 JNL L1
> ; DA: 488B4C8301 MOV RCX, [RBX+RAX*4+1]
> ; DF: L1: 4883C002 ADD RAX, 2
> ; E3: L2: 4883F812 CMP RAX, 18
> ; E7: 7CE7 JL L0
> ; E9: 488BD1 MOV RDX, RCX
> ; EC: 488BE5 MOV RSP, RBP
> ; EF: F8 CLC
> ; F0: 5D POP RBP
> ; F1: C3 RET
>
> My platform is x86-64. What should I change in the code to obtain CMOV?

Would that be an improvement?

Smart instructions are not always the most optimized way to do it.

Does CMOV support the same addressing mode, in addition to having to
specify the condition?


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Pascal Costanza

6/14/2015 1:00:00 PM

0

On 14/06/2015 13:19, Pascal J. Bourguignon wrote:
> Andrei Zorine <zoav1602@gmail.com> writes:
>
>> Hello, group!
>>
>> Just out of curiousity, when does SBCL generate a CMOV assembler
>> instruction? I expected to see it in the disiassembly of the following
>> function:
>>
>> (lambda (x)
>> (declare (type (simple-array fixnum (10)) x)
>> (optimize speed (debug 0) (safety 0)))
>> (let ((v (aref x 9)))
>> (declare (type fixnum v))
>> (dotimes (i 9 v)
>> (declare (type fixnum i))
>> (if (< v (aref x i))
>> (setf v (aref x i)))))
>>
>> But I see only ordinary MOV instructions in the output:
>>
>> ; disassembly for (LAMBDA (X))
>> ; Size: 48 bytes. Origin: #x100935F0C2
>> ; C2: 488B4B49 MOV RCX, [RBX+73] ; no-arg-parsing entry point
>> ; C6: 31C0 XOR EAX, EAX
>> ; C8: EB19 JMP L2
>> ; CA: 660F1F440000 NOP
>> ; D0: L0: 488B548301 MOV RDX, [RBX+RAX*4+1]
>> ; D5: 4839D1 CMP RCX, RDX
>> ; D8: 7D05 JNL L1
>> ; DA: 488B4C8301 MOV RCX, [RBX+RAX*4+1]
>> ; DF: L1: 4883C002 ADD RAX, 2
>> ; E3: L2: 4883F812 CMP RAX, 18
>> ; E7: 7CE7 JL L0
>> ; E9: 488BD1 MOV RDX, RCX
>> ; EC: 488BE5 MOV RSP, RBP
>> ; EF: F8 CLC
>> ; F0: 5D POP RBP
>> ; F1: C3 RET
>>
>> My platform is x86-64. What should I change in the code to obtain CMOV?
>
> Would that be an improvement?
>
> Smart instructions are not always the most optimized way to do it.

Conditional moves don't need to involve branch prediction, because they
avoid the branch altogether.


Pascal

--
My website: http:/...
Common Lisp Document Repository: http://cdr.eu...
Closer to MOP & ContextL: http://common-lisp.net/proje...
The views expressed are my own, and not those of my employer.