1 ;;;; allocation VOPs for the x86-64
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))
74 (length :scs
(any-reg))
75 (words :scs
(any-reg)))
76 (:results
(result :scs
(descriptor-reg) :from
:load
))
77 (:arg-types positive-fixnum
82 (inst lea result
(make-ea :byte
:base words
:disp
83 (+ (1- (ash 1 n-lowtag-bits
))
84 (* vector-data-offset n-word-bytes
))))
85 (inst and result
(lognot lowtag-mask
))
87 (allocation result result
)
88 (inst lea result
(make-ea :byte
:base result
:disp other-pointer-lowtag
))
89 (storew type result
0 other-pointer-lowtag
)
90 (storew length result vector-length-slot other-pointer-lowtag
))))
92 (define-vop (allocate-vector-on-stack)
93 (:args
(type :scs
(unsigned-reg))
94 (length :scs
(any-reg))
95 (words :scs
(any-reg) :target ecx
))
96 (:temporary
(:sc any-reg
:offset ecx-offset
:from
(:argument
2)) ecx
)
97 (:temporary
(:sc any-reg
:offset eax-offset
:from
(:argument
2)) zero
)
98 (:temporary
(:sc any-reg
:offset edi-offset
:from
(:argument
0)) res
)
99 (:results
(result :scs
(descriptor-reg) :from
:load
))
100 (:arg-types positive-fixnum
103 (:translate allocate-vector
)
107 (inst lea result
(make-ea :byte
:base words
:disp
108 (+ (1- (ash 1 n-lowtag-bits
))
109 (* vector-data-offset n-word-bytes
))))
110 (inst and result
(lognot lowtag-mask
))
111 ;; FIXME: It would be good to check for stack overflow here.
113 (inst shr ecx n-fixnum-tag-bits
)
114 (allocation result result node t other-pointer-lowtag
)
117 (make-ea :byte
:base result
:disp
(- (* vector-data-offset n-word-bytes
)
118 other-pointer-lowtag
)))
119 (storew type result
0 other-pointer-lowtag
)
120 (storew length result vector-length-slot other-pointer-lowtag
)
128 (define-vop (allocate-code-object)
129 (:args
(boxed-arg :scs
(any-reg) :target boxed
)
130 (unboxed-arg :scs
(any-reg) :target unboxed
))
131 (:results
(result :scs
(descriptor-reg) :from
:eval
))
132 (:temporary
(:sc unsigned-reg
:from
(:argument
0)) boxed
)
133 (:temporary
(:sc unsigned-reg
:from
(:argument
1)) unboxed
)
136 (move boxed boxed-arg
)
137 (inst add boxed
(fixnumize (1+ code-trace-table-offset-slot
)))
138 (inst and boxed
(lognot lowtag-mask
))
139 (move unboxed unboxed-arg
)
140 (inst shr unboxed word-shift
)
141 (inst add unboxed lowtag-mask
)
142 (inst and unboxed
(lognot lowtag-mask
))
143 (inst mov result boxed
)
144 (inst add result unboxed
)
146 (allocation result result node
)
147 (inst lea result
(make-ea :byte
:base result
:disp other-pointer-lowtag
))
148 (inst shl boxed
(- n-widetag-bits word-shift
))
149 (inst or boxed code-header-widetag
)
150 (storew boxed result
0 other-pointer-lowtag
)
151 (storew unboxed result code-code-size-slot other-pointer-lowtag
)
152 (storew nil-value result code-entry-points-slot other-pointer-lowtag
))
153 (storew nil-value result code-debug-info-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" :foreign
)
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 stack-allocate-p
179 (storew (logior (ash (1- size
) n-widetag-bits
) closure-header-widetag
)
180 result
0 fun-pointer-lowtag
))
181 (loadw temp function closure-fun-slot fun-pointer-lowtag
)
182 (storew temp result closure-fun-slot fun-pointer-lowtag
))))
184 ;;; The compiler likes to be able to directly make value cells.
185 (define-vop (make-value-cell)
186 (:args
(value :scs
(descriptor-reg any-reg
) :to
:result
))
187 (:results
(result :scs
(descriptor-reg) :from
:eval
))
188 (:info stack-allocate-p
)
191 (with-fixed-allocation
192 (result value-cell-header-widetag value-cell-size node stack-allocate-p
)
193 (storew value result value-cell-value-slot other-pointer-lowtag
))))
195 ;;;; automatic allocators for primitive objects
197 (define-vop (make-unbound-marker)
199 (:results
(result :scs
(any-reg)))
201 (inst mov result unbound-marker-widetag
)))
203 (define-vop (make-funcallable-instance-tramp)
205 (:results
(result :scs
(any-reg)))
207 (inst lea result
(make-fixup "funcallable_instance_tramp" :foreign
))))
209 (define-vop (fixed-alloc)
211 (:info name words type lowtag stack-allocate-p
)
213 (:results
(result :scs
(descriptor-reg)))
216 (maybe-pseudo-atomic stack-allocate-p
217 (allocation result
(pad-data-block words
) node stack-allocate-p lowtag
)
219 (storew (logior (ash (1- words
) n-widetag-bits
) type
)
224 (define-vop (var-alloc)
225 (:args
(extra :scs
(any-reg)))
226 (:arg-types positive-fixnum
)
227 (:info name words type lowtag
)
229 (:results
(result :scs
(descriptor-reg) :from
(:eval
1)))
230 (:temporary
(:sc any-reg
:from
:eval
:to
(:eval
1)) bytes
)
231 (:temporary
(:sc any-reg
:from
:eval
:to
:result
) header
)
235 (make-ea :qword
:base extra
:disp
(* (1+ words
) n-word-bytes
)))
236 (inst mov header bytes
)
237 (inst shl header
(- n-widetag-bits
3)) ; w+1 to length field
238 (inst lea header
; (w-1 << 8) | type
239 (make-ea :qword
:base header
:disp
(+ (ash -
2 n-widetag-bits
) type
)))
240 (inst and bytes
(lognot lowtag-mask
))
242 (allocation result bytes node
)
243 (inst lea result
(make-ea :byte
:base result
:disp lowtag
))
244 (storew header result
0 lowtag
))))
246 (define-vop (%make-symbol
)
248 (:translate %make-symbol
)
249 (:args
(name :scs
(descriptor-reg) :to
:eval
))
250 (:temporary
(:sc unsigned-reg
:from
:eval
) temp
)
251 (:results
(result :scs
(descriptor-reg) :from
:argument
))
254 (with-fixed-allocation (result symbol-header-widetag symbol-size node
)
255 (storew name result symbol-name-slot other-pointer-lowtag
)
256 (storew unbound-marker-widetag
259 other-pointer-lowtag
)
260 ;; Set up a random hash value for the symbol. Perhaps the object
261 ;; address could be used for even faster and smaller code!
262 ;; FIXME: We don't mind the symbol hash not being repeatable, so
263 ;; we might as well add in the object address here, too. (Adding entropy
264 ;; is good, even if ANSI doesn't understand that.)
266 (make-fixup "fast_random_state" :foreign
)
268 (inst add temp
12345)
269 (inst mov
(make-fixup "fast_random_state" :foreign
)
271 ;; We want a positive fixnum for the hash value, so discard the LS bits.
273 ;; FIXME: OK, who wants to tell me (CSR) why these two
274 ;; instructions aren't replaced by (INST AND TEMP #x8FFFFFFC)?
275 ;; Are the following two instructions actually faster? Does the
276 ;; difference in behaviour really matter?
278 (inst and temp
#xfffffffc
)
279 (storew temp result symbol-hash-slot other-pointer-lowtag
)
280 (storew nil-value result symbol-plist-slot other-pointer-lowtag
)
281 (storew nil-value result symbol-package-slot other-pointer-lowtag
))))