96621a3553b53e2bd1e9c87b84a180ad57f5d895
[sbcl.git] / src / compiler / alpha / alloc.lisp
1 ;;;; allocation VOPs for the Alpha port
2
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; LIST and LIST*
15 (define-vop (list-or-list*)
16   (:args (things :more t))
17   (:temporary (:scs (descriptor-reg) :type list) ptr)
18   (:temporary (:scs (descriptor-reg)) temp)
19   (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
20               res)
21   (:info num)
22   (:results (result :scs (descriptor-reg)))
23   (:variant-vars star)
24   (:policy :safe)
25   (:node-var node)
26   (:generator 0
27     (cond ((zerop num)
28            (move null-tn result))
29           ((and star (= num 1))
30            (move (tn-ref-tn things) result))
31           (t
32            (macrolet
33                ((store-car (tn list &optional (slot cons-car-slot))
34                   `(let ((reg
35                           (sc-case ,tn
36                             ((any-reg descriptor-reg) ,tn)
37                             (zero zero-tn)
38                             (null null-tn)
39                             (control-stack
40                              (load-stack-tn temp ,tn)
41                              temp))))
42                      (storew reg ,list ,slot list-pointer-lowtag))))
43              (let* ((dx-p (node-stack-allocate-p node))
44                     (cons-cells (if star (1- num) num))
45                     (space (* (pad-data-block cons-size) cons-cells)))
46                (pseudo-atomic (:extra (if dx-p 0 space))
47                  (cond (dx-p
48                         (align-csp res)
49                         (inst bis csp-tn list-pointer-lowtag res)
50                         (inst lda csp-tn space csp-tn))
51                        (t
52                         (inst bis alloc-tn list-pointer-lowtag res)))
53                  (move res ptr)
54                  (dotimes (i (1- cons-cells))
55                    (store-car (tn-ref-tn things) ptr)
56                    (setf things (tn-ref-across things))
57                    (inst lda ptr (pad-data-block cons-size) ptr)
58                    (storew ptr ptr
59                            (- cons-cdr-slot cons-size)
60                            list-pointer-lowtag))
61                  (store-car (tn-ref-tn things) ptr)
62                  (cond (star
63                         (setf things (tn-ref-across things))
64                         (store-car (tn-ref-tn things) ptr cons-cdr-slot))
65                        (t
66                         (storew null-tn ptr
67                                 cons-cdr-slot list-pointer-lowtag)))
68                  (aver (null (tn-ref-across things)))
69                  (move res result))))))))
70
71 (define-vop (list list-or-list*)
72   (:variant nil))
73
74 (define-vop (list* list-or-list*)
75   (:variant t))
76 \f
77 ;;;; special purpose inline allocators
78
79 (define-vop (allocate-code-object)
80   (:args (boxed-arg :scs (any-reg))
81          (unboxed-arg :scs (any-reg)))
82   (:results (result :scs (descriptor-reg)))
83   (:temporary (:scs (non-descriptor-reg)) ndescr)
84   (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
85   (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
86   (:generator 100
87     (inst li (lognot lowtag-mask) ndescr)
88     (inst lda boxed (fixnumize (1+ code-trace-table-offset-slot))
89           boxed-arg)
90     (inst and boxed ndescr boxed)
91     (inst srl unboxed-arg word-shift unboxed)
92     (inst lda unboxed lowtag-mask unboxed)
93     (inst and unboxed ndescr unboxed)
94     (inst sll boxed (- n-widetag-bits word-shift) ndescr)
95     (inst bis ndescr code-header-widetag ndescr)
96
97     (pseudo-atomic ()
98       (inst bis alloc-tn other-pointer-lowtag result)
99       (storew ndescr result 0 other-pointer-lowtag)
100       (storew unboxed result code-code-size-slot other-pointer-lowtag)
101       (storew null-tn result code-entry-points-slot other-pointer-lowtag)
102       (inst addq alloc-tn boxed alloc-tn)
103       (inst addq alloc-tn unboxed alloc-tn))
104
105     (storew null-tn result code-debug-info-slot other-pointer-lowtag)))
106
107 (define-vop (make-fdefn)
108   (:policy :fast-safe)
109   (:translate make-fdefn)
110   (:args (name :scs (descriptor-reg) :to :eval))
111   (:temporary (:scs (non-descriptor-reg)) temp)
112   (:results (result :scs (descriptor-reg) :from :argument))
113   (:generator 37
114     (with-fixed-allocation (result temp fdefn-widetag fdefn-size)
115       (storew name result fdefn-name-slot other-pointer-lowtag)
116       (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
117       (inst li (make-fixup "undefined_tramp" :foreign) temp)
118       (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
119
120 (define-vop (make-closure)
121   (:args (function :to :save :scs (descriptor-reg)))
122   (:info length stack-allocate-p)
123   (:temporary (:scs (non-descriptor-reg)) temp)
124   (:results (result :scs (descriptor-reg)))
125   (:generator 10
126     (let* ((size (+ length closure-info-offset))
127            (alloc-size (pad-data-block size)))
128       (inst li
129             (logior (ash (1- size) n-widetag-bits) closure-header-widetag)
130             temp)
131       (pseudo-atomic (:extra (if stack-allocate-p 0 alloc-size))
132         (cond (stack-allocate-p
133                (align-csp result)
134                (inst bis csp-tn fun-pointer-lowtag result)
135                (inst lda csp-tn alloc-size csp-tn))
136               (t
137                (inst bis alloc-tn fun-pointer-lowtag result)))
138         (storew temp result 0 fun-pointer-lowtag)
139         (storew function result closure-fun-slot fun-pointer-lowtag)))))
140
141 ;;; The compiler likes to be able to directly make value cells.
142 (define-vop (make-value-cell)
143   (:args (value :to :save :scs (descriptor-reg any-reg null zero)))
144   (:temporary (:scs (non-descriptor-reg)) temp)
145   (:info stack-allocate-p)
146   (:ignore stack-allocate-p)
147   (:results (result :scs (descriptor-reg)))
148   (:generator 10
149     (with-fixed-allocation
150         (result temp value-cell-header-widetag value-cell-size)
151       (storew value result value-cell-value-slot other-pointer-lowtag))))
152 \f
153 ;;;; automatic allocators for primitive objects
154
155 (define-vop (make-unbound-marker)
156   (:args)
157   (:results (result :scs (any-reg)))
158   (:generator 1
159     (inst li unbound-marker-widetag result)))
160
161 (define-vop (make-funcallable-instance-tramp)
162   (:args)
163   (:results (result :scs (any-reg)))
164   (:generator 1
165     (inst li (make-fixup "funcallable_instance_tramp" :foreign) result)))
166
167 (define-vop (fixed-alloc)
168   (:args)
169   (:info name words type lowtag stack-allocate-p)
170   (:ignore name stack-allocate-p)
171   (:results (result :scs (descriptor-reg)))
172   (:temporary (:scs (non-descriptor-reg)) temp)
173   (:generator 4
174     (pseudo-atomic (:extra (pad-data-block words))
175       (inst bis alloc-tn lowtag result)
176       (when type
177         (inst li (logior (ash (1- words) n-widetag-bits) type) temp)
178         (storew temp result 0 lowtag)))))
179
180 (define-vop (var-alloc)
181   (:args (extra :scs (any-reg)))
182   (:arg-types positive-fixnum)
183   (:info name words type lowtag)
184   (:ignore name)
185   (:results (result :scs (descriptor-reg)))
186   (:temporary (:scs (non-descriptor-reg)) header)
187   (:temporary (:scs (non-descriptor-reg)) bytes)
188   (:generator 6
189     (inst lda bytes (* (1+ words) n-word-bytes) extra)
190     (inst sll bytes (- n-widetag-bits 2) header)
191     (inst lda header (+ (ash -2 n-widetag-bits) type) header)
192     (inst srl bytes n-lowtag-bits bytes)
193     (inst sll bytes n-lowtag-bits bytes)
194     (pseudo-atomic ()
195       (inst bis alloc-tn lowtag result)
196       (storew header result 0 lowtag)
197       (inst addq alloc-tn bytes alloc-tn))))