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
76 (define-vop (allocate-code-object)
77 (:args (boxed-arg :scs (any-reg) :target boxed)
78 (unboxed-arg :scs (any-reg) :target unboxed))
79 (:results (result :scs (descriptor-reg) :from :eval))
80 (:temporary (:sc unsigned-reg :from (:argument 0)) boxed)
81 (:temporary (:sc unsigned-reg :from (:argument 1)) unboxed)
84 (move boxed boxed-arg)
85 (inst add boxed (fixnumize (1+ code-trace-table-offset-slot)))
86 (inst and boxed (lognot lowtag-mask))
87 (move unboxed unboxed-arg)
88 (inst shr unboxed word-shift)
89 (inst add unboxed lowtag-mask)
90 (inst and unboxed (lognot lowtag-mask))
91 (inst mov result boxed)
92 (inst add result unboxed)
94 (allocation result result node)
95 (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
96 (inst shl boxed (- n-widetag-bits word-shift))
97 (inst or boxed code-header-widetag)
98 (storew boxed result 0 other-pointer-lowtag)
99 (storew unboxed result code-code-size-slot other-pointer-lowtag)
100 (storew nil-value result code-entry-points-slot other-pointer-lowtag))
101 (storew nil-value result code-debug-info-slot other-pointer-lowtag)))
103 (define-vop (make-fdefn)
105 (:translate make-fdefn)
106 (:args (name :scs (descriptor-reg) :to :eval))
107 (:results (result :scs (descriptor-reg) :from :argument))
110 (with-fixed-allocation (result fdefn-widetag fdefn-size node)
111 (storew name result fdefn-name-slot other-pointer-lowtag)
112 (storew nil-value result fdefn-fun-slot other-pointer-lowtag)
113 (storew (make-fixup (extern-alien-name "undefined_tramp") :foreign)
114 result fdefn-raw-addr-slot other-pointer-lowtag))))
116 (define-vop (make-closure)
117 (:args (function :to :save :scs (descriptor-reg)))
119 (:temporary (:sc any-reg) temp)
120 (:results (result :scs (descriptor-reg)))
124 (let ((size (+ length closure-info-offset)))
125 (allocation result (pad-data-block size) node)
127 (make-ea :byte :base result :disp fun-pointer-lowtag))
128 (storew (logior (ash (1- size) n-widetag-bits) closure-header-widetag)
129 result 0 fun-pointer-lowtag))
130 (loadw temp function closure-fun-slot fun-pointer-lowtag)
131 (storew temp result closure-fun-slot fun-pointer-lowtag))))
133 ;;; The compiler likes to be able to directly make value cells.
134 (define-vop (make-value-cell)
135 (:args (value :scs (descriptor-reg any-reg) :to :result))
136 (:results (result :scs (descriptor-reg) :from :eval))
139 (with-fixed-allocation
140 (result value-cell-header-widetag value-cell-size node))
141 (storew value result value-cell-value-slot other-pointer-lowtag)))
143 ;;;; automatic allocators for primitive objects
145 (define-vop (make-unbound-marker)
147 (:results (result :scs (any-reg)))
149 (inst mov result unbound-marker-widetag)))
151 (define-vop (fixed-alloc)
153 (:info name words type lowtag)
155 (:results (result :scs (descriptor-reg)))
159 (allocation result (pad-data-block words) node)
160 (inst lea result (make-ea :byte :base result :disp lowtag))
162 (storew (logior (ash (1- words) n-widetag-bits) type)
167 (define-vop (var-alloc)
168 (:args (extra :scs (any-reg)))
169 (:arg-types positive-fixnum)
170 (:info name words type lowtag)
172 (:results (result :scs (descriptor-reg) :from (:eval 1)))
173 (:temporary (:sc any-reg :from :eval :to (:eval 1)) bytes)
174 (:temporary (:sc any-reg :from :eval :to :result) header)
178 (make-ea :dword :base extra :disp (* (1+ words) n-word-bytes)))
179 (inst mov header bytes)
180 (inst shl header (- n-widetag-bits 2)) ; w+1 to length field
181 (inst lea header ; (w-1 << 8) | type
182 (make-ea :dword :base header :disp (+ (ash -2 n-widetag-bits) type)))
183 (inst and bytes (lognot lowtag-mask))
185 (allocation result bytes node)
186 (inst lea result (make-ea :byte :base result :disp lowtag))
187 (storew header result 0 lowtag))))