Fix CLISP-hosted build.
[sbcl.git] / src / compiler / arm / alloc.lisp
blobc35d16c23b2db883dcd13736e8f8d2190ec9ff2c
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-entry-points-slot other-pointer-lowtag)
95 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
97 (define-vop (make-fdefn)
98 (:args (name :scs (descriptor-reg) :to :eval))
99 (:temporary (:scs (non-descriptor-reg)) temp)
100 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
101 (:results (result :scs (descriptor-reg) :from :argument))
102 (:temporary (:sc interior-reg) lip)
103 (:policy :fast-safe)
104 (:translate make-fdefn)
105 (:generator 37
106 (let ((undefined-tramp-fixup (gen-label)))
107 (with-fixed-allocation (result pa-flag fdefn-widetag fdefn-size)
108 (inst load-from-label temp lip undefined-tramp-fixup)
109 (storew name result fdefn-name-slot other-pointer-lowtag)
110 (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
111 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))
112 (assemble (*elsewhere*)
113 (emit-label undefined-tramp-fixup)
114 (inst word (make-fixup "undefined_tramp" :foreign))))))
116 (define-vop (make-closure)
117 (:args (function :to :save :scs (descriptor-reg)))
118 (:info length stack-allocate-p)
119 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
120 (:results (result :scs (descriptor-reg)))
121 (:generator 10
122 (let* ((size (+ length closure-info-offset))
123 (alloc-size (pad-data-block size)))
124 (pseudo-atomic (pa-flag)
125 (allocation result alloc-size
126 fun-pointer-lowtag
127 :flag-tn pa-flag
128 :stack-allocate-p stack-allocate-p)
129 (load-immediate-word pa-flag
130 (logior
131 (ash (1- size) n-widetag-bits)
132 closure-header-widetag))
133 (storew pa-flag result 0 fun-pointer-lowtag)
134 (storew function result closure-fun-slot fun-pointer-lowtag)))))
136 ;;; The compiler likes to be able to directly make value cells.
138 (define-vop (make-value-cell)
139 (:args (value :to :save :scs (descriptor-reg any-reg)))
140 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
141 (:info stack-allocate-p)
142 (:results (result :scs (descriptor-reg)))
143 (:generator 10
144 (with-fixed-allocation (result pa-flag value-cell-header-widetag
145 value-cell-size :stack-allocate-p stack-allocate-p)
146 (storew value result value-cell-value-slot other-pointer-lowtag))))
148 ;;;; Automatic allocators for primitive objects.
150 (define-vop (make-unbound-marker)
151 (:args)
152 (:results (result :scs (descriptor-reg any-reg)))
153 (:generator 1
154 (inst mov result unbound-marker-widetag)))
156 (define-vop (make-funcallable-instance-tramp)
157 (:args)
158 (:results (result :scs (any-reg)))
159 (:temporary (:sc interior-reg) lip)
160 (:generator 1
161 (let ((fixup (gen-label)))
162 (inst load-from-label result lip fixup)
163 (assemble (*elsewhere*)
164 (emit-label fixup)
165 (inst word (make-fixup "funcallable_instance_tramp" :foreign))))))
167 (define-vop (fixed-alloc)
168 (:args)
169 (:info name words type lowtag stack-allocate-p)
170 (:ignore name)
171 (:results (result :scs (descriptor-reg)))
172 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
173 (:generator 4
174 (with-fixed-allocation (result pa-flag type words
175 :lowtag lowtag
176 :stack-allocate-p stack-allocate-p))))
178 (define-vop (var-alloc)
179 (:args (extra :scs (any-reg)))
180 (:arg-types positive-fixnum)
181 (:info name words type lowtag)
182 (:ignore name)
183 (:results (result :scs (descriptor-reg)))
184 (:temporary (:scs (any-reg)) bytes)
185 (:temporary (:scs (non-descriptor-reg)) header)
186 (:temporary (:sc non-descriptor-reg :offset ocfp-offset) pa-flag)
187 (:generator 6
188 ;; Build the object header, assuming that the header was in WORDS
189 ;; but should not be in the header
190 (inst add bytes extra (* (1- words) n-word-bytes))
191 (inst mov header (lsl bytes (- n-widetag-bits n-fixnum-tag-bits)))
192 (inst add header header type)
193 ;; Add the object header to the allocation size and round up to
194 ;; the allocation granularity
195 (inst add bytes bytes (* 2 n-word-bytes))
196 (inst bic bytes bytes lowtag-mask)
197 ;; Allocate the object and set its header
198 (pseudo-atomic (pa-flag)
199 (allocation result bytes lowtag :flag-tn pa-flag)
200 (storew header result 0 lowtag))))