Hoist tests from scan_weak_pointers() into scav_weak_pointer()
[sbcl.git] / src / compiler / hppa / alloc.lisp
blob3d97f4bfe7936fd40b7df99bac1efb4b611f5ab3
1 ;;;; allocation VOPs for the HPPA
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 (define-vop (list-or-list*)
16 (:args (things :more t))
17 (:temporary (:scs (descriptor-reg) :type list) ptr)
18 (:temporary (:scs (descriptor-reg)) temp)
19 (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
20 res)
21 (:info num)
22 (:results (result :scs (descriptor-reg)))
23 (:variant-vars star)
24 (:policy :safe)
25 (:node-var node)
26 (:generator 0
27 (cond ((zerop num)
28 (move null-tn result))
29 ((and star (= num 1))
30 (move (tn-ref-tn things) result))
32 (macrolet
33 ((store-car (tn list &optional (slot cons-car-slot))
34 `(let ((reg (sc-case ,tn
35 ((any-reg descriptor-reg zero null) ,tn)
36 (control-stack
37 (load-stack-tn temp ,tn)
38 temp))))
39 (storew reg ,list ,slot list-pointer-lowtag))))
40 (let* ((dx-p (node-stack-allocate-p node))
41 (cons-cells (if star (1- num) num))
42 (alloc (* (pad-data-block cons-size) cons-cells)))
43 (pseudo-atomic (:extra (if dx-p 0 alloc))
44 (when dx-p
45 (align-csp res))
46 (set-lowtag list-pointer-lowtag (if dx-p csp-tn alloc-tn) res)
47 (when dx-p
48 (if (typep alloc '(signed-byte 14))
49 (inst ldo alloc csp-tn csp-tn)
50 ;; FIXME: We have TEMP available, so can do an
51 ;; LIDL / LDO / ADD sequence here instead of
52 ;; punting.
53 (error "VOP LIST-OR-LIST* can't stack-allocate more than 511 CONSes at once")))
54 (move res ptr)
55 (dotimes (i (1- cons-cells))
56 (store-car (tn-ref-tn things) ptr)
57 (setf things (tn-ref-across things))
58 (inst addi (pad-data-block cons-size) ptr ptr)
59 (storew ptr ptr
60 (- cons-cdr-slot cons-size)
61 list-pointer-lowtag))
62 (store-car (tn-ref-tn things) ptr)
63 (cond (star
64 (setf things (tn-ref-across things))
65 (store-car (tn-ref-tn things) ptr cons-cdr-slot))
67 (storew null-tn ptr
68 cons-cdr-slot list-pointer-lowtag)))
69 (aver (null (tn-ref-across things)))
70 (move res result))))))))
72 (define-vop (list list-or-list*)
73 (:variant nil))
75 (define-vop (list* list-or-list*)
76 (:variant t))
79 ;;;; Special purpose inline allocators.
80 ;;; ALLOCATE-VECTOR
81 (define-vop (allocate-vector-on-heap)
82 (:args (type :scs (unsigned-reg))
83 (length :scs (any-reg))
84 (words :scs (any-reg)))
85 (:arg-types positive-fixnum
86 positive-fixnum
87 positive-fixnum)
88 (:temporary (:sc non-descriptor-reg) bytes)
89 (:results (result :scs (descriptor-reg) :from :load))
90 #!-stack-allocatable-vectors
91 (:translate allocate-vector)
92 (:policy :fast-safe)
93 (:generator 100
94 (inst addi (+ lowtag-mask
95 (* vector-data-offset n-word-bytes)) words bytes)
96 (inst dep 0 31 n-lowtag-bits bytes)
97 (pseudo-atomic ()
98 (set-lowtag other-pointer-lowtag alloc-tn result)
99 (inst add bytes alloc-tn alloc-tn)
100 (storew type result 0 other-pointer-lowtag)
101 (storew length result vector-length-slot other-pointer-lowtag))))
103 (define-vop (allocate-vector-on-stack)
104 (:args (type :scs (unsigned-reg))
105 (length :scs (any-reg))
106 (words :scs (any-reg)))
107 (:arg-types positive-fixnum
108 positive-fixnum
109 positive-fixnum)
110 (:temporary (:sc non-descriptor-reg) bytes temp)
111 (:results (result :scs (descriptor-reg) :from :load))
112 (:policy :fast-safe)
113 (:generator 100
114 (inst addi (+ lowtag-mask
115 (* vector-data-offset n-word-bytes)) words bytes)
116 (inst dep 0 31 n-lowtag-bits bytes)
117 ;; FIXME: It would be good to check for stack overflow here.
118 (pseudo-atomic ()
119 (align-csp temp)
120 (set-lowtag other-pointer-lowtag csp-tn result)
121 (inst addi (* vector-data-offset n-word-bytes) csp-tn temp)
122 (inst add bytes csp-tn csp-tn)
123 (storew type result 0 other-pointer-lowtag)
124 (storew length result vector-length-slot other-pointer-lowtag)
125 (let ((loop (gen-label)))
126 (emit-label loop)
127 (inst comb :<> temp csp-tn loop :nullify t)
128 (inst stwm zero-tn n-word-bytes temp)))))
130 (define-vop (allocate-code-object)
131 (:args (boxed-arg :scs (any-reg))
132 (unboxed-arg :scs (any-reg)))
133 (:results (result :scs (descriptor-reg)))
134 (:temporary (:scs (non-descriptor-reg)) ndescr)
135 (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
136 (:temporary (:scs (non-descriptor-reg)) unboxed)
137 (:generator 100
138 (inst addi (fixnumize (1+ code-constants-offset)) boxed-arg boxed)
139 (inst dep 0 31 n-lowtag-bits boxed)
140 (inst srl unboxed-arg word-shift unboxed)
141 (inst addi lowtag-mask unboxed unboxed)
142 (inst dep 0 31 n-lowtag-bits unboxed)
143 (inst sll boxed (- n-widetag-bits word-shift) ndescr)
144 (inst addi code-header-widetag ndescr ndescr)
145 (pseudo-atomic ()
146 (set-lowtag other-pointer-lowtag alloc-tn result)
147 (inst add alloc-tn boxed alloc-tn)
148 (inst add alloc-tn unboxed alloc-tn)
149 (storew ndescr result 0 other-pointer-lowtag)
150 (storew unboxed-arg result code-code-size-slot other-pointer-lowtag)
151 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
153 (define-vop (make-fdefn)
154 (:translate make-fdefn)
155 (:policy :fast-safe)
156 (:args (name :scs (descriptor-reg) :to :eval))
157 (:temporary (:scs (non-descriptor-reg)) temp)
158 (:results (result :scs (descriptor-reg) :from :argument))
159 (:generator 37
160 (with-fixed-allocation (result nil temp fdefn-widetag fdefn-size nil)
161 (inst li (make-fixup 'undefined-tramp :assembly-routine) temp)
162 (storew name result fdefn-name-slot other-pointer-lowtag)
163 (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
164 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
166 (define-vop (make-closure)
167 (:args (function :to :save :scs (descriptor-reg)))
168 (:info length stack-allocate-p)
169 (:temporary (:scs (non-descriptor-reg)) temp)
170 (:results (result :scs (descriptor-reg)))
171 (:generator 10
172 (with-fixed-allocation
173 (result nil temp closure-header-widetag
174 (+ length closure-info-offset)
175 stack-allocate-p :lowtag fun-pointer-lowtag)
176 (storew function result closure-fun-slot fun-pointer-lowtag))))
178 ;;; The compiler likes to be able to directly make value cells.
179 (define-vop (make-value-cell)
180 (:args (value :to :save :scs (descriptor-reg any-reg)))
181 (:temporary (:scs (non-descriptor-reg)) temp)
182 (:results (result :scs (descriptor-reg)))
183 (:info stack-allocate-p)
184 (:generator 10
185 (with-fixed-allocation
186 (result nil temp value-cell-header-widetag value-cell-size stack-allocate-p)
187 (storew value result value-cell-value-slot other-pointer-lowtag))))
189 ;;;; Automatic allocators for primitive objects.
191 (define-vop (make-unbound-marker)
192 (:args)
193 (:results (result :scs (descriptor-reg any-reg)))
194 (:generator 1
195 (inst li unbound-marker-widetag result)))
197 (define-vop (make-funcallable-instance-tramp)
198 (:args)
199 (:results (result :scs (any-reg)))
200 (:generator 1
201 (inst li (make-fixup 'funcallable-instance-tramp :assembly-routine)
202 result)))
204 (define-vop (fixed-alloc)
205 (:args)
206 (:info name words type lowtag stack-allocate-p)
207 (:ignore name)
208 (:results (result :scs (descriptor-reg)))
209 (:temporary (:scs (non-descriptor-reg)) temp)
210 (:generator 4
211 (with-fixed-allocation
212 (result nil temp type words stack-allocate-p
213 :lowtag lowtag :maybe-write t))))
215 (define-vop (var-alloc)
216 (:args (extra :scs (any-reg)))
217 (:arg-types positive-fixnum)
218 (:info name words type lowtag)
219 (:ignore name)
220 (:results (result :scs (descriptor-reg)))
221 (:temporary (:scs (any-reg)) bytes)
222 (:temporary (:scs (non-descriptor-reg)) header)
223 (:generator 6
224 (inst addi (* (1+ words) n-word-bytes) extra bytes)
225 (inst sll bytes (- n-widetag-bits 2) header)
226 (inst addi (+ (ash -2 n-widetag-bits) type) header header)
227 (inst dep 0 31 n-lowtag-bits bytes)
228 (pseudo-atomic ()
229 (set-lowtag lowtag alloc-tn result)
230 (storew header result 0 lowtag)
231 (inst add alloc-tn bytes alloc-tn))))