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