Merged sbcl-1.0.14 with the sb-simd 1.3 patches
[sbcl/simd.git] / src / compiler / ppc / alloc.lisp
blobe3dd0fbeab58cacd8f0ff31f67a7e9e07037e5d9
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 (storew temp result 0 fun-pointer-lowtag)
151 (storew function result closure-fun-slot fun-pointer-lowtag)))))
153 ;;; The compiler likes to be able to directly make value cells.
155 (define-vop (make-value-cell)
156 (:args (value :to :save :scs (descriptor-reg any-reg)))
157 (:temporary (:scs (non-descriptor-reg)) temp)
158 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
159 (:info stack-allocate-p)
160 (:ignore stack-allocate-p)
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))))
168 ;;;; Automatic allocators for primitive objects.
170 (define-vop (make-unbound-marker)
171 (:args)
172 (:results (result :scs (any-reg)))
173 (:generator 1
174 (inst li result unbound-marker-widetag)))
176 (define-vop (make-funcallable-instance-tramp)
177 (:args)
178 (:results (result :scs (any-reg)))
179 (:generator 1
180 (inst lr result (make-fixup "funcallable_instance_tramp" :foreign))))
182 (define-vop (fixed-alloc)
183 (:args)
184 (:info name words type lowtag stack-allocate-p)
185 (:ignore name stack-allocate-p)
186 (:results (result :scs (descriptor-reg)))
187 (:temporary (:scs (non-descriptor-reg)) temp)
188 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
189 (:generator 4
190 (with-fixed-allocation (result pa-flag temp type words :lowtag lowtag)
193 (define-vop (var-alloc)
194 (:args (extra :scs (any-reg)))
195 (:arg-types positive-fixnum)
196 (:info name words type lowtag)
197 (:ignore name #!-gencgc temp)
198 (:results (result :scs (descriptor-reg)))
199 (:temporary (:scs (any-reg)) bytes)
200 (:temporary (:scs (non-descriptor-reg)) header)
201 (:temporary (:scs (non-descriptor-reg)) temp)
202 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
203 (:generator 6
204 (inst addi bytes extra (* (1+ words) n-word-bytes))
205 (inst slwi header bytes (- n-widetag-bits 2))
206 (inst addi header header (+ (ash -2 n-widetag-bits) type))
207 (inst clrrwi bytes bytes n-lowtag-bits)
208 (pseudo-atomic (pa-flag)
209 (allocation result bytes lowtag :temp-tn temp :flag-tn pa-flag)
210 (storew header result 0 lowtag))))