📄 macros.lisp
字号:
(once-only ((result-tn result-tn) (size size) (stack-allocate-p stack-allocate-p)) `(maybe-pseudo-atomic ,stack-allocate-p (allocation ,result-tn (pad-data-block ,size) ,inline ,stack-allocate-p other-pointer-lowtag) (storew (logior (ash (1- ,size) n-widetag-bits) ,widetag) ,result-tn 0 other-pointer-lowtag) ,@forms)));;;; error code(defun emit-error-break (vop kind code values) (assemble () #!-darwin (inst int 3) ; i386 breakpoint instruction ;; CLH 20060314 ;; On Darwin, we need to use #x0b0f instead of int3 in order ;; to generate a SIGILL instead of a SIGTRAP as darwin/x86 ;; doesn't seem to be reliably firing SIGTRAP ;; handlers. Hopefully this will be fixed by Apple at a ;; later date. #!+darwin (inst word #x0b0f) ;; The return PC points here; note the location for the debugger. (when vop (note-this-location vop :internal-error)) (inst byte kind) ; e.g. trap_xyyy (with-adjustable-vector (vector) ; interr arguments (write-var-integer code vector) (dolist (tn values) ;; classic CMU CL comment: ;; zzzzz jrd here. tn-offset is zero for constant ;; tns. (write-var-integer (make-sc-offset (sc-number (tn-sc tn)) (or (tn-offset tn) 0)) vector)) (inst byte (length vector)) (dotimes (i (length vector)) (inst byte (aref vector i))))))(defun error-call (vop error-code &rest values) #!+sb-doc "Cause an error. ERROR-CODE is the error to cause." (emit-error-break vop error-trap (error-number-or-lose error-code) values))(defun generate-error-code (vop error-code &rest values) #!+sb-doc "Generate-Error-Code Error-code Value* 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;;; KLUDGE: since the stack on the x86 is treated conservatively, it;;; does not matter whether a signal occurs during construction of a;;; dynamic-extent object, as the half-finished construction of the;;; object will not cause any difficulty. We can therefore elide(defmacro maybe-pseudo-atomic (not-really-p &body forms) `(if ,not-really-p (progn ,@forms) (pseudo-atomic ,@forms)))#!+sb-thread(defmacro pseudo-atomic (&rest forms) (with-unique-names (label) `(let ((,label (gen-label))) (inst or (make-ea :byte :disp (* 4 thread-pseudo-atomic-bits-slot)) (fixnumize 1) :fs) ,@forms (inst xor (make-ea :byte :disp (* 4 thread-pseudo-atomic-bits-slot)) (fixnumize 1) :fs) (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))) (inst or (make-ea-for-symbol-value *pseudo-atomic-bits* :byte) (fixnumize 1)) ,@forms (inst xor (make-ea-for-symbol-value *pseudo-atomic-bits* :byte) (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 immediate unsigned-reg) :to :result) (old-value :scs ,scs :target eax) (new-value :scs ,scs)) (:arg-types ,type tagged-num ,el-type ,el-type) (:temporary (:sc descriptor-reg :offset eax-offset :from (:argument 2) :to :result :target value) eax) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 5 (move eax old-value) (let ((ea (sc-case index (immediate (make-ea :dword :base object :disp (- (* (+ ,offset (tn-value index)) n-word-bytes) ,lowtag))) (unsigned-reg (make-ea :dword :base object :index index :scale 4 :disp (- (* ,offset n-word-bytes) ,lowtag))) (t (make-ea :dword :base object :index index :disp (- (* ,offset n-word-bytes) ,lowtag)))))) (inst cmpxchg ea new-value :lock)) (move value eax)))))(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 immediate unsigned-reg))) (:arg-types ,type tagged-num) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 3 ; pw was 5 (sc-case index (immediate (inst mov value (make-ea :dword :base object :disp (- (* (+ ,offset (tn-value index)) n-word-bytes) ,lowtag)))) (unsigned-reg (inst mov value (make-ea :dword :base object :index index :scale 4 :disp (- (* ,offset n-word-bytes) ,lowtag)))) (t (inst mov value (make-ea :dword :base object :index index :disp (- (* ,offset 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 immediate unsigned-reg))) (:arg-types ,type tagged-num (:constant (constant-displacement ,lowtag sb!vm:n-word-bytes ,offset))) (:info offset) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 3 ; pw was 5 (sc-case index (immediate (inst mov value (make-ea :dword :base object :disp (- (* (+ ,offset (tn-value index) offset) n-word-bytes) ,lowtag)))) (unsigned-reg (inst mov value (make-ea :dword :base object :index index :scale 4 :disp (- (* (+ ,offset offset) n-word-bytes) ,lowtag)))) (t (inst mov value (make-ea :dword :base object :index index :disp (- (* (+ ,offset 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 immediate)) (value :scs ,scs :target result)) (:arg-types ,type tagged-num ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 4 ; was 5 (sc-case index (immediate (inst mov (make-ea :dword :base object :disp (- (* (+ ,offset (tn-value index)) n-word-bytes) ,lowtag)) value)) (t (inst mov (make-ea :dword :base object :index index :disp (- (* ,offset 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 immediate)) (value :scs ,scs :target result)) (:info offset) (:arg-types ,type tagged-num (:constant (constant-displacement ,lowtag sb!vm:n-word-bytes ,offset)) ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 4 ; was 5 (sc-case index (immediate (inst mov (make-ea :dword :base object :disp (- (* (+ ,offset (tn-value index) offset) n-word-bytes) ,lowtag)) value)) (t (inst mov (make-ea :dword :base object :index index :disp (- (* (+ ,offset 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 + -