📄 macros.lisp
字号:
Emit code for an error with the specified Error-Code and context Values." (assemble (*elsewhere*) (let ((start-lab (gen-label))) (emit-label start-lab) (emit-error-break vop error-trap (error-number-or-lose error-code) values) start-lab)));;;; PSEUDO-ATOMIC;;; This is used to wrap operations which leave untagged memory lying;;; around. It's an operation which the AOP weenies would describe as;;; having "cross-cutting concerns", meaning it appears all over the;;; place and there's no logical single place to attach documentation.;;; grep (mostly in src/runtime) is your friend(defmacro maybe-pseudo-atomic (not-really-p &body body) `(if ,not-really-p (progn ,@body) (pseudo-atomic ,@body)))#!+sb-thread(defmacro pseudo-atomic (&rest forms) (with-unique-names (label) `(let ((,label (gen-label))) (inst or (make-ea :byte :base thread-base-tn :disp (* 8 thread-pseudo-atomic-bits-slot)) (fixnumize 1)) ,@forms (inst xor (make-ea :byte :base thread-base-tn :disp (* 8 thread-pseudo-atomic-bits-slot)) (fixnumize 1)) (inst jmp :z ,label) ;; if PAI was set, interrupts were disabled at the same ;; time using the process signal mask. (inst break pending-interrupt-trap) (emit-label ,label))))#!-sb-thread(defmacro pseudo-atomic (&rest forms) (with-unique-names (label) `(let ((,label (gen-label))) ;; FIXME: The MAKE-EA noise should become a MACROLET macro or ;; something. (perhaps SVLB, for static variable low byte) (inst or (make-ea :byte :disp (+ nil-value (static-symbol-offset '*pseudo-atomic-bits*) (ash symbol-value-slot word-shift) (- other-pointer-lowtag))) (fixnumize 1)) ,@forms (inst xor (make-ea :byte :disp (+ nil-value (static-symbol-offset '*pseudo-atomic-bits*) (ash symbol-value-slot word-shift) (- other-pointer-lowtag))) (fixnumize 1)) (inst jmp :z ,label) ;; if PAI was set, interrupts were disabled at the same time ;; using the process signal mask. (inst break pending-interrupt-trap) (emit-label ,label))));;;; indexed references(defmacro define-full-compare-and-swap (name type offset lowtag scs el-type &optional translate) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg) :to :eval) (index :scs (any-reg) :to :result) (old-value :scs ,scs :target rax) (new-value :scs ,scs)) (:arg-types ,type tagged-num ,el-type ,el-type) (:temporary (:sc descriptor-reg :offset rax-offset :from (:argument 2) :to :result :target value) rax) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 5 (move rax old-value) (inst cmpxchg (make-ea :qword :base object :index index :disp (- (* ,offset n-word-bytes) ,lowtag)) new-value :lock) (move value rax)))))(defmacro define-full-reffer (name type offset lowtag scs el-type &optional translate) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (any-reg))) (:arg-types ,type tagged-num) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 3 ; pw was 5 (inst mov value (make-ea :qword :base object :index index :disp (- (* ,offset n-word-bytes) ,lowtag))))) (define-vop (,(symbolicate name "-C")) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg))) (:info index) (:arg-types ,type (:constant (load/store-index ,n-word-bytes ,(eval lowtag) ,(eval offset)))) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 2 ; pw was 5 (inst mov value (make-ea :qword :base object :disp (- (* (+ ,offset index) n-word-bytes) ,lowtag)))))))(defmacro define-full-reffer+offset (name type offset lowtag scs el-type &optional translate) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (any-reg))) (:info offset) (:arg-types ,type tagged-num (:constant (constant-displacement other-pointer-lowtag n-word-bytes vector-data-offset))) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 3 ; pw was 5 (inst mov value (make-ea :qword :base object :index index :disp (- (* (+ ,offset offset) n-word-bytes) ,lowtag))))) (define-vop (,(symbolicate name "-C")) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg))) (:info index offset) (:arg-types ,type (:constant (load/store-index ,n-word-bytes ,(eval lowtag) ,(eval offset))) (:constant (constant-displacement other-pointer-lowtag n-word-bytes vector-data-offset))) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 2 ; pw was 5 (inst mov value (make-ea :qword :base object :disp (- (* (+ ,offset index offset) n-word-bytes) ,lowtag)))))))(defmacro define-full-setter (name type offset lowtag scs el-type &optional translate) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (any-reg)) (value :scs ,scs :target result)) (:arg-types ,type tagged-num ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 4 ; was 5 (inst mov (make-ea :qword :base object :index index :disp (- (* ,offset n-word-bytes) ,lowtag)) value) (move result value))) (define-vop (,(symbolicate name "-C")) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (value :scs ,scs :target result)) (:info index) (:arg-types ,type (:constant (load/store-index ,n-word-bytes ,(eval lowtag) ,(eval offset))) ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 3 ; was 5 (inst mov (make-ea :qword :base object :disp (- (* (+ ,offset index) n-word-bytes) ,lowtag)) value) (move result value)))))(defmacro define-full-setter+offset (name type offset lowtag scs el-type &optional translate) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (any-reg)) (value :scs ,scs :target result)) (:info offset) (:arg-types ,type tagged-num (:constant (constant-displacement other-pointer-lowtag n-word-bytes vector-data-offset)) ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 4 ; was 5 (inst mov (make-ea :qword :base object :index index :disp (- (* (+ ,offset offset) n-word-bytes) ,lowtag)) value) (move result value))) (define-vop (,(symbolicate name "-C")) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (value :scs ,scs :target result)) (:info index offset) (:arg-types ,type (:constant (load/store-index ,n-word-bytes ,(eval lowtag) ,(eval offset))) (:constant (constant-displacement other-pointer-lowtag n-word-bytes vector-data-offset)) ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 3 ; was 5 (inst mov (make-ea :qword :base object :disp (- (* (+ ,offset index offset) n-word-bytes) ,lowtag)) value) (move result value)))));;; helper for alien stuff.(def!macro with-pinned-objects ((&rest objects) &body body) "Arrange with the garbage collector that the pages occupied byOBJECTS will not be moved in memory for the duration of BODY.Useful for e.g. foreign calls where another thread may triggercollection." (if objects (let ((pins (make-gensym-list (length objects))) (wpo (block-gensym "WPO"))) ;; BODY is stuffed in a function to preserve the lexical ;; environment. `(flet ((,wpo () (progn ,@body))) ;; PINS are dx-allocated in case the compiler for some ;; unfathomable reason decides to allocate value-cells ;; for them -- since we have DX value-cells on x86oid ;; platforms this still forces them on the stack. (dx-let ,(mapcar #'list pins objects) (multiple-value-prog1 (,wpo) ;; TOUCH-OBJECT has a VOP with an empty body: compiler ;; thinks we're using the argument and doesn't flush ;; the variable, but we don't have to pay any extra ;; beyond that -- and MULTIPLE-VALUE-PROG1 keeps them ;; live till the body has finished. *whew* ,@(mapcar (lambda (pin) `(touch-object ,pin)) pins))))) `(progn ,@body)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -