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.
14 ;;;; CONS, LIST and LIST*
15 (define-vop (list-or-list*)
16 (:args
(things :more t
))
17 (:temporary
(:sc unsigned-reg
) ptr temp
)
18 (:temporary
(:sc unsigned-reg
:to
(:result
0) :target result
) res
)
20 (:results
(result :scs
(descriptor-reg)))
26 ;; (move result nil-value)
27 (inst mov result nil-value
))
29 (move result
(tn-ref-tn things
)))
32 ((store-car (tn list
&optional
(slot cons-car-slot
))
35 ((any-reg descriptor-reg
) ,tn
)
39 (storew reg
,list
,slot list-pointer-lowtag
))))
40 (let ((cons-cells (if star
(1- num
) num
))
41 (stack-allocate-p (awhen (sb!c
::node-lvar node
)
42 (sb!c
::lvar-dynamic-extent it
))))
43 (maybe-pseudo-atomic stack-allocate-p
44 (allocation res
(* (pad-data-block cons-size
) cons-cells
) node
45 stack-allocate-p list-pointer-lowtag
)
47 (dotimes (i (1- cons-cells
))
48 (store-car (tn-ref-tn things
) ptr
)
49 (setf things
(tn-ref-across things
))
50 (inst add ptr
(pad-data-block cons-size
))
51 (storew ptr ptr
(- cons-cdr-slot cons-size
)
53 (store-car (tn-ref-tn things
) ptr
)
55 (setf things
(tn-ref-across things
))
56 (store-car (tn-ref-tn things
) ptr cons-cdr-slot
))
58 (storew nil-value ptr cons-cdr-slot
59 list-pointer-lowtag
)))
60 (aver (null (tn-ref-across things
)))))
61 (move result res
))))))
63 (define-vop (list list-or-list
*)
66 (define-vop (list* list-or-list
*)
69 ;;;; special-purpose inline allocators
72 (define-vop (allocate-vector-on-heap)
73 (:args
(type :scs
(unsigned-reg immediate
))
74 (length :scs
(any-reg immediate
))
75 (words :scs
(any-reg immediate
)))
76 (:results
(result :scs
(descriptor-reg) :from
:load
))
77 (:arg-types positive-fixnum
82 (let ((size (sc-case words
84 (logandc2 (+ (fixnumize (tn-value words
))
85 (+ (1- (ash 1 n-lowtag-bits
))
86 (* vector-data-offset n-word-bytes
)))
89 (inst lea result
(make-ea :byte
:base words
:disp
90 (+ (1- (ash 1 n-lowtag-bits
))
93 (inst and result
(lognot lowtag-mask
))
96 (allocation result size
)
97 (inst lea result
(make-ea :byte
:base result
:disp other-pointer-lowtag
))
100 (aver (typep (tn-value type
) '(unsigned-byte 8)))
101 (storeb (tn-value type
) result
0 other-pointer-lowtag
))
103 (storew type result
0 other-pointer-lowtag
)))
106 (let ((fixnum-length (fixnumize (tn-value length
))))
107 (typecase fixnum-length
109 (storeb fixnum-length result
110 vector-length-slot other-pointer-lowtag
))
112 (storew fixnum-length result
113 vector-length-slot other-pointer-lowtag
)))))
115 (storew length result vector-length-slot other-pointer-lowtag
)))))))
117 (define-vop (allocate-vector-on-stack)
118 (:args
(type :scs
(unsigned-reg immediate
) :to
:save
)
119 (length :scs
(any-reg) :to
:eval
:target zero
)
120 (words :scs
(any-reg) :target ecx
))
121 (:temporary
(:sc any-reg
:offset ecx-offset
:from
(:argument
2)) ecx
)
122 (:temporary
(:sc any-reg
:offset eax-offset
:from
:eval
) zero
)
123 (:temporary
(:sc any-reg
:offset edi-offset
) res
)
124 (:results
(result :scs
(descriptor-reg) :from
:load
))
125 (:arg-types positive-fixnum
128 (:translate allocate-vector
)
132 (inst lea result
(make-ea :byte
:base words
:disp
133 (+ (1- (ash 1 n-lowtag-bits
))
134 (* vector-data-offset n-word-bytes
))))
135 (inst and result
(lognot lowtag-mask
))
136 ;; FIXME: It would be good to check for stack overflow here.
138 (inst shr ecx n-fixnum-tag-bits
)
139 (allocation result result node t other-pointer-lowtag
)
142 (make-ea :byte
:base result
:disp
(- (* vector-data-offset n-word-bytes
)
143 other-pointer-lowtag
)))
146 (aver (typep (tn-value type
) '(unsigned-byte 8)))
147 (storeb (tn-value type
) result
0 other-pointer-lowtag
))
149 (storew type result
0 other-pointer-lowtag
)))
150 (storew length result vector-length-slot other-pointer-lowtag
)
156 (define-vop (make-fdefn)
158 (:translate make-fdefn
)
159 (:args
(name :scs
(descriptor-reg) :to
:eval
))
160 (:results
(result :scs
(descriptor-reg) :from
:argument
))
163 (with-fixed-allocation (result fdefn-widetag fdefn-size node
)
164 (storew name result fdefn-name-slot other-pointer-lowtag
)
165 (storew nil-value result fdefn-fun-slot other-pointer-lowtag
)
166 (storew (make-fixup "undefined_tramp" :foreign
)
167 result fdefn-raw-addr-slot other-pointer-lowtag
))))
169 (define-vop (make-closure)
170 (:args
(function :to
:save
:scs
(descriptor-reg)))
171 (:info length stack-allocate-p
)
172 (:temporary
(:sc any-reg
) temp
)
173 (:results
(result :scs
(descriptor-reg)))
176 (maybe-pseudo-atomic stack-allocate-p
177 (let ((size (+ length closure-info-offset
)))
178 (allocation result
(pad-data-block size
) node
181 (storew (logior (ash (1- size
) n-widetag-bits
) closure-header-widetag
)
182 result
0 fun-pointer-lowtag
))
183 (loadw temp function closure-fun-slot fun-pointer-lowtag
)
184 (storew temp result closure-fun-slot fun-pointer-lowtag
))))
186 ;;; The compiler likes to be able to directly make value cells.
187 (define-vop (make-value-cell)
188 (:args
(value :scs
(descriptor-reg any-reg
) :to
:result
))
189 (:results
(result :scs
(descriptor-reg) :from
:eval
))
190 (:info stack-allocate-p
)
193 (with-fixed-allocation
194 (result value-cell-header-widetag value-cell-size node stack-allocate-p
)
195 (storew value result value-cell-value-slot other-pointer-lowtag
))))
197 ;;;; automatic allocators for primitive objects
199 (define-vop (make-unbound-marker)
201 (:results
(result :scs
(any-reg)))
203 (inst mov result unbound-marker-widetag
)))
205 (define-vop (make-funcallable-instance-tramp)
207 (:results
(result :scs
(any-reg)))
209 (inst lea result
(make-fixup "funcallable_instance_tramp" :foreign
))))
211 (define-vop (fixed-alloc)
213 (:info name words type lowtag stack-allocate-p
)
215 (:results
(result :scs
(descriptor-reg)))
218 ;; We special case the allocation of conses, because they're
219 ;; extremely common and because the pseudo-atomic sequence on x86
220 ;; is relatively heavyweight. However, if the user asks for top
221 ;; speed, we accomodate him. The primary reason that we don't
222 ;; also check for (< SPEED SPACE) is because we want the space
223 ;; savings that these out-of-line allocation routines bring whilst
224 ;; compiling SBCL itself. --njf, 2006-07-08
225 (if (and (not stack-allocate-p
)
226 (= lowtag list-pointer-lowtag
) (policy node
(< speed
3)))
228 ;; FIXME: out-of-line dx-allocation
229 #.
(loop for offset in
*dword-regs
*
231 ',(intern (format nil
"ALLOCATE-CONS-TO-~A"
232 (svref *dword-register-names
*
233 offset
)))) into cases
234 finally
(return `(case (tn-offset result
)
237 (inst call
(make-fixup dst
:assembly-routine
)))
238 (maybe-pseudo-atomic stack-allocate-p
239 (allocation result
(pad-data-block words
) node stack-allocate-p lowtag
)
241 (storew (logior (ash (1- words
) n-widetag-bits
) type
)
246 (define-vop (var-alloc)
247 (:args
(extra :scs
(any-reg)))
248 (:arg-types positive-fixnum
)
249 (:info name words type lowtag
)
251 (:results
(result :scs
(descriptor-reg) :from
(:eval
1)))
252 (:temporary
(:sc any-reg
:from
:eval
:to
(:eval
1)) bytes
)
253 (:temporary
(:sc any-reg
:from
:eval
:to
:result
) header
)
257 (make-ea :dword
:base extra
:disp
(* (1+ words
) n-word-bytes
)))
258 (inst mov header bytes
)
259 (inst shl header
(- n-widetag-bits
2)) ; w+1 to length field
260 (inst lea header
; (w-1 << 8) | type
261 (make-ea :dword
:base header
:disp
(+ (ash -
2 n-widetag-bits
) type
)))
262 (inst and bytes
(lognot lowtag-mask
))
264 (allocation result bytes node
)
265 (inst lea result
(make-ea :byte
:base result
:disp lowtag
))
266 (storew header result
0 lowtag
))))