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