1 ;;;; allocation VOPs for Mips
3 ;;;; This software is part of the SBCL system. See the README file for
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.
15 (defoptimizer (list stack-allocate-result
) ((&rest 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
)
26 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
28 (:results
(result :scs
(descriptor-reg)))
34 (move result null-tn
))
36 (move result
(tn-ref-tn things
)))
39 ((store-car (tn list
&optional
(slot cons-car-slot
))
42 ((any-reg descriptor-reg zero null
)
45 (load-stack-tn temp
,tn
)
47 (storew reg
,list
,slot list-pointer-lowtag
))))
48 (let* ((dx-p (node-stack-allocate-p node
))
49 (cons-cells (if star
(1- num
) num
))
50 (alloc (* (pad-data-block cons-size
) cons-cells
)))
51 (pseudo-atomic (pa-flag :extra
(if dx-p
0 alloc
))
54 (inst srl res
(if dx-p csp-tn alloc-tn
) n-lowtag-bits
)
55 (inst sll res n-lowtag-bits
)
56 (inst or res list-pointer-lowtag
)
58 (inst addu csp-tn alloc
))
60 (dotimes (i (1- cons-cells
))
61 (store-car (tn-ref-tn things
) ptr
)
62 (setf things
(tn-ref-across things
))
63 (inst addu ptr ptr
(pad-data-block cons-size
))
65 (- cons-cdr-slot cons-size
)
67 (store-car (tn-ref-tn things
) ptr
)
69 (setf things
(tn-ref-across things
))
70 (store-car (tn-ref-tn things
) ptr cons-cdr-slot
))
73 cons-cdr-slot list-pointer-lowtag
)))
74 (aver (null (tn-ref-across things
)))
75 (move result res
))))))))
77 (define-vop (list list-or-list
*)
80 (define-vop (list* list-or-list
*)
83 ;;;; Special purpose inline allocators.
85 (define-vop (allocate-code-object)
86 (:args
(boxed-arg :scs
(any-reg))
87 (unboxed-arg :scs
(any-reg)))
88 (:results
(result :scs
(descriptor-reg)))
89 (:temporary
(:scs
(non-descriptor-reg)) ndescr
)
90 (:temporary
(:scs
(any-reg) :from
(:argument
0)) boxed
)
91 (:temporary
(:scs
(non-descriptor-reg) :from
(:argument
1)) unboxed
)
92 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
94 (inst li ndescr
(lognot lowtag-mask
))
95 (inst addu boxed boxed-arg
96 (fixnumize (1+ code-trace-table-offset-slot
)))
97 (inst and boxed ndescr
)
98 (inst srl unboxed unboxed-arg word-shift
)
99 (inst addu unboxed unboxed lowtag-mask
)
100 (inst and unboxed ndescr
)
101 (inst sll ndescr boxed
(- n-widetag-bits word-shift
))
102 (inst or ndescr code-header-widetag
)
104 (pseudo-atomic (pa-flag)
105 (inst or result alloc-tn other-pointer-lowtag
)
106 (inst addu alloc-tn boxed
)
107 (storew ndescr result
0 other-pointer-lowtag
)
108 (storew unboxed result code-code-size-slot other-pointer-lowtag
)
109 (inst addu alloc-tn unboxed
)
110 (storew null-tn result code-entry-points-slot other-pointer-lowtag
)
111 (storew null-tn result code-debug-info-slot other-pointer-lowtag
))))
113 (define-vop (make-fdefn)
115 (:translate make-fdefn
)
116 (:args
(name :scs
(descriptor-reg) :to
:eval
))
117 (:temporary
(:scs
(non-descriptor-reg)) temp
)
118 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
119 (:results
(result :scs
(descriptor-reg) :from
:argument
))
121 (with-fixed-allocation (result pa-flag temp fdefn-widetag fdefn-size
)
122 (inst li temp
(make-fixup "undefined_tramp" :foreign
))
123 (storew name result fdefn-name-slot other-pointer-lowtag
)
124 (storew null-tn result fdefn-fun-slot other-pointer-lowtag
)
125 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag
))))
127 (define-vop (make-closure)
128 (:args
(function :to
:save
:scs
(descriptor-reg)))
129 (:info length stack-allocate-p
)
130 (:temporary
(:scs
(non-descriptor-reg)) temp
)
131 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
132 (:results
(result :scs
(descriptor-reg)))
134 (let* ((size (+ length closure-info-offset
))
135 (alloc-size (pad-data-block size
)))
136 (pseudo-atomic (pa-flag :extra
(if stack-allocate-p
0 alloc-size
))
137 (cond (stack-allocate-p
139 (inst srl result csp-tn n-lowtag-bits
)
140 (inst addu csp-tn alloc-size
))
142 (inst srl result alloc-tn n-lowtag-bits
)))
143 (inst sll result n-lowtag-bits
)
144 (inst or result fun-pointer-lowtag
)
145 (inst li temp
(logior (ash (1- size
) n-widetag-bits
)
146 closure-header-widetag
))
147 (storew temp result
0 fun-pointer-lowtag
))
148 (storew function result closure-fun-slot fun-pointer-lowtag
))))
150 ;;; 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 null zero
)))
153 (:temporary
(:scs
(non-descriptor-reg)) temp
)
154 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
155 (:info stack-allocate-p
)
156 (:ignore stack-allocate-p
)
157 (:results
(result :scs
(descriptor-reg)))
159 (with-fixed-allocation (result pa-flag temp value-cell-header-widetag value-cell-size
)
160 (storew value result value-cell-value-slot other-pointer-lowtag
))))
163 ;;;; Automatic allocators for primitive objects.
165 (define-vop (make-unbound-marker)
167 (:results
(result :scs
(any-reg)))
169 (inst li result unbound-marker-widetag
)))
171 (define-vop (make-funcallable-instance-tramp)
173 (:results
(result :scs
(any-reg)))
175 (inst li result
(make-fixup "funcallable_instance_tramp" :foreign
))))
177 (define-vop (fixed-alloc)
179 (:info name words type lowtag
)
181 (:results
(result :scs
(descriptor-reg)))
182 (:temporary
(:scs
(non-descriptor-reg)) temp
)
183 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
185 (pseudo-atomic (pa-flag :extra
(pad-data-block words
))
186 (inst or result alloc-tn lowtag
)
188 (inst li temp
(logior (ash (1- words
) n-widetag-bits
) type
))
189 (storew temp result
0 lowtag
)))))
191 (define-vop (var-alloc)
192 (:args
(extra :scs
(any-reg)))
193 (:arg-types positive-fixnum
)
194 (:info name words type lowtag
)
196 (:results
(result :scs
(descriptor-reg)))
197 (:temporary
(:scs
(any-reg)) bytes
)
198 (:temporary
(:scs
(non-descriptor-reg)) header
)
199 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
201 (inst addu bytes extra
(* (1+ words
) n-word-bytes
))
202 (inst sll header bytes
(- n-widetag-bits
2))
203 (inst addu header header
(+ (ash -
2 n-widetag-bits
) type
))
204 (inst srl bytes bytes n-lowtag-bits
)
205 (inst sll bytes bytes n-lowtag-bits
)
206 (pseudo-atomic (pa-flag)
207 (inst or result alloc-tn lowtag
)
208 (storew header result
0 lowtag
)
209 (inst addu alloc-tn alloc-tn bytes
))))