36e7f0a531fa996f4b56140da9076c1955955e0c
[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
16 (define-vop (list-or-list*)
17   (:args (things :more t))
18   (:temporary (:scs (descriptor-reg) :type list) ptr)
19   (:temporary (:scs (descriptor-reg)) temp)
20   (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
21               res)
22   (:info num)
23   (:results (result :scs (descriptor-reg)))
24   (:variant-vars star)
25   (:policy :safe)
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 ((cons-cells (if star (1- num) num)))
44                (pseudo-atomic (:extra (* (pad-data-block cons-size)
45                                          cons-cells))
46                  (inst bis alloc-tn list-pointer-lowtag res)
47                  (move res ptr)
48                  (dotimes (i (1- cons-cells))
49                    (store-car (tn-ref-tn things) ptr)
50                    (setf things (tn-ref-across things))
51                    (inst lda ptr (pad-data-block cons-size) ptr)
52                    (storew ptr ptr
53                            (- cons-cdr-slot cons-size)
54                            list-pointer-lowtag))
55                  (store-car (tn-ref-tn things) ptr)
56                  (cond (star
57                         (setf things (tn-ref-across things))
58                         (store-car (tn-ref-tn things) ptr cons-cdr-slot))
59                        (t
60                         (storew null-tn ptr
61                                 cons-cdr-slot list-pointer-lowtag)))
62                  (assert (null (tn-ref-across things)))
63                  (move res result))))))))
64
65 (define-vop (list list-or-list*)
66   (:variant nil))
67
68 (define-vop (list* list-or-list*)
69   (:variant t))
70 \f
71 ;;;; special purpose inline allocators
72
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 (any-reg) :from (:argument 0)) boxed)
79   (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
80   (:generator 100
81     (inst li (lognot lowtag-mask) ndescr)
82     (inst lda boxed (fixnumize (1+ code-trace-table-offset-slot))
83           boxed-arg)
84     (inst and boxed ndescr boxed)
85     (inst srl unboxed-arg word-shift unboxed)
86     (inst lda unboxed lowtag-mask unboxed)
87     (inst and unboxed ndescr unboxed)
88     (inst sll boxed (- n-widetag-bits word-shift) ndescr)
89     (inst bis ndescr code-header-widetag ndescr)
90     
91     (pseudo-atomic ()
92       (inst bis alloc-tn other-pointer-lowtag result)
93       (storew ndescr result 0 other-pointer-lowtag)
94       (storew unboxed result code-code-size-slot other-pointer-lowtag)
95       (storew null-tn result code-entry-points-slot other-pointer-lowtag)
96       (inst addq alloc-tn boxed alloc-tn)
97       (inst addq alloc-tn unboxed alloc-tn))
98
99     (storew null-tn result code-debug-info-slot other-pointer-lowtag)))
100
101 (define-vop (make-fdefn)
102   (:policy :fast-safe)
103   (:translate make-fdefn)
104   (:args (name :scs (descriptor-reg) :to :eval))
105   (:temporary (:scs (non-descriptor-reg)) temp)
106   (:results (result :scs (descriptor-reg) :from :argument))
107   (:generator 37
108     (with-fixed-allocation (result temp fdefn-widetag fdefn-size)
109       (storew name result fdefn-name-slot other-pointer-lowtag)
110       (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
111       (inst li (make-fixup "undefined_tramp" :foreign) temp)
112       (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
113
114 (define-vop (make-closure)
115   (:args (function :to :save :scs (descriptor-reg)))
116   (:info length)
117   (:temporary (:scs (non-descriptor-reg)) temp)
118   (:results (result :scs (descriptor-reg)))
119   (:generator 10
120     (let ((size (+ length closure-info-offset)))
121       (inst li
122             (logior (ash (1- size) n-widetag-bits) closure-header-widetag)
123             temp)
124       (pseudo-atomic (:extra (pad-data-block size))
125         (inst bis alloc-tn fun-pointer-lowtag result)
126         (storew temp result 0 fun-pointer-lowtag))
127       (storew function result closure-fun-slot fun-pointer-lowtag))))
128
129 ;;; The compiler likes to be able to directly make value cells.
130 ;;; 
131 (define-vop (make-value-cell)
132   (:args (value :to :save :scs (descriptor-reg any-reg null zero)))
133   (:temporary (:scs (non-descriptor-reg)) temp)
134   (:results (result :scs (descriptor-reg)))
135   (:generator 10
136     (with-fixed-allocation
137         (result temp value-cell-header-widetag value-cell-size))
138     (storew value result value-cell-value-slot other-pointer-lowtag)))
139
140 \f
141 ;;;; automatic allocators for primitive objects
142
143 (define-vop (make-unbound-marker)
144   (:args)
145   (:results (result :scs (any-reg)))
146   (:generator 1
147     (inst li unbound-marker-widetag result)))
148
149 (define-vop (fixed-alloc)
150   (:args)
151   (:info name words type lowtag)
152   (:ignore name)
153   (:results (result :scs (descriptor-reg)))
154   (:temporary (:scs (non-descriptor-reg)) temp)
155   (:generator 4
156     (pseudo-atomic (:extra (pad-data-block words))
157       (inst bis alloc-tn lowtag result)
158       (when type
159         (inst li (logior (ash (1- words) n-widetag-bits) type) temp)
160         (storew temp result 0 lowtag)))))
161
162 (define-vop (var-alloc)
163   (:args (extra :scs (any-reg)))
164   (:arg-types positive-fixnum)
165   (:info name words type lowtag)
166   (:ignore name)
167   (:results (result :scs (descriptor-reg)))
168   (:temporary (:scs (non-descriptor-reg)) header)
169   (:temporary (:scs (non-descriptor-reg)) bytes)
170   (:generator 6
171     (inst lda bytes (* (1+ words) n-word-bytes) extra)
172     (inst sll bytes (- n-widetag-bits 2) header)
173     (inst lda header (+ (ash -2 n-widetag-bits) type) header)
174     (inst srl bytes n-lowtag-bits bytes)
175     (inst sll bytes n-lowtag-bits bytes)
176     (pseudo-atomic ()
177       (inst bis alloc-tn lowtag result)
178       (storew header result 0 lowtag)
179       (inst addq alloc-tn bytes alloc-tn))))