Remove "-HEADER-" from SYMBOL and VALUE-CELL widetag names
[sbcl.git] / src / compiler / arm64 / alloc.lisp
blob3745607eb7b7fca493f56b4a538dfe50221a3397
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 (descriptor-reg) :type list :to (:result 0) :target result)
18 res)
19 (:temporary (:sc non-descriptor-reg) pa-flag temp)
20 (:temporary (:scs (interior-reg)) lip)
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 :lip lip)
48 (move ptr res)
49 (dotimes (i (1- cons-cells))
50 (storew (maybe-load (tn-ref-tn things)) ptr
51 cons-car-slot list-pointer-lowtag)
52 (setf things (tn-ref-across things))
53 (inst add ptr ptr (pad-data-block cons-size))
54 (storew ptr ptr
55 (- cons-cdr-slot cons-size)
56 list-pointer-lowtag))
57 (storew (maybe-load (tn-ref-tn things)) ptr
58 cons-car-slot list-pointer-lowtag)
59 (storew (if star
60 (maybe-load (tn-ref-tn (tn-ref-across things)))
61 null-tn)
62 ptr cons-cdr-slot list-pointer-lowtag))
63 (move result res)))))))
65 (define-vop (list list-or-list*)
66 (:variant nil))
68 (define-vop (list* list-or-list*)
69 (:variant t))
71 ;;;; Special purpose inline allocators.
72 #!-gencgc
73 (define-vop (allocate-code-object)
74 (:args (boxed-arg :scs (any-reg))
75 (unboxed-arg :scs (any-reg)))
76 (:results (result :scs (descriptor-reg)))
77 (:temporary (:scs (non-descriptor-reg)) ndescr)
78 (:temporary (:scs (non-descriptor-reg)) size)
79 (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
80 (:temporary (:scs (non-descriptor-reg)) unboxed)
81 (:temporary (:sc non-descriptor-reg) pa-flag)
82 (:temporary (:scs (interior-reg)) lip)
83 (:generator 100
84 (inst add boxed boxed-arg (fixnumize (1+ code-constants-offset)))
85 (inst and boxed boxed (bic-mask lowtag-mask))
86 (inst lsr unboxed unboxed-arg word-shift)
87 (inst add unboxed unboxed lowtag-mask)
88 (inst and unboxed unboxed (bic-mask lowtag-mask))
89 (inst lsl ndescr boxed (- n-widetag-bits word-shift))
90 (inst orr ndescr ndescr code-header-widetag)
91 (inst add size boxed unboxed)
92 (pseudo-atomic (pa-flag)
93 (allocation result size other-pointer-lowtag :flag-tn pa-flag :lip lip)
94 (storew ndescr result 0 other-pointer-lowtag)
95 (storew unboxed-arg result code-code-size-slot other-pointer-lowtag)
96 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
98 (define-vop (make-fdefn)
99 (:args (name :scs (descriptor-reg) :to :eval))
100 (:temporary (:sc non-descriptor-reg) pa-flag temp)
101 (:temporary (:scs (interior-reg)) lip)
102 (:results (result :scs (descriptor-reg) :from :argument))
103 (:policy :fast-safe)
104 (:translate make-fdefn)
105 (:generator 37
106 (with-fixed-allocation (result pa-flag fdefn-widetag fdefn-size :lip lip)
107 (load-inline-constant temp '(:fixup undefined-tramp :assembly-routine) lip)
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))))
112 (define-vop (make-closure)
113 (:args (function :to :save :scs (descriptor-reg)))
114 (:info length stack-allocate-p)
115 (:temporary (:sc non-descriptor-reg) pa-flag)
116 (:temporary (:scs (interior-reg)) lip)
117 (:results (result :scs (descriptor-reg)))
118 (:generator 10
119 (let* ((size (+ length closure-info-offset))
120 (alloc-size (pad-data-block size)))
121 (pseudo-atomic (pa-flag)
122 (allocation result alloc-size
123 fun-pointer-lowtag
124 :flag-tn pa-flag
125 :stack-allocate-p stack-allocate-p
126 :lip lip)
127 (load-immediate-word pa-flag
128 (logior
129 (ash (1- size) n-widetag-bits)
130 closure-header-widetag))
131 (storew pa-flag result 0 fun-pointer-lowtag)
132 (storew function result closure-fun-slot fun-pointer-lowtag)))))
134 ;;; The compiler likes to be able to directly make value cells.
136 (define-vop (make-value-cell)
137 (:args (value :to :save :scs (descriptor-reg any-reg)))
138 (:temporary (:sc non-descriptor-reg) pa-flag)
139 (:temporary (:scs (interior-reg)) lip)
140 (:info stack-allocate-p)
141 (:results (result :scs (descriptor-reg)))
142 (:generator 10
143 (with-fixed-allocation (result pa-flag value-cell-widetag
144 value-cell-size :stack-allocate-p stack-allocate-p
145 :lip lip)
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 (:temporary (:scs (interior-reg)) lip)
159 (:results (result :scs (any-reg)))
160 (:generator 1
161 (load-inline-constant result '(:fixup funcallable-instance-tramp :assembly-routine) lip)))
163 (define-vop (fixed-alloc)
164 (:args)
165 (:info name words type lowtag stack-allocate-p)
166 (:ignore name)
167 (:results (result :scs (descriptor-reg)))
168 (:temporary (:sc non-descriptor-reg) pa-flag)
169 (:temporary (:scs (interior-reg)) lip)
170 (:generator 4
171 (with-fixed-allocation (result pa-flag type words
172 :lowtag lowtag
173 :stack-allocate-p stack-allocate-p
174 :lip lip))))
176 (define-vop (var-alloc)
177 (:args (extra :scs (any-reg)))
178 (:arg-types positive-fixnum)
179 (:info name words type lowtag)
180 (:ignore name)
181 (:results (result :scs (descriptor-reg)))
182 (:temporary (:scs (any-reg) :from :argument) bytes)
183 (:temporary (:sc non-descriptor-reg) pa-flag header)
184 (:temporary (:scs (interior-reg)) lip)
185 (:generator 6
186 ;; Build the object header, assuming that the header was in WORDS
187 ;; but should not be in the header
188 (inst lsl bytes extra (- word-shift n-fixnum-tag-bits))
189 (inst add bytes bytes (add-sub-immediate (* (1- words) n-word-bytes)))
190 (inst lsl header bytes (- n-widetag-bits word-shift))
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 and bytes bytes (bic-mask lowtag-mask))
196 ;; Allocate the object and set its header
197 (pseudo-atomic (pa-flag)
198 (allocation result bytes lowtag :flag-tn pa-flag :lip lip)
199 (storew header result 0 lowtag))))