📄 move.lisp
字号:
;;; This VOP exists just to begin the lifetime of a TN that couldn't;;; be written legally due to a type error. An error is signalled;;; before this VOP is so we don't need to do anything (not that there;;; would be anything sensible to do anyway.)(define-vop (illegal-move) (:args (x) (type)) (:results (y)) (:ignore y) (:vop-var vop) (:save-p :compute-only) (:generator 666 (error-call vop 'object-not-type-error x type)));;;; moves and coercions;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw;;; integer to a tagged bignum or fixnum.;;; Arg is a fixnum, so just shift it. We need a type restriction;;; because some possible arg SCs (control-stack) overlap with;;; possible bignum arg SCs.(define-vop (move-to-word/fixnum) (:args (x :scs (any-reg descriptor-reg) :target y :load-if (not (location= x y)))) (:results (y :scs (signed-reg unsigned-reg) :load-if (not (location= x y)))) (:arg-types tagged-num) (:note "fixnum untagging") (:generator 1 (move y x) (inst sar y (1- n-lowtag-bits))))(define-move-vop move-to-word/fixnum :move (any-reg descriptor-reg) (signed-reg unsigned-reg));;; Arg is a non-immediate constant, load it.(define-vop (move-to-word-c) (:args (x :scs (constant))) (:results (y :scs (signed-reg unsigned-reg))) (:note "constant load") (:generator 1 (inst mov y (tn-value x))))(define-move-vop move-to-word-c :move (constant) (signed-reg unsigned-reg));;; Arg is a fixnum or bignum, figure out which and load if necessary.(define-vop (move-to-word/integer) (:args (x :scs (descriptor-reg) :target eax)) (:results (y :scs (signed-reg unsigned-reg))) (:note "integer to untagged word coercion") (:temporary (:sc unsigned-reg :offset eax-offset :from (:argument 0) :to (:result 0) :target y) eax) (:generator 4 (move eax x) (inst test al-tn 7) ; a symbolic constant for this (inst jmp :z FIXNUM) ; would be nice (loadw y eax bignum-digits-offset other-pointer-lowtag) (inst jmp DONE) FIXNUM (inst sar eax (1- n-lowtag-bits)) (move y eax) DONE))(define-move-vop move-to-word/integer :move (descriptor-reg) (signed-reg unsigned-reg));;; Result is a fixnum, so we can just shift. We need the result type;;; restriction because of the control-stack ambiguity noted above.(define-vop (move-from-word/fixnum) (:args (x :scs (signed-reg unsigned-reg) :target y :load-if (not (location= x y)))) (:results (y :scs (any-reg descriptor-reg) :load-if (not (location= x y)))) (:result-types tagged-num) (:note "fixnum tagging") (:generator 1 (cond ((and (sc-is x signed-reg unsigned-reg) (not (location= x y))) ;; Uses 7 bytes, but faster on the Pentium (inst lea y (make-ea :qword :index x :scale 8))) (t ;; Uses: If x is a reg 2 + 3; if x = y uses only 3 bytes (move y x) (inst shl y (1- n-lowtag-bits))))))(define-move-vop move-from-word/fixnum :move (signed-reg unsigned-reg) (any-reg descriptor-reg));;; Convert an untagged signed word to a lispobj -- fixnum or bignum;;; as the case may be. Fixnum case inline, bignum case in an assembly;;; routine.(define-vop (move-from-signed) (:args (x :scs (signed-reg unsigned-reg) :to :result)) (:results (y :scs (any-reg descriptor-reg) :from :argument)) (:note "signed word to integer coercion") ;; Worst case cost to make sure people know they may be number consing. (:generator 20 (aver (not (location= x y))) (let ((done (gen-label))) (inst imul y x #.(ash 1 n-fixnum-tag-bits)) (inst jmp :no done) (inst mov y x) (inst lea temp-reg-tn (make-ea :qword :disp (make-fixup (ecase (tn-offset y) (#.rax-offset 'alloc-signed-bignum-in-rax) (#.rcx-offset 'alloc-signed-bignum-in-rcx) (#.rdx-offset 'alloc-signed-bignum-in-rdx) (#.rbx-offset 'alloc-signed-bignum-in-rbx) (#.rsi-offset 'alloc-signed-bignum-in-rsi) (#.rdi-offset 'alloc-signed-bignum-in-rdi) (#.r8-offset 'alloc-signed-bignum-in-r8) (#.r9-offset 'alloc-signed-bignum-in-r9) (#.r10-offset 'alloc-signed-bignum-in-r10) (#.r12-offset 'alloc-signed-bignum-in-r12) (#.r13-offset 'alloc-signed-bignum-in-r13) (#.r14-offset 'alloc-signed-bignum-in-r14) (#.r15-offset 'alloc-signed-bignum-in-r15)) :assembly-routine))) (inst call temp-reg-tn) (emit-label done))))(define-move-vop move-from-signed :move (signed-reg) (descriptor-reg));;; Convert an untagged unsigned word to a lispobj -- fixnum or bignum;;; as the case may be. Fixnum case inline, bignum case in an assembly;;; routine.(define-vop (move-from-unsigned) (:args (x :scs (signed-reg unsigned-reg) :to :result)) (:results (y :scs (any-reg descriptor-reg) :from :argument)) (:note "unsigned word to integer coercion") ;; Worst case cost to make sure people know they may be number consing. (:generator 20 (aver (not (location= x y))) (let ((done (gen-label))) (inst mov y #.(ash lowtag-mask (- n-word-bits n-fixnum-tag-bits 1))) ;; The assembly routines test the sign flag from this one, so if ;; you change stuff here, make sure the sign flag doesn't get ;; overwritten before the CALL! (inst test x y) ;; Faster but bigger then SHL Y 4. The cost of doing this ;; speculatively should be noise compared to bignum consing if ;; that is needed and saves one branch. (inst lea y (make-ea :qword :index x :scale 8)) (inst jmp :z done) (inst mov y x) (inst lea temp-reg-tn (make-ea :qword :disp (make-fixup (ecase (tn-offset y) (#.rax-offset 'alloc-unsigned-bignum-in-rax) (#.rcx-offset 'alloc-unsigned-bignum-in-rcx) (#.rdx-offset 'alloc-unsigned-bignum-in-rdx) (#.rbx-offset 'alloc-unsigned-bignum-in-rbx) (#.rsi-offset 'alloc-unsigned-bignum-in-rsi) (#.rdi-offset 'alloc-unsigned-bignum-in-rdi) (#.r8-offset 'alloc-unsigned-bignum-in-r8) (#.r9-offset 'alloc-unsigned-bignum-in-r9) (#.r10-offset 'alloc-unsigned-bignum-in-r10) (#.r12-offset 'alloc-unsigned-bignum-in-r12) (#.r13-offset 'alloc-unsigned-bignum-in-r13) (#.r14-offset 'alloc-unsigned-bignum-in-r14) (#.r15-offset 'alloc-unsigned-bignum-in-r15)) :assembly-routine))) (inst call temp-reg-tn) (emit-label done))))(define-move-vop move-from-unsigned :move (unsigned-reg) (descriptor-reg));;; Move untagged numbers.(define-vop (word-move) (:args (x :scs (signed-reg unsigned-reg) :target y :load-if (not (location= x y)))) (:results (y :scs (signed-reg unsigned-reg) :load-if (not (or (location= x y) (and (sc-is x signed-reg unsigned-reg) (sc-is y signed-stack unsigned-stack)))))) (:effects) (:affected) (:note "word integer move") (:generator 0 (move y x)))(define-move-vop word-move :move (signed-reg unsigned-reg) (signed-reg unsigned-reg));;; Move untagged number arguments/return-values.(define-vop (move-word-arg) (:args (x :scs (signed-reg unsigned-reg) :target y) (fp :scs (any-reg) :load-if (not (sc-is y sap-reg)))) (:results (y)) (:note "word integer argument move") (:generator 0 (sc-case y ((signed-reg unsigned-reg) (move y x)) ((signed-stack unsigned-stack) (if (= (tn-offset fp) esp-offset) (storew x fp (tn-offset y)) ; c-call (storew x fp (- (1+ (tn-offset y)))))))))(define-move-vop move-word-arg :move-arg (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg));;; Use standard MOVE-ARG and coercion to move an untagged number;;; to a descriptor passing location.(define-move-vop move-arg :move-arg (signed-reg unsigned-reg) (any-reg descriptor-reg))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -