📄 macros.lisp
字号:
(dotimes (i (length ,vector)) (inst byte (aref ,vector i)))) (emit-alignment word-shift)))))(defmacro error-call (vop error-code &rest values) #!+sb-doc "Cause an error. ERROR-CODE is the error to cause." (cons 'progn (emit-error-break vop error-trap error-code values)))(defmacro cerror-call (vop label error-code &rest values) #!+sb-doc "Cause a continuable error. If the error is continued, execution resumes at LABEL." `(progn (without-scheduling () (inst b ,label) ,@(emit-error-break vop cerror-trap error-code values))))(defmacro 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) (error-call ,vop ,error-code ,@values) start-lab)))(defmacro generate-cerror-code (vop error-code &rest values) #!+sb-doc "Generate-CError-Code Error-code Value* Emit code for a continuable error with the specified Error-Code and context Values. If the error is continued, execution resumes after the GENERATE-CERROR-CODE form." (with-unique-names (continue error) `(let ((,continue (gen-label))) (emit-label ,continue) (assemble (*elsewhere*) (let ((,error (gen-label))) (emit-label ,error) (cerror-call ,vop ,continue ,error-code ,@values) ,error)))));;;; PSEUDO-ATOMIC;;; handy macro for making sequences look atomic(defmacro pseudo-atomic ((flag-tn &key (extra 0)) &rest forms) `(progn (aver (= (tn-offset ,flag-tn) nl4-offset)) (aver (not (minusp ,extra))) (without-scheduling () (inst li ,flag-tn ,extra) (inst addu alloc-tn 1)) ,@forms (without-scheduling () (let ((label (gen-label))) (inst bgez ,flag-tn label) (inst addu alloc-tn (1- ,extra)) (inst break 0 16) (emit-label label)))));;;; memory accessor vop generators(deftype load/store-index (scale lowtag min-offset &optional (max-offset min-offset)) `(integer ,(- (truncate (+ (ash 1 16) (* min-offset n-word-bytes) (- lowtag)) scale)) ,(truncate (- (+ (1- (ash 1 16)) lowtag) (* max-offset n-word-bytes)) scale)))(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) (:temporary (:scs (interior-reg)) lip) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 5 (inst addu lip object index) (loadw value lip ,offset ,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 4 (loadw value object (+ ,offset index) ,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) (:temporary (:scs (interior-reg)) lip) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 2 (inst addu lip object index) (storew value lip ,offset ,lowtag) (move result value))) (define-vop (,(symbolicate name "-C")) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (value :scs ,scs)) (: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 1 (storew value object (+ ,offset index) ,lowtag) (move result value)))))(defmacro define-partial-reffer (name type size signed offset lowtag scs el-type &optional translate) (let ((scale (ecase size (:byte 1) (:short 2)))) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (unsigned-reg))) (:arg-types ,type positive-fixnum) (:results (value :scs ,scs)) (:result-types ,el-type) (:temporary (:scs (interior-reg)) lip) (:generator 5 (inst addu lip object index) ,@(when (eq size :short) '((inst addu lip index))) (inst ,(ecase size (:byte (if signed 'lb 'lbu)) (:short (if signed 'lh 'lhu))) value lip (- (* ,offset n-word-bytes) ,lowtag)) (inst nop))) (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 ,scale ,(eval lowtag) ,(eval offset)))) (:results (value :scs ,scs)) (:result-types ,el-type) (:generator 4 (inst ,(ecase size (:byte (if signed 'lb 'lbu)) (:short (if signed 'lh 'lhu))) value object (- (+ (* ,offset n-word-bytes) (* index ,scale)) ,lowtag)) (inst nop))))))(defmacro define-partial-setter (name type size offset lowtag scs el-type &optional translate) (let ((scale (ecase size (:byte 1) (:short 2)))) `(progn (define-vop (,name) ,@(when translate `((:translate ,translate))) (:policy :fast-safe) (:args (object :scs (descriptor-reg)) (index :scs (unsigned-reg)) (value :scs ,scs :target result)) (:arg-types ,type positive-fixnum ,el-type) (:temporary (:scs (interior-reg)) lip) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 5 (inst addu lip object index) ,@(when (eq size :short) '((inst addu lip index))) (inst ,(ecase size (:byte 'sb) (:short 'sh)) value lip (- (* ,offset n-word-bytes) ,lowtag)) (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 ,scale ,(eval lowtag) ,(eval offset))) ,el-type) (:results (result :scs ,scs)) (:result-types ,el-type) (:generator 4 (inst ,(ecase size (:byte 'sb) (:short 'sh)) value object (- (+ (* ,offset n-word-bytes) (* index ,scale)) ,lowtag)) (move result value))))))(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 triggergarbage collection. This is currently implemented by disabling GC" (declare (ignore objects)) ;should we eval these for side-effect? `(without-gcing ,@body))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -