1.0.7.1: dynamic extent value cells
[sbcl/simd.git] / src / compiler / ppc / alloc.lisp
blob0f8f20df242b3049c5b170c8b68e2a068a260360
1 ;;;; allocation VOPs for the PPC
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 (: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)))
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)))))))
78 (define-vop (list list-or-list*)
79 (:variant nil))
81 (define-vop (list* list-or-list*)
82 (:variant t))
85 ;;;; Special purpose inline allocators.
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))))
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))))
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 function result closure-fun-slot fun-pointer-lowtag)))))
154 ;;; The compiler likes to be able to directly make value cells.
156 (define-vop (make-value-cell)
157 (:args (value :to :save :scs (descriptor-reg any-reg)))
158 (:temporary (:scs (non-descriptor-reg)) temp)
159 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
160 (:info stack-allocate-p)
161 (:ignore stack-allocate-p)
162 (:results (result :scs (descriptor-reg)))
163 (:generator 10
164 (with-fixed-allocation (result pa-flag temp value-cell-header-widetag value-cell-size)
165 (storew value result value-cell-value-slot other-pointer-lowtag))))
169 ;;;; Automatic allocators for primitive objects.
171 (define-vop (make-unbound-marker)
172 (:args)
173 (:results (result :scs (any-reg)))
174 (:generator 1
175 (inst li result unbound-marker-widetag)))
177 (define-vop (make-funcallable-instance-tramp)
178 (:args)
179 (:results (result :scs (any-reg)))
180 (:generator 1
181 (inst lr result (make-fixup "funcallable_instance_tramp" :foreign))))
183 (define-vop (fixed-alloc)
184 (:args)
185 (:info name words type lowtag)
186 (:ignore name)
187 (:results (result :scs (descriptor-reg)))
188 (:temporary (:scs (non-descriptor-reg)) temp)
189 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
190 (:generator 4
191 (with-fixed-allocation (result pa-flag temp type words :lowtag lowtag)
194 (define-vop (var-alloc)
195 (:args (extra :scs (any-reg)))
196 (:arg-types positive-fixnum)
197 (:info name words type lowtag)
198 (:ignore name #!-gencgc temp)
199 (:results (result :scs (descriptor-reg)))
200 (:temporary (:scs (any-reg)) bytes)
201 (:temporary (:scs (non-descriptor-reg)) header)
202 (:temporary (:scs (non-descriptor-reg)) temp)
203 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
204 (:generator 6
205 (inst addi bytes extra (* (1+ words) n-word-bytes))
206 (inst slwi header bytes (- n-widetag-bits 2))
207 (inst addi header header (+ (ash -2 n-widetag-bits) type))
208 (inst clrrwi bytes bytes n-lowtag-bits)
209 (pseudo-atomic (pa-flag)
210 (allocation result bytes lowtag :temp-tn temp :flag-tn pa-flag)
211 (storew header result 0 lowtag))))