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 (node-stack-allocate-p node
)))
42 (maybe-pseudo-atomic stack-allocate-p
43 (allocation res
(* (pad-data-block cons-size
) cons-cells
) node
44 stack-allocate-p list-pointer-lowtag
)
46 (dotimes (i (1- cons-cells
))
47 (store-car (tn-ref-tn things
) ptr
)
48 (setf things
(tn-ref-across things
))
49 (inst add ptr
(pad-data-block cons-size
))
50 (storew ptr ptr
(- cons-cdr-slot cons-size
)
52 (store-car (tn-ref-tn things
) ptr
)
54 (setf things
(tn-ref-across things
))
55 (store-car (tn-ref-tn things
) ptr cons-cdr-slot
))
57 (storew nil-value ptr cons-cdr-slot
58 list-pointer-lowtag
)))
59 (aver (null (tn-ref-across things
)))))
60 (move result res
))))))
62 (define-vop (list list-or-list
*)
65 (define-vop (list* list-or-list
*)
68 ;;;; special-purpose inline allocators
71 (define-vop (allocate-vector-on-heap)
72 (:args
(type :scs
(unsigned-reg immediate
))
73 (length :scs
(any-reg immediate
))
74 (words :scs
(any-reg immediate
)))
75 (:results
(result :scs
(descriptor-reg) :from
:load
))
76 (:arg-types positive-fixnum
81 (let ((size (sc-case words
83 (logandc2 (+ (fixnumize (tn-value words
))
84 (+ (1- (ash 1 n-lowtag-bits
))
85 (* vector-data-offset n-word-bytes
)))
88 (inst lea result
(make-ea :byte
:base words
:disp
89 (+ (1- (ash 1 n-lowtag-bits
))
92 (inst and result
(lognot lowtag-mask
))
95 (allocation result size
)
96 (inst lea result
(make-ea :byte
:base result
:disp other-pointer-lowtag
))
99 (aver (typep (tn-value type
) '(unsigned-byte 8)))
100 (storeb (tn-value type
) result
0 other-pointer-lowtag
))
102 (storew type result
0 other-pointer-lowtag
)))
105 (let ((fixnum-length (fixnumize (tn-value length
))))
106 (typecase fixnum-length
108 (storeb fixnum-length result
109 vector-length-slot other-pointer-lowtag
))
111 (storew fixnum-length result
112 vector-length-slot other-pointer-lowtag
)))))
114 (storew length result vector-length-slot other-pointer-lowtag
)))))))
116 (define-vop (allocate-vector-on-stack)
117 (:args
(type :scs
(unsigned-reg immediate
) :to
:save
)
118 (length :scs
(any-reg) :to
:eval
:target zero
)
119 (words :scs
(any-reg) :target ecx
))
120 (:temporary
(:sc any-reg
:offset ecx-offset
:from
(:argument
2)) ecx
)
121 (:temporary
(:sc any-reg
:offset eax-offset
:from
:eval
) zero
)
122 (:temporary
(:sc any-reg
:offset edi-offset
) res
)
123 (:results
(result :scs
(descriptor-reg) :from
:load
))
124 (:arg-types positive-fixnum
127 (:translate allocate-vector
)
131 (inst lea result
(make-ea :byte
:base words
:disp
132 (+ (1- (ash 1 n-lowtag-bits
))
133 (* vector-data-offset n-word-bytes
))))
134 (inst and result
(lognot lowtag-mask
))
135 ;; FIXME: It would be good to check for stack overflow here.
137 (inst shr ecx n-fixnum-tag-bits
)
138 (allocation result result node t other-pointer-lowtag
)
141 (make-ea :byte
:base result
:disp
(- (* vector-data-offset n-word-bytes
)
142 other-pointer-lowtag
)))
145 (aver (typep (tn-value type
) '(unsigned-byte 8)))
146 (storeb (tn-value type
) result
0 other-pointer-lowtag
))
148 (storew type result
0 other-pointer-lowtag
)))
149 (storew length result vector-length-slot other-pointer-lowtag
)
155 (define-vop (make-fdefn)
157 (:translate make-fdefn
)
158 (:args
(name :scs
(descriptor-reg) :to
:eval
))
159 (:results
(result :scs
(descriptor-reg) :from
:argument
))
162 (with-fixed-allocation (result fdefn-widetag fdefn-size node
)
163 (storew name result fdefn-name-slot other-pointer-lowtag
)
164 (storew nil-value result fdefn-fun-slot other-pointer-lowtag
)
165 (storew (make-fixup 'undefined-tramp
:assembly-routine
)
166 result fdefn-raw-addr-slot other-pointer-lowtag
))))
168 (define-vop (make-closure)
169 (:args
(function :to
:save
:scs
(descriptor-reg)))
170 (:info length stack-allocate-p
)
171 (:temporary
(:sc any-reg
) temp
)
172 (:results
(result :scs
(descriptor-reg)))
175 (maybe-pseudo-atomic stack-allocate-p
176 (let ((size (+ length closure-info-offset
)))
177 (allocation result
(pad-data-block size
) node
180 (storew (logior (ash (1- size
) n-widetag-bits
) closure-header-widetag
)
181 result
0 fun-pointer-lowtag
))
182 (loadw temp function closure-fun-slot fun-pointer-lowtag
)
183 (storew temp result closure-fun-slot fun-pointer-lowtag
))))
185 ;;; The compiler likes to be able to directly make value cells.
186 (define-vop (make-value-cell)
187 (:args
(value :scs
(descriptor-reg any-reg
) :to
:result
))
188 (:results
(result :scs
(descriptor-reg) :from
:eval
))
189 (:info stack-allocate-p
)
192 (with-fixed-allocation
193 (result value-cell-widetag value-cell-size node stack-allocate-p
)
194 (storew value result value-cell-value-slot other-pointer-lowtag
))))
196 ;;;; automatic allocators for primitive objects
198 (define-vop (make-unbound-marker)
200 (:results
(result :scs
(descriptor-reg any-reg
)))
202 (inst mov result unbound-marker-widetag
)))
204 (define-vop (make-funcallable-instance-tramp)
206 (:results
(result :scs
(any-reg)))
208 (inst lea result
(make-fixup 'funcallable-instance-tramp
:assembly-routine
))))
210 (define-vop (fixed-alloc)
212 (:info name words type lowtag stack-allocate-p
)
214 (:results
(result :scs
(descriptor-reg)))
217 ;; We special case the allocation of conses, because they're
218 ;; extremely common and because the pseudo-atomic sequence on x86
219 ;; is relatively heavyweight. However, if the user asks for top
220 ;; speed, we accomodate him. The primary reason that we don't
221 ;; also check for (< SPEED SPACE) is because we want the space
222 ;; savings that these out-of-line allocation routines bring whilst
223 ;; compiling SBCL itself. --njf, 2006-07-08
224 (if (and (not stack-allocate-p
)
225 (= lowtag list-pointer-lowtag
) (policy node
(< speed
3)))
227 ;; FIXME: out-of-line dx-allocation
228 #.
(loop for offset in
*dword-regs
*
230 ',(intern (format nil
"ALLOCATE-CONS-TO-~A"
231 (svref *dword-register-names
*
232 offset
)))) into cases
233 finally
(return `(case (tn-offset result
)
236 (inst call
(make-fixup dst
:assembly-routine
)))
237 (maybe-pseudo-atomic stack-allocate-p
238 (allocation result
(pad-data-block words
) node stack-allocate-p lowtag
)
240 (storew (logior (ash (1- words
) n-widetag-bits
) type
)
245 (define-vop (var-alloc)
246 (:args
(extra :scs
(any-reg)))
247 (:arg-types positive-fixnum
)
248 (:info name words type lowtag
)
250 (:results
(result :scs
(descriptor-reg) :from
(:eval
1)))
251 (:temporary
(:sc any-reg
:from
:eval
:to
(:eval
1)) bytes
)
252 (:temporary
(:sc any-reg
:from
:eval
:to
:result
) header
)
256 (make-ea :dword
:base extra
:disp
(* (1+ words
) n-word-bytes
)))
257 (inst mov header bytes
)
258 (inst shl header
(- n-widetag-bits
2)) ; w+1 to length field
259 (inst lea header
; (w-1 << 8) | type
260 (make-ea :dword
:base header
:disp
(+ (ash -
2 n-widetag-bits
) type
)))
261 (inst and bytes
(lognot lowtag-mask
))
263 (allocation result bytes node
)
264 (inst lea result
(make-ea :byte
:base result
:disp lowtag
))
265 (storew header result
0 lowtag
))))