Thou shalt not MAKE-OTHER-IMMEDIATE-TYPE.
[sbcl.git] / src / compiler / ppc / alloc.lisp
1 ;;;; allocation VOPs for the PPC
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   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
22   (:temporary (:scs (non-descriptor-reg)) alloc-temp)
23   (:info num)
24   (:results (result :scs (descriptor-reg)))
25   (:variant-vars star)
26   (:policy :safe)
27   (:node-var node)
28   #!-gencgc (:ignore alloc-temp)
29   (:generator 0
30     (cond ((zerop num)
31            (move result null-tn))
32           ((and star (= num 1))
33            (move result (tn-ref-tn things)))
34           (t
35            (macrolet
36                ((maybe-load (tn)
37                   (once-only ((tn tn))
38                     `(sc-case ,tn
39                        ((any-reg descriptor-reg zero null)
40                         ,tn)
41                        (control-stack
42                         (load-stack-tn temp ,tn)
43                         temp)))))
44              (let* ((dx-p (node-stack-allocate-p node))
45                     (cons-cells (if star (1- num) num))
46                     (alloc (* (pad-data-block cons-size) cons-cells)))
47                (pseudo-atomic (pa-flag)
48                  (if dx-p
49                      (progn
50                        (align-csp res)
51                        (inst clrrwi res csp-tn n-lowtag-bits)
52                        (inst ori res res list-pointer-lowtag)
53                        (inst addi csp-tn csp-tn alloc))
54                      (allocation res alloc list-pointer-lowtag :temp-tn alloc-temp
55                                  :flag-tn pa-flag))
56                  (move ptr res)
57                  (dotimes (i (1- cons-cells))
58                    (storew (maybe-load (tn-ref-tn things)) ptr
59                            cons-car-slot list-pointer-lowtag)
60                    (setf things (tn-ref-across things))
61                    (inst addi ptr ptr (pad-data-block cons-size))
62                    (storew ptr ptr
63                            (- cons-cdr-slot cons-size)
64                            list-pointer-lowtag))
65                  (storew (maybe-load (tn-ref-tn things)) ptr
66                          cons-car-slot list-pointer-lowtag)
67                  (storew (if star
68                              (maybe-load (tn-ref-tn (tn-ref-across things)))
69                              null-tn)
70                          ptr cons-cdr-slot list-pointer-lowtag))
71                (move result res)))))))
72
73 (define-vop (list list-or-list*)
74   (:variant nil))
75
76 (define-vop (list* list-or-list*)
77   (:variant t))
78
79 \f
80 ;;;; Special purpose inline allocators.
81
82 (define-vop (allocate-code-object)
83   (:args (boxed-arg :scs (any-reg))
84          (unboxed-arg :scs (any-reg)))
85   (:results (result :scs (descriptor-reg)))
86   (:temporary (:scs (non-descriptor-reg)) ndescr)
87   (:temporary (:scs (non-descriptor-reg)) size)
88   (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
89   (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
90   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
91   (:generator 100
92     (inst addi boxed boxed-arg (fixnumize (1+ code-trace-table-offset-slot)))
93     (inst clrrwi boxed boxed n-lowtag-bits)
94     (inst srwi unboxed unboxed-arg word-shift)
95     (inst addi unboxed unboxed lowtag-mask)
96     (inst clrrwi unboxed unboxed n-lowtag-bits)
97     (pseudo-atomic (pa-flag)
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.
101       (inst add size boxed unboxed)
102       (allocation result size other-pointer-lowtag :temp-tn ndescr :flag-tn pa-flag)
103       (inst slwi ndescr boxed (- n-widetag-bits word-shift))
104       (inst ori ndescr ndescr code-header-widetag)
105       (storew ndescr result 0 other-pointer-lowtag)
106       (storew unboxed result code-code-size-slot other-pointer-lowtag)
107       (storew null-tn result code-entry-points-slot other-pointer-lowtag)
108       (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
109
110 (define-vop (make-fdefn)
111   (:args (name :scs (descriptor-reg) :to :eval))
112   (:temporary (:scs (non-descriptor-reg)) temp)
113   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
114   (:results (result :scs (descriptor-reg) :from :argument))
115   (:policy :fast-safe)
116   (:translate make-fdefn)
117   (:generator 37
118     (with-fixed-allocation (result pa-flag temp fdefn-widetag fdefn-size)
119       (inst lr temp  (make-fixup "undefined_tramp" :foreign))
120       (storew name result fdefn-name-slot other-pointer-lowtag)
121       (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
122       (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
123
124 (define-vop (make-closure)
125   (:args (function :to :save :scs (descriptor-reg)))
126   (:info length stack-allocate-p)
127   (:temporary (:scs (non-descriptor-reg)) temp)
128   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
129   (:results (result :scs (descriptor-reg)))
130   (:generator 10
131     (let* ((size (+ length closure-info-offset))
132            (alloc-size (pad-data-block size)))
133       (pseudo-atomic (pa-flag)
134         (if stack-allocate-p
135             (progn
136               (align-csp result)
137               (inst clrrwi. result csp-tn n-lowtag-bits)
138               (inst addi csp-tn csp-tn alloc-size)
139               (inst ori result result fun-pointer-lowtag)
140               (inst lr temp (logior (ash (1- size) n-widetag-bits) closure-header-widetag)))
141             (progn
142               (allocation result (pad-data-block size)
143                           fun-pointer-lowtag :temp-tn temp :flag-tn pa-flag)
144               (inst lr 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)))))
147
148 ;;; The compiler likes to be able to directly make value cells.
149 ;;;
150 (define-vop (make-value-cell)
151   (:args (value :to :save :scs (descriptor-reg any-reg)))
152   (:temporary (:scs (non-descriptor-reg)) temp)
153   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
154   (:info stack-allocate-p)
155   (:ignore stack-allocate-p)
156   (:results (result :scs (descriptor-reg)))
157   (:generator 10
158     (with-fixed-allocation (result pa-flag temp value-cell-header-widetag value-cell-size)
159       (storew value result value-cell-value-slot other-pointer-lowtag))))
160
161
162 \f
163 ;;;; Automatic allocators for primitive objects.
164
165 (define-vop (make-unbound-marker)
166   (:args)
167   (:results (result :scs (descriptor-reg any-reg)))
168   (:generator 1
169     (inst li result unbound-marker-widetag)))
170
171 (define-vop (make-funcallable-instance-tramp)
172   (:args)
173   (:results (result :scs (any-reg)))
174   (:generator 1
175     (inst lr result (make-fixup "funcallable_instance_tramp" :foreign))))
176
177 (define-vop (fixed-alloc)
178   (:args)
179   (:info name words type lowtag stack-allocate-p)
180   (:ignore name stack-allocate-p)
181   (:results (result :scs (descriptor-reg)))
182   (:temporary (:scs (non-descriptor-reg)) temp)
183   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
184   (:generator 4
185     (with-fixed-allocation (result pa-flag temp type words :lowtag lowtag)
186       )))
187
188 (define-vop (var-alloc)
189   (:args (extra :scs (any-reg)))
190   (:arg-types positive-fixnum)
191   (:info name words type lowtag)
192   (:ignore name #!-gencgc temp)
193   (:results (result :scs (descriptor-reg)))
194   (:temporary (:scs (any-reg)) bytes)
195   (:temporary (:scs (non-descriptor-reg)) header)
196   (:temporary (:scs (non-descriptor-reg)) temp)
197   (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
198   (:generator 6
199     (inst addi bytes extra (* (1+ words) n-word-bytes))
200     (inst slwi header bytes (- n-widetag-bits n-fixnum-tag-bits))
201     (inst addi header header (+ (ash -2 n-widetag-bits) type))
202     (inst clrrwi bytes bytes n-lowtag-bits)
203     (pseudo-atomic (pa-flag)
204       (allocation result bytes lowtag :temp-tn temp :flag-tn pa-flag)
205       (storew header result 0 lowtag))))