Replace %CODE-ENTRY-POINTS with an array, remove %SIMPLE-FUN-NEXT.
[sbcl.git] / src / compiler / arm / alloc.lisp
blob8c86e099fefc240731f301df9fe63076c943f252
1 ;;;; allocation VOPs for the ARM
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 (define-vop (list-or-list*)
15 (:args (things :more t :scs (control-stack)))
16 (:temporary (:scs (descriptor-reg) :type list) ptr)
17 (:temporary (:scs (any-reg)) temp)
18 (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
19 res)
20 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
21 (:info num)
22 (:results (result :scs (descriptor-reg)))
23 (:variant-vars star)
24 (:policy :fast-safe)
25 (:node-var node)
26 (:generator 0
27 (cond ((zerop num)
28 (move result null-tn))
29 ((and star (= num 1))
30 (move result (tn-ref-tn things)))
32 (macrolet
33 ((maybe-load (tn)
34 (once-only ((tn tn))
35 `(sc-case ,tn
36 ((any-reg descriptor-reg null)
37 ,tn)
38 (control-stack
39 (load-stack-tn temp ,tn)
40 temp)))))
41 (let* ((cons-cells (if star (1- num) num))
42 (alloc (* (pad-data-block cons-size) cons-cells)))
43 (pseudo-atomic (pa-flag)
44 (allocation res alloc list-pointer-lowtag
45 :flag-tn pa-flag
46 :stack-allocate-p (node-stack-allocate-p node))
47 (move ptr res)
48 (dotimes (i (1- cons-cells))
49 (storew (maybe-load (tn-ref-tn things)) ptr
50 cons-car-slot list-pointer-lowtag)
51 (setf things (tn-ref-across things))
52 (inst add ptr ptr (pad-data-block cons-size))
53 (storew ptr ptr
54 (- cons-cdr-slot cons-size)
55 list-pointer-lowtag))
56 (storew (maybe-load (tn-ref-tn things)) ptr
57 cons-car-slot list-pointer-lowtag)
58 (storew (if star
59 (maybe-load (tn-ref-tn (tn-ref-across things)))
60 null-tn)
61 ptr cons-cdr-slot list-pointer-lowtag))
62 (move result res)))))))
64 (define-vop (list list-or-list*)
65 (:variant nil))
67 (define-vop (list* list-or-list*)
68 (:variant t))
70 ;;;; Special purpose inline allocators.
71 #!-gencgc
72 (define-vop (allocate-code-object)
73 (:args (boxed-arg :scs (any-reg))
74 (unboxed-arg :scs (any-reg)))
75 (:results (result :scs (descriptor-reg)))
76 (:temporary (:scs (non-descriptor-reg)) ndescr)
77 (:temporary (:scs (non-descriptor-reg)) size)
78 (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
79 (:temporary (:scs (non-descriptor-reg)) unboxed)
80 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
81 (:generator 100
82 (inst add boxed boxed-arg (fixnumize (1+ code-constants-offset)))
83 (inst bic boxed boxed lowtag-mask)
84 (inst mov unboxed (lsr unboxed-arg word-shift))
85 (inst add unboxed unboxed lowtag-mask)
86 (inst bic unboxed unboxed lowtag-mask)
87 (inst mov ndescr (lsl boxed (- n-widetag-bits word-shift)))
88 (inst orr ndescr ndescr code-header-widetag)
89 (inst add size boxed unboxed)
90 (pseudo-atomic (pa-flag)
91 (allocation result size other-pointer-lowtag :flag-tn pa-flag)
92 (storew ndescr result 0 other-pointer-lowtag)
93 (storew unboxed-arg result code-code-size-slot other-pointer-lowtag)
94 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
96 (define-vop (make-fdefn)
97 (:args (name :scs (descriptor-reg) :to :eval))
98 (:temporary (:scs (non-descriptor-reg)) temp)
99 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
100 (:results (result :scs (descriptor-reg) :from :argument))
101 (:temporary (:sc interior-reg) lip)
102 (:policy :fast-safe)
103 (:translate make-fdefn)
104 (:generator 37
105 (let ((undefined-tramp-fixup (gen-label)))
106 (with-fixed-allocation (result pa-flag fdefn-widetag fdefn-size)
107 (inst load-from-label temp lip undefined-tramp-fixup)
108 (storew name result fdefn-name-slot other-pointer-lowtag)
109 (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
110 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))
111 (assemble (*elsewhere*)
112 (emit-label undefined-tramp-fixup)
113 (inst word (make-fixup 'undefined-tramp :assembly-routine))))))
115 (define-vop (make-closure)
116 (:args (function :to :save :scs (descriptor-reg)))
117 (:info length stack-allocate-p)
118 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
119 (:results (result :scs (descriptor-reg)))
120 (:generator 10
121 (let* ((size (+ length closure-info-offset))
122 (alloc-size (pad-data-block size)))
123 (pseudo-atomic (pa-flag)
124 (allocation result alloc-size
125 fun-pointer-lowtag
126 :flag-tn pa-flag
127 :stack-allocate-p stack-allocate-p)
128 (load-immediate-word pa-flag
129 (logior
130 (ash (1- size) n-widetag-bits)
131 closure-header-widetag))
132 (storew pa-flag result 0 fun-pointer-lowtag)
133 (storew function result closure-fun-slot fun-pointer-lowtag)))))
135 ;;; The compiler likes to be able to directly make value cells.
137 (define-vop (make-value-cell)
138 (:args (value :to :save :scs (descriptor-reg any-reg)))
139 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
140 (:info stack-allocate-p)
141 (:results (result :scs (descriptor-reg)))
142 (:generator 10
143 (with-fixed-allocation (result pa-flag value-cell-header-widetag
144 value-cell-size :stack-allocate-p stack-allocate-p)
145 (storew value result value-cell-value-slot other-pointer-lowtag))))
147 ;;;; Automatic allocators for primitive objects.
149 (define-vop (make-unbound-marker)
150 (:args)
151 (:results (result :scs (descriptor-reg any-reg)))
152 (:generator 1
153 (inst mov result unbound-marker-widetag)))
155 (define-vop (make-funcallable-instance-tramp)
156 (:args)
157 (:results (result :scs (any-reg)))
158 (:temporary (:sc interior-reg) lip)
159 (:generator 1
160 (let ((fixup (gen-label)))
161 (inst load-from-label result lip fixup)
162 (assemble (*elsewhere*)
163 (emit-label fixup)
164 (inst word (make-fixup 'funcallable-instance-tramp :assembly-routine))))))
166 (define-vop (fixed-alloc)
167 (:args)
168 (:info name words type lowtag stack-allocate-p)
169 (:ignore name)
170 (:results (result :scs (descriptor-reg)))
171 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
172 (:generator 4
173 (with-fixed-allocation (result pa-flag type words
174 :lowtag lowtag
175 :stack-allocate-p stack-allocate-p))))
177 (define-vop (var-alloc)
178 (:args (extra :scs (any-reg)))
179 (:arg-types positive-fixnum)
180 (:info name words type lowtag)
181 (:ignore name)
182 (:results (result :scs (descriptor-reg)))
183 (:temporary (:scs (any-reg)) bytes)
184 (:temporary (:scs (non-descriptor-reg)) header)
185 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
186 (:generator 6
187 ;; Build the object header, assuming that the header was in WORDS
188 ;; but should not be in the header
189 (inst add bytes extra (* (1- words) n-word-bytes))
190 (inst mov header (lsl bytes (- n-widetag-bits n-fixnum-tag-bits)))
191 (inst add header header type)
192 ;; Add the object header to the allocation size and round up to
193 ;; the allocation granularity
194 (inst add bytes bytes (* 2 n-word-bytes))
195 (inst bic bytes bytes lowtag-mask)
196 ;; Allocate the object and set its header
197 (pseudo-atomic (pa-flag)
198 (allocation result bytes lowtag :flag-tn pa-flag)
199 (storew header result 0 lowtag))))