0.6.12.5:
[sbcl.git] / src / compiler / alpha / values.lisp
1 ;;;; the Alpha implementation of unknown-values VOPs
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
14 (define-vop (reset-stack-pointer)
15   (:args (ptr :scs (any-reg)))
16   (:generator 1
17     (move ptr csp-tn)))
18
19 ;;; Push some values onto the stack, returning the start and number of
20 ;;; values pushed as results. It is assumed that the Vals are wired to
21 ;;; the standard argument locations. Nvals is the number of values to
22 ;;; push.
23 ;;;
24 ;;; The generator cost is pseudo-random. We could get it right by
25 ;;; defining a bogus SC that reflects the costs of the
26 ;;; memory-to-memory moves for each operand, but this seems
27 ;;; unworthwhile.
28 (define-vop (push-values)
29   (:args
30    (vals :more t))
31   (:results
32    (start :scs (any-reg))
33    (count :scs (any-reg)))
34   (:info nvals)
35   (:temporary (:scs (descriptor-reg)) temp)
36   (:temporary (:scs (descriptor-reg)
37                :to (:result 0)
38                :target start)
39               start-temp)
40   (:generator 20
41     (move csp-tn start-temp)
42     (inst lda csp-tn (* nvals word-bytes) csp-tn)
43     (do ((val vals (tn-ref-across val))
44          (i 0 (1+ i)))
45         ((null val))
46       (let ((tn (tn-ref-tn val)))
47         (sc-case tn
48           (descriptor-reg
49            (storew tn start-temp i))
50           (control-stack
51            (load-stack-tn temp tn)
52            (storew temp start-temp i)))))
53     (move start-temp start)
54     (inst li (fixnumize nvals) count)))
55
56 ;;; Push a list of values on the stack, returning Start and Count as
57 ;;; used in unknown values continuations.
58 (define-vop (values-list)
59   (:args (arg :scs (descriptor-reg) :target list))
60   (:arg-types list)
61   (:policy :fast-safe)
62   (:results (start :scs (any-reg))
63             (count :scs (any-reg)))
64   (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
65   (:temporary (:scs (non-descriptor-reg)) temp)
66   (:temporary (:scs (non-descriptor-reg)) ndescr)
67   (:vop-var vop)
68   (:save-p :compute-only)
69   (:generator 0
70     (move arg list)
71     (move csp-tn start)
72     
73     LOOP
74     (inst cmpeq list null-tn temp)
75     (inst bne temp done)
76     (loadw temp list cons-car-slot list-pointer-type)
77     (loadw list list cons-cdr-slot list-pointer-type)
78     (inst lda csp-tn word-bytes csp-tn)
79     (storew temp csp-tn -1)
80     (inst and list lowtag-mask ndescr)
81     (inst xor ndescr list-pointer-type ndescr)
82     (inst beq ndescr loop)
83     (error-call vop bogus-argument-to-values-list-error list)
84     
85     DONE
86     (inst subq csp-tn start count)))
87
88 ;;; Copy the &MORE arg block to the top of the stack so we can use
89 ;;; them as function arguments.
90 (define-vop (%more-arg-values)
91   (:args (context :scs (descriptor-reg any-reg) :target src)
92          (skip :scs (any-reg zero immediate))
93          (num :scs (any-reg) :target count))
94   (:arg-types * positive-fixnum positive-fixnum)
95   (:temporary (:sc any-reg :from (:argument 0)) src)
96   (:temporary (:sc any-reg :from (:argument 2)) dst)
97   (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
98   (:temporary (:sc non-descriptor-reg) temp1)
99   (:results (start :scs (any-reg))
100             (count :scs (any-reg)))
101   (:generator 20
102     (sc-case skip
103       (zero
104        (move context src))
105       (immediate
106        (inst lda src (* (tn-value skip) word-bytes) context))
107       (any-reg
108        (inst addq context skip src)))
109     (move num count)
110     (inst move csp-tn start)
111     (inst beq num done)
112     (inst move csp-tn dst)
113     (inst addq csp-tn count csp-tn)
114     LOOP
115     (inst ldl temp 0 src)
116     (inst addq src 4 src)
117     (inst addq dst 4 dst)
118     (inst stl temp -4 dst)
119     (inst cmpeq dst csp-tn temp1)
120     (inst beq temp1 loop)
121     DONE))