1 ;;;; allocation VOPs for the x86
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
15 (defoptimizer (list stack-allocate-result) ((&rest args))
17 (defoptimizer (list* stack-allocate-result) ((&rest args))
18 (not (null (rest args))))
20 (define-vop (list-or-list*)
21 (:args (things :more t))
22 (:temporary (:sc unsigned-reg) ptr temp)
23 (:temporary (:sc unsigned-reg :to (:result 0) :target result) res)
25 (:results (result :scs (descriptor-reg)))
31 ;; (move result nil-value)
32 (inst mov result nil-value))
34 (move result (tn-ref-tn things)))
37 ((store-car (tn list &optional (slot cons-car-slot))
40 ((any-reg descriptor-reg) ,tn)
44 (storew reg ,list ,slot list-pointer-lowtag))))
45 (let ((cons-cells (if star (1- num) num)))
47 (allocation res (* (pad-data-block cons-size) cons-cells) node
48 (awhen (sb!c::node-lvar node) (sb!c::lvar-dynamic-extent it)))
50 (make-ea :byte :base res :disp list-pointer-lowtag))
52 (dotimes (i (1- cons-cells))
53 (store-car (tn-ref-tn things) ptr)
54 (setf things (tn-ref-across things))
55 (inst add ptr (pad-data-block cons-size))
56 (storew ptr ptr (- cons-cdr-slot cons-size)
58 (store-car (tn-ref-tn things) ptr)
60 (setf things (tn-ref-across things))
61 (store-car (tn-ref-tn things) ptr cons-cdr-slot))
63 (storew nil-value ptr cons-cdr-slot
64 list-pointer-lowtag)))
65 (aver (null (tn-ref-across things)))))
66 (move result res))))))
68 (define-vop (list list-or-list*)
71 (define-vop (list* list-or-list*)
74 ;;;; special-purpose inline allocators
75 (defoptimizer (allocate-vector stack-allocate-result)
76 ((type length words) node)
77 (ecase (policy node sb!c::stack-allocate-vector)
80 ;; a vector object should fit in one page
81 (values-subtypep (sb!c::lvar-derived-type words)
83 (specifier-type `(integer 0 ,(- (/ *backend-page-size*
85 vector-data-offset))))))
88 (define-vop (allocate-vector)
89 (:args (type :scs (unsigned-reg))
90 (length :scs (any-reg))
91 (words :scs (any-reg)))
92 (:results (result :scs (descriptor-reg) :from :load))
93 (:arg-types positive-fixnum
96 (:translate allocate-vector)
100 (inst lea result (make-ea :byte :base words :disp
101 (+ (1- (ash 1 n-lowtag-bits))
102 (* vector-data-offset n-word-bytes))))
103 (inst and result (lognot lowtag-mask))
104 (let ((stack-allocate-p (awhen (sb!c::node-lvar node)
105 (sb!c::lvar-dynamic-extent it))))
106 (maybe-pseudo-atomic stack-allocate-p
107 ;; FIXME: It would be good to check for stack overflow here.
108 (allocation result result node stack-allocate-p)
109 (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
110 (storew type result 0 other-pointer-lowtag)
111 (storew length result vector-length-slot other-pointer-lowtag)))))
113 (define-vop (allocate-code-object)
114 (:args (boxed-arg :scs (any-reg) :target boxed)
115 (unboxed-arg :scs (any-reg) :target unboxed))
116 (:results (result :scs (descriptor-reg) :from :eval))
117 (:temporary (:sc unsigned-reg :from (:argument 0)) boxed)
118 (:temporary (:sc unsigned-reg :from (:argument 1)) unboxed)
121 (move boxed boxed-arg)
122 (inst add boxed (fixnumize (1+ code-trace-table-offset-slot)))
123 (inst and boxed (lognot lowtag-mask))
124 (move unboxed unboxed-arg)
125 (inst shr unboxed word-shift)
126 (inst add unboxed lowtag-mask)
127 (inst and unboxed (lognot lowtag-mask))
128 (inst mov result boxed)
129 (inst add result unboxed)
131 (allocation result result node)
132 (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
133 (inst shl boxed (- n-widetag-bits word-shift))
134 (inst or boxed code-header-widetag)
135 (storew boxed result 0 other-pointer-lowtag)
136 (storew unboxed result code-code-size-slot other-pointer-lowtag)
137 (storew nil-value result code-entry-points-slot other-pointer-lowtag))
138 (storew nil-value result code-debug-info-slot other-pointer-lowtag)))
140 (define-vop (make-fdefn)
142 (:translate make-fdefn)
143 (:args (name :scs (descriptor-reg) :to :eval))
144 (:results (result :scs (descriptor-reg) :from :argument))
147 (with-fixed-allocation (result fdefn-widetag fdefn-size node)
148 (storew name result fdefn-name-slot other-pointer-lowtag)
149 (storew nil-value result fdefn-fun-slot other-pointer-lowtag)
150 (storew (make-fixup "undefined_tramp" :foreign)
151 result fdefn-raw-addr-slot other-pointer-lowtag))))
153 (define-vop (make-closure)
154 (:args (function :to :save :scs (descriptor-reg)))
155 (:info length stack-allocate-p)
156 (:temporary (:sc any-reg) temp)
157 (:results (result :scs (descriptor-reg)))
160 (maybe-pseudo-atomic stack-allocate-p
161 (let ((size (+ length closure-info-offset)))
162 (allocation result (pad-data-block size) node
165 (make-ea :byte :base result :disp fun-pointer-lowtag))
166 (storew (logior (ash (1- size) n-widetag-bits) closure-header-widetag)
167 result 0 fun-pointer-lowtag))
168 (loadw temp function closure-fun-slot fun-pointer-lowtag)
169 (storew temp result closure-fun-slot fun-pointer-lowtag))))
171 ;;; The compiler likes to be able to directly make value cells.
172 (define-vop (make-value-cell)
173 (:args (value :scs (descriptor-reg any-reg) :to :result))
174 (:results (result :scs (descriptor-reg) :from :eval))
177 (with-fixed-allocation
178 (result value-cell-header-widetag value-cell-size node))
179 (storew value result value-cell-value-slot other-pointer-lowtag)))
181 ;;;; automatic allocators for primitive objects
183 (define-vop (make-unbound-marker)
185 (:results (result :scs (any-reg)))
187 (inst mov result unbound-marker-widetag)))
189 (define-vop (fixed-alloc)
191 (:info name words type lowtag)
193 (:results (result :scs (descriptor-reg)))
197 (allocation result (pad-data-block words) node)
198 (inst lea result (make-ea :byte :base result :disp lowtag))
200 (storew (logior (ash (1- words) n-widetag-bits) type)
205 (define-vop (var-alloc)
206 (:args (extra :scs (any-reg)))
207 (:arg-types positive-fixnum)
208 (:info name words type lowtag)
210 (:results (result :scs (descriptor-reg) :from (:eval 1)))
211 (:temporary (:sc any-reg :from :eval :to (:eval 1)) bytes)
212 (:temporary (:sc any-reg :from :eval :to :result) header)
216 (make-ea :dword :base extra :disp (* (1+ words) n-word-bytes)))
217 (inst mov header bytes)
218 (inst shl header (- n-widetag-bits 2)) ; w+1 to length field
219 (inst lea header ; (w-1 << 8) | type
220 (make-ea :dword :base header :disp (+ (ash -2 n-widetag-bits) type)))
221 (inst and bytes (lognot lowtag-mask))
223 (allocation result bytes node)
224 (inst lea result (make-ea :byte :base result :disp lowtag))
225 (storew header result 0 lowtag))))