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.
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)
49 (sb!c::lvar-dynamic-extent it)))
51 (make-ea :byte :base res :disp list-pointer-lowtag))
53 (dotimes (i (1- cons-cells))
54 (store-car (tn-ref-tn things) ptr)
55 (setf things (tn-ref-across things))
56 (inst add ptr (pad-data-block cons-size))
57 (storew ptr ptr (- cons-cdr-slot cons-size)
59 (store-car (tn-ref-tn things) ptr)
61 (setf things (tn-ref-across things))
62 (store-car (tn-ref-tn things) ptr cons-cdr-slot))
64 (storew nil-value ptr cons-cdr-slot
65 list-pointer-lowtag)))
66 (aver (null (tn-ref-across things)))))
67 (move result res))))))
69 (define-vop (list list-or-list*)
72 (define-vop (list* list-or-list*)
75 ;;;; special-purpose inline allocators
77 (define-vop (allocate-code-object)
78 (:args (boxed-arg :scs (any-reg) :target boxed)
79 (unboxed-arg :scs (any-reg) :target unboxed))
80 (:results (result :scs (descriptor-reg) :from :eval))
81 (:temporary (:sc unsigned-reg :from (:argument 0)) boxed)
82 (:temporary (:sc unsigned-reg :from (:argument 1)) unboxed)
85 (move boxed boxed-arg)
86 (inst add boxed (fixnumize (1+ code-trace-table-offset-slot)))
87 (inst and boxed (lognot lowtag-mask))
88 (move unboxed unboxed-arg)
89 (inst shr unboxed word-shift)
90 (inst add unboxed lowtag-mask)
91 (inst and unboxed (lognot lowtag-mask))
92 (inst mov result boxed)
93 (inst add result unboxed)
95 (allocation result result node)
96 (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
97 (inst shl boxed (- n-widetag-bits word-shift))
98 (inst or boxed code-header-widetag)
99 (storew boxed result 0 other-pointer-lowtag)
100 (storew unboxed result code-code-size-slot other-pointer-lowtag)
101 (storew nil-value result code-entry-points-slot other-pointer-lowtag))
102 (storew nil-value result code-debug-info-slot other-pointer-lowtag)))
104 (define-vop (make-fdefn)
106 (:translate make-fdefn)
107 (:args (name :scs (descriptor-reg) :to :eval))
108 (:results (result :scs (descriptor-reg) :from :argument))
111 (with-fixed-allocation (result fdefn-widetag fdefn-size node)
112 (storew name result fdefn-name-slot other-pointer-lowtag)
113 (storew nil-value result fdefn-fun-slot other-pointer-lowtag)
114 (storew (make-fixup "undefined_tramp" :foreign)
115 result fdefn-raw-addr-slot other-pointer-lowtag))))
117 (define-vop (make-closure)
118 (:args (function :to :save :scs (descriptor-reg)))
119 (:info length stack-allocate-p)
120 (:temporary (:sc any-reg) temp)
121 (:results (result :scs (descriptor-reg)))
124 (maybe-pseudo-atomic stack-allocate-p
125 (let ((size (+ length closure-info-offset)))
126 (allocation result (pad-data-block size) node stack-allocate-p)
128 (make-ea :byte :base result :disp fun-pointer-lowtag))
129 (storew (logior (ash (1- size) n-widetag-bits) closure-header-widetag)
130 result 0 fun-pointer-lowtag))
131 (storew result result closure-self-slot fun-pointer-lowtag)
132 (loadw temp function closure-fun-slot fun-pointer-lowtag)
133 (storew temp result closure-fun-slot fun-pointer-lowtag))))
135 ;;; The compiler likes to be able to directly make value cells.
136 (define-vop (make-value-cell)
137 (:args (value :scs (descriptor-reg any-reg) :to :result))
138 (:results (result :scs (descriptor-reg) :from :eval))
141 (with-fixed-allocation
142 (result value-cell-header-widetag value-cell-size node)
143 (storew value result value-cell-value-slot other-pointer-lowtag))))
145 ;;;; automatic allocators for primitive objects
147 (define-vop (make-unbound-marker)
149 (:results (result :scs (any-reg)))
151 (inst mov result unbound-marker-widetag)))
153 (define-vop (fixed-alloc)
155 (:info name words type lowtag)
157 (:results (result :scs (descriptor-reg)))
161 (allocation result (pad-data-block words) node)
162 (inst lea result (make-ea :byte :base result :disp lowtag))
164 (storew (logior (ash (1- words) n-widetag-bits) type)
169 (define-vop (var-alloc)
170 (:args (extra :scs (any-reg)))
171 (:arg-types positive-fixnum)
172 (:info name words type lowtag)
174 (:results (result :scs (descriptor-reg) :from (:eval 1)))
175 (:temporary (:sc any-reg :from :eval :to (:eval 1)) bytes)
176 (:temporary (:sc any-reg :from :eval :to :result) header)
180 (make-ea :qword :base extra :disp (* (1+ words) n-word-bytes)))
181 (inst mov header bytes)
182 (inst shl header (- n-widetag-bits 3)) ; w+1 to length field
183 (inst lea header ; (w-1 << 8) | type
184 (make-ea :qword :base header :disp (+ (ash -2 n-widetag-bits) type)))
185 (inst and bytes (lognot lowtag-mask))
187 (allocation result bytes node)
188 (inst lea result (make-ea :byte :base result :disp lowtag))
189 (storew header result 0 lowtag))))
191 (define-vop (%make-symbol)
193 (:translate %make-symbol)
194 (:args (name :scs (descriptor-reg) :to :eval))
195 (:temporary (:sc unsigned-reg :from :eval) temp)
196 (:results (result :scs (descriptor-reg) :from :argument))
199 (with-fixed-allocation (result symbol-header-widetag symbol-size node)
200 (storew name result symbol-name-slot other-pointer-lowtag)
201 (storew unbound-marker-widetag
204 other-pointer-lowtag)
205 ;; Set up a random hash value for the symbol. Perhaps the object
206 ;; address could be used for even faster and smaller code!
207 ;; FIXME: We don't mind the symbol hash not being repeatable, so
208 ;; we might as well add in the object address here, too. (Adding entropy
209 ;; is good, even if ANSI doesn't understand that.)
211 (make-fixup "fast_random_state" :foreign)
213 (inst add temp 12345)
214 (inst mov (make-fixup "fast_random_state" :foreign)
216 ;; We want a positive fixnum for the hash value, so discard the LS bits.
218 ;; FIXME: OK, who wants to tell me (CSR) why these two
219 ;; instructions aren't replaced by (INST AND TEMP #x8FFFFFFC)?
220 ;; Are the following two instructions actually faster? Does the
221 ;; difference in behaviour really matter?
223 (inst and temp #xfffffffc)
224 (storew temp result symbol-hash-slot other-pointer-lowtag)
225 (storew nil-value result symbol-plist-slot other-pointer-lowtag)
226 (storew nil-value result symbol-package-slot other-pointer-lowtag))))