1.0.10.5: dynamic-extent CONS
[sbcl/simd.git] / src / compiler / sparc / alloc.lisp
blob51350be64801ee705967c36f4730cee7df9fe1ab
1 ;;;; allocation VOPs for the Sparc port
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
12 (in-package "SB!VM")
14 ;;;; LIST and LIST*
15 (defoptimizer (list stack-allocate-result) ((&rest args))
16 (not (null 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 (:scs (descriptor-reg) :type list) ptr)
23 (:temporary (:scs (descriptor-reg)) temp)
24 (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
25 res)
26 (:info num)
27 (:results (result :scs (descriptor-reg)))
28 (:variant-vars star)
29 (:policy :safe)
30 (:node-var node)
31 (:generator 0
32 (cond ((zerop num)
33 (move result null-tn))
34 ((and star (= num 1))
35 (move result (tn-ref-tn things)))
37 (macrolet
38 ((maybe-load (tn)
39 (once-only ((tn tn))
40 `(sc-case ,tn
41 ((any-reg descriptor-reg zero null)
42 ,tn)
43 (control-stack
44 (load-stack-tn temp ,tn)
45 temp)))))
46 (let* ((dx-p (node-stack-allocate-p node))
47 (cons-cells (if star (1- num) num))
48 (alloc (* (pad-data-block cons-size) cons-cells)))
49 (pseudo-atomic (:extra (if dx-p 0 alloc))
50 (let ((allocation-area-tn (if dx-p csp-tn alloc-tn)))
51 (when dx-p
52 (align-csp res))
53 (inst andn res allocation-area-tn lowtag-mask)
54 (inst or res list-pointer-lowtag)
55 (when dx-p
56 (inst add csp-tn csp-tn alloc)))
57 (move ptr res)
58 (dotimes (i (1- cons-cells))
59 (storew (maybe-load (tn-ref-tn things)) ptr
60 cons-car-slot list-pointer-lowtag)
61 (setf things (tn-ref-across things))
62 (inst add ptr ptr (pad-data-block cons-size))
63 (storew ptr ptr
64 (- cons-cdr-slot cons-size)
65 list-pointer-lowtag))
66 (storew (maybe-load (tn-ref-tn things)) ptr
67 cons-car-slot list-pointer-lowtag)
68 (storew (if star
69 (maybe-load (tn-ref-tn (tn-ref-across things)))
70 null-tn)
71 ptr cons-cdr-slot list-pointer-lowtag))
72 (move result res)))))))
74 (define-vop (list list-or-list*)
75 (:variant nil))
77 (define-vop (list* list-or-list*)
78 (:variant t))
81 ;;;; Special purpose inline allocators.
83 (define-vop (allocate-code-object)
84 (:args (boxed-arg :scs (any-reg))
85 (unboxed-arg :scs (any-reg)))
86 (:results (result :scs (descriptor-reg)))
87 (:temporary (:scs (non-descriptor-reg)) ndescr)
88 (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
89 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
90 (:generator 100
91 (inst add boxed boxed-arg (fixnumize (1+ code-trace-table-offset-slot)))
92 (inst and boxed (lognot lowtag-mask))
93 (inst srl unboxed unboxed-arg word-shift)
94 (inst add unboxed lowtag-mask)
95 (inst and unboxed (lognot lowtag-mask))
96 (pseudo-atomic ()
97 ;; CMUCL Comment:
98 ;; Note: we don't have to subtract off the 4 that was added by
99 ;; pseudo-atomic, because oring in other-pointer-lowtag just adds
100 ;; it right back.
102 ;; This looks like another dreadful type pun. CSR - 2002-02-06
103 (inst or result alloc-tn other-pointer-lowtag)
104 (inst add alloc-tn boxed)
105 (inst add alloc-tn unboxed)
106 (inst sll ndescr boxed (- n-widetag-bits word-shift))
107 (inst or ndescr code-header-widetag)
108 (storew ndescr result 0 other-pointer-lowtag)
109 (storew unboxed result code-code-size-slot other-pointer-lowtag)
110 (storew null-tn result code-entry-points-slot other-pointer-lowtag)
111 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
113 (define-vop (make-fdefn)
114 (:args (name :scs (descriptor-reg) :to :eval))
115 (:temporary (:scs (non-descriptor-reg)) temp)
116 (:results (result :scs (descriptor-reg) :from :argument))
117 (:policy :fast-safe)
118 (:translate make-fdefn)
119 (:generator 37
120 (with-fixed-allocation (result temp fdefn-widetag fdefn-size)
121 (inst li temp (make-fixup "undefined_tramp" :foreign))
122 (storew name result fdefn-name-slot other-pointer-lowtag)
123 (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
124 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
127 (define-vop (make-closure)
128 (:args (function :to :save :scs (descriptor-reg)))
129 (:info length stack-allocate-p)
130 (:temporary (:scs (non-descriptor-reg)) temp)
131 (:results (result :scs (descriptor-reg)))
132 (:generator 10
133 (let* ((size (+ length closure-info-offset))
134 (alloc-size (pad-data-block size)))
135 (pseudo-atomic (:extra (if stack-allocate-p 0 alloc-size))
136 (cond (stack-allocate-p
137 (align-csp temp)
138 (inst andn result csp-tn lowtag-mask)
139 (inst or result fun-pointer-lowtag)
140 (inst add csp-tn alloc-size))
142 (inst andn result alloc-tn lowtag-mask)
143 (inst or result fun-pointer-lowtag)))
144 (inst li temp (logior (ash (1- size) n-widetag-bits) closure-header-widetag))
145 (storew temp result 0 fun-pointer-lowtag)
146 (storew function result closure-fun-slot fun-pointer-lowtag)))))
148 ;;; The compiler likes to be able to directly make value cells.
149 (define-vop (make-value-cell)
150 (:args (value :to :save :scs (descriptor-reg any-reg)))
151 (:temporary (:scs (non-descriptor-reg)) temp)
152 (:info stack-allocate-p)
153 (:ignore stack-allocate-p)
154 (:results (result :scs (descriptor-reg)))
155 (:generator 10
156 (with-fixed-allocation
157 (result temp value-cell-header-widetag value-cell-size)
158 (storew value result value-cell-value-slot other-pointer-lowtag))))
160 ;;;; Automatic allocators for primitive objects.
162 (define-vop (make-unbound-marker)
163 (:args)
164 (:results (result :scs (any-reg)))
165 (:generator 1
166 (inst li result unbound-marker-widetag)))
168 (define-vop (make-funcallable-instance-tramp)
169 (:args)
170 (:results (result :scs (any-reg)))
171 (:generator 1
172 (inst li result (make-fixup "funcallable_instance_tramp" :foreign))))
174 (define-vop (fixed-alloc)
175 (:args)
176 (:info name words type lowtag stack-allocate-p)
177 (:ignore name stack-allocate-p)
178 (:results (result :scs (descriptor-reg)))
179 (:temporary (:scs (non-descriptor-reg)) temp)
180 (:generator 4
181 (pseudo-atomic (:extra (pad-data-block words))
182 (cond ((logbitp (1- n-lowtag-bits) lowtag)
183 (inst or result alloc-tn lowtag))
185 (inst andn result alloc-tn lowtag-mask)
186 (inst or result lowtag)))
187 (when type
188 (inst li temp (logior (ash (1- words) n-widetag-bits) type))
189 (storew temp result 0 lowtag)))))
191 (define-vop (var-alloc)
192 (:args (extra :scs (any-reg)))
193 (:arg-types positive-fixnum)
194 (:info name words type lowtag)
195 (:ignore name)
196 (:results (result :scs (descriptor-reg)))
197 (:temporary (:scs (any-reg)) bytes)
198 (:temporary (:scs (non-descriptor-reg)) header)
199 (:generator 6
200 (inst add bytes extra (* (1+ words) n-word-bytes))
201 (inst sll header bytes (- n-widetag-bits 2))
202 (inst add header header (+ (ash -2 n-widetag-bits) type))
203 (inst and bytes (lognot lowtag-mask))
204 (pseudo-atomic ()
205 ;; Need to be careful if the lowtag and the pseudo-atomic flag
206 ;; are not compatible.
207 (cond ((logbitp (1- n-lowtag-bits) lowtag)
208 (inst or result alloc-tn lowtag))
210 (inst andn result alloc-tn lowtag-mask)
211 (inst or result lowtag)))
212 (storew header result 0 lowtag)
213 (inst add alloc-tn alloc-tn bytes))))