Thou shalt not MAKE-OTHER-IMMEDIATE-TYPE.
[sbcl.git] / src / compiler / hppa / alloc.lisp
1 ;;;; allocation VOPs for the HPPA
2
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.
11
12 (in-package "SB!VM")
13 \f
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))
31           (t
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                    (inst addi alloc csp-tn csp-tn))
49                  (move res ptr)
50                  (dotimes (i (1- cons-cells))
51                    (store-car (tn-ref-tn things) ptr)
52                    (setf things (tn-ref-across things))
53                    (inst addi (pad-data-block cons-size) ptr ptr)
54                    (storew ptr ptr
55                            (- cons-cdr-slot cons-size)
56                            list-pointer-lowtag))
57                  (store-car (tn-ref-tn things) ptr)
58                  (cond (star
59                         (setf things (tn-ref-across things))
60                         (store-car (tn-ref-tn things) ptr cons-cdr-slot))
61                        (t
62                         (storew null-tn ptr
63                                 cons-cdr-slot list-pointer-lowtag)))
64                  (aver (null (tn-ref-across things)))
65                  (move res result))))))))
66
67 (define-vop (list list-or-list*)
68   (:variant nil))
69
70 (define-vop (list* list-or-list*)
71   (:variant t))
72
73 \f
74 ;;;; Special purpose inline allocators.
75 ;;; ALLOCATE-VECTOR
76 (define-vop (allocate-vector-on-heap)
77   (:args (type :scs (unsigned-reg))
78          (length :scs (any-reg))
79          (words :scs (any-reg)))
80   (:arg-types positive-fixnum
81               positive-fixnum
82               positive-fixnum)
83   (:temporary (:sc non-descriptor-reg) bytes)
84   (:results (result :scs (descriptor-reg) :from :load))
85   (:policy :fast-safe)
86   (:generator 100
87     (inst addi (+ lowtag-mask
88                   (* vector-data-offset n-word-bytes)) words bytes)
89     (inst dep 0 31 n-lowtag-bits bytes)
90     (pseudo-atomic ()
91       (set-lowtag other-pointer-lowtag alloc-tn result)
92       (inst add bytes alloc-tn alloc-tn)
93       (storew type result 0 other-pointer-lowtag)
94       (storew length result vector-length-slot other-pointer-lowtag))))
95
96 (define-vop (allocate-vector-on-stack)
97   (:args (type :scs (unsigned-reg))
98          (length :scs (any-reg))
99          (words :scs (any-reg)))
100   (:arg-types positive-fixnum
101               positive-fixnum
102               positive-fixnum)
103   (:temporary (:sc non-descriptor-reg) bytes temp)
104   (:results (result :scs (descriptor-reg) :from :load))
105   (:policy :fast-safe)
106   (:generator 100
107     (inst addi (+ lowtag-mask
108                   (* vector-data-offset n-word-bytes)) words bytes)
109     (inst dep 0 31 n-lowtag-bits bytes)
110     ;; FIXME: It would be good to check for stack overflow here.
111     (pseudo-atomic ()
112       (align-csp temp)
113       (set-lowtag other-pointer-lowtag csp-tn result)
114       (inst addi (* vector-data-offset n-word-bytes) csp-tn temp)
115       (inst add bytes csp-tn csp-tn)
116       (storew type result 0 other-pointer-lowtag)
117       (storew length result vector-length-slot other-pointer-lowtag)
118       (let ((loop (gen-label)))
119         (emit-label loop)
120         (inst comb :<> temp csp-tn loop :nullify t)
121         (inst stwm zero-tn n-word-bytes temp)))))
122
123 (define-vop (allocate-code-object)
124   (:args (boxed-arg :scs (any-reg))
125          (unboxed-arg :scs (any-reg)))
126   (:results (result :scs (descriptor-reg)))
127   (:temporary (:scs (non-descriptor-reg)) ndescr)
128   (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
129   (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
130   (:generator 100
131     (inst addi (fixnumize (1+ code-trace-table-offset-slot)) boxed-arg boxed)
132     (inst dep 0 31 n-lowtag-bits boxed)
133     (inst srl unboxed-arg word-shift unboxed)
134     (inst addi lowtag-mask unboxed unboxed)
135     (inst dep 0 31 n-lowtag-bits unboxed)
136     (inst sll boxed (- n-widetag-bits word-shift) ndescr)
137     (inst addi code-header-widetag ndescr ndescr)
138     (pseudo-atomic ()
139       (set-lowtag other-pointer-lowtag alloc-tn result)
140       (inst add alloc-tn boxed alloc-tn)
141       (inst add alloc-tn unboxed alloc-tn)
142       (storew ndescr result 0 other-pointer-lowtag)
143       (storew unboxed result code-code-size-slot other-pointer-lowtag)
144       (storew null-tn result code-entry-points-slot other-pointer-lowtag)
145       (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
146
147 (define-vop (make-fdefn)
148   (:translate make-fdefn)
149   (:policy :fast-safe)
150   (:args (name :scs (descriptor-reg) :to :eval))
151   (:temporary (:scs (non-descriptor-reg)) temp)
152   (:results (result :scs (descriptor-reg) :from :argument))
153   (:generator 37
154     (with-fixed-allocation (result nil temp fdefn-widetag fdefn-size nil)
155       (inst li (make-fixup "undefined_tramp" :foreign) temp)
156       (storew name result fdefn-name-slot other-pointer-lowtag)
157       (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
158       (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
159
160 (define-vop (make-closure)
161   (:args (function :to :save :scs (descriptor-reg)))
162   (:info length stack-allocate-p)
163   (:temporary (:scs (non-descriptor-reg)) temp)
164   (:results (result :scs (descriptor-reg)))
165   (:generator 10
166     (with-fixed-allocation
167         (result nil temp closure-header-widetag
168          (+ length closure-info-offset)
169          stack-allocate-p :lowtag fun-pointer-lowtag)
170       (storew function result closure-fun-slot fun-pointer-lowtag))))
171
172 ;;; The compiler likes to be able to directly make value cells.
173 (define-vop (make-value-cell)
174   (:args (value :to :save :scs (descriptor-reg any-reg)))
175   (:temporary (:scs (non-descriptor-reg)) temp)
176   (:results (result :scs (descriptor-reg)))
177   (:info stack-allocate-p)
178   (:generator 10
179     (with-fixed-allocation
180         (result nil temp value-cell-header-widetag value-cell-size stack-allocate-p)
181       (storew value result value-cell-value-slot other-pointer-lowtag))))
182 \f
183 ;;;; Automatic allocators for primitive objects.
184
185 (define-vop (make-unbound-marker)
186   (:args)
187   (:results (result :scs (descriptor-reg any-reg)))
188   (:generator 1
189     (inst li unbound-marker-widetag result)))
190
191 (define-vop (make-funcallable-instance-tramp)
192   (:args)
193   (:results (result :scs (any-reg)))
194   (:generator 1
195     (inst li (make-fixup 'funcallable-instance-tramp :assembly-routine)
196           result)))
197
198 (define-vop (fixed-alloc)
199   (:args)
200   (:info name words type lowtag stack-allocate-p)
201   (:ignore name)
202   (:results (result :scs (descriptor-reg)))
203   (:temporary (:scs (non-descriptor-reg)) temp)
204   (:generator 4
205     (with-fixed-allocation
206       (result nil temp type words stack-allocate-p
207        :lowtag lowtag :maybe-write t))))
208
209 (define-vop (var-alloc)
210   (:args (extra :scs (any-reg)))
211   (:arg-types positive-fixnum)
212   (:info name words type lowtag)
213   (:ignore name)
214   (:results (result :scs (descriptor-reg)))
215   (:temporary (:scs (any-reg)) bytes)
216   (:temporary (:scs (non-descriptor-reg)) header)
217   (:generator 6
218     (inst addi (* (1+ words) n-word-bytes) extra bytes)
219     (inst sll bytes (- n-widetag-bits 2) header)
220     (inst addi (+ (ash -2 n-widetag-bits) type) header header)
221     (inst dep 0 31 n-lowtag-bits bytes)
222     (pseudo-atomic ()
223       (set-lowtag lowtag alloc-tn result)
224       (storew header result 0 lowtag)
225       (inst add alloc-tn bytes alloc-tn))))
226