0.8.1.50
[sbcl.git] / src / compiler / ppc / values.lisp
1 ;;;
2 ;;; Written by Rob MacLachlan
3 ;;;
4 ;;; Converted for SPARC by William Lott.
5 ;;; 
6
7 (in-package "SB!VM")
8
9 (define-vop (reset-stack-pointer)
10   (:args (ptr :scs (any-reg)))
11   (:generator 1
12     (move csp-tn ptr)))
13
14
15 ;;; Push some values onto the stack, returning the start and number of values
16 ;;; pushed as results.  It is assumed that the Vals are wired to the standard
17 ;;; argument locations.  Nvals is the number of values to push.
18 ;;;
19 ;;; The generator cost is pseudo-random.  We could get it right by defining a
20 ;;; bogus SC that reflects the costs of the memory-to-memory moves for each
21 ;;; operand, but this seems unworthwhile.
22 ;;;
23 (define-vop (push-values)
24   (:args (vals :more t))
25   (:results (start :scs (any-reg) :from :load)
26             (count :scs (any-reg)))
27   (:info nvals)
28   (:temporary (:scs (descriptor-reg)) temp)
29   (:generator 20
30     (inst mr start csp-tn)
31     (inst addi csp-tn csp-tn (* nvals n-word-bytes))
32     (do ((val vals (tn-ref-across val))
33          (i 0 (1+ i)))
34         ((null val))
35       (let ((tn (tn-ref-tn val)))
36         (sc-case tn
37           (descriptor-reg
38            (storew tn start i))
39           (control-stack
40            (load-stack-tn temp tn)
41            (storew temp start i)))))
42     (inst lr count (fixnumize nvals))))
43
44 ;;; Push a list of values on the stack, returning Start and Count as used in
45 ;;; unknown values continuations.
46 ;;;
47 (define-vop (values-list)
48   (:args (arg :scs (descriptor-reg) :target list))
49   (:arg-types list)
50   (:policy :fast-safe)
51   (:results (start :scs (any-reg))
52             (count :scs (any-reg)))
53   (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
54   (:temporary (:scs (descriptor-reg)) temp)
55   (:temporary (:scs (non-descriptor-reg)) ndescr)
56   (:vop-var vop)
57   (:save-p :compute-only)
58   (:generator 0
59     (let ((loop (gen-label))
60           (done (gen-label)))
61
62       (move list arg)
63       (move start csp-tn)
64
65       (emit-label loop)
66       (inst cmpw list null-tn)
67       (loadw temp list cons-car-slot list-pointer-lowtag)
68       (inst beq done)
69       (loadw list list cons-cdr-slot list-pointer-lowtag)
70       (inst addi csp-tn csp-tn n-word-bytes)
71       (storew temp csp-tn -1)
72       (test-type list loop nil (list-pointer-lowtag) :temp ndescr)
73       (error-call vop bogus-arg-to-values-list-error list)
74
75       (emit-label done)
76       (inst sub count csp-tn start))))
77
78
79 ;;; Copy the more arg block to the top of the stack so we can use them
80 ;;; as function arguments.
81 ;;;
82 (define-vop (%more-arg-values)
83   (:args (context :scs (descriptor-reg any-reg) :target src)
84          (skip :scs (any-reg zero immediate))
85          (num :scs (any-reg) :target count))
86   (:arg-types * positive-fixnum positive-fixnum)
87   (:temporary (:sc any-reg :from (:argument 0)) src)
88   (:temporary (:sc any-reg :from (:argument 2)) dst)
89   (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
90   (:temporary (:sc any-reg) i)
91   (:results (start :scs (any-reg))
92             (count :scs (any-reg)))
93   (:generator 20
94     (sc-case skip
95       (zero
96        (inst mr src context))
97       (immediate
98        (inst addi src context (* (tn-value skip) n-word-bytes)))
99       (any-reg
100        (inst add src context skip)))
101     (inst mr. count num)
102     (inst mr start csp-tn)
103     (inst beq done)
104     (inst mr dst csp-tn)
105     (inst add csp-tn csp-tn count)
106     (inst mr i count)
107     LOOP
108     (inst cmpwi i 4)
109     (inst subi i i 4)
110     (inst lwzx temp src i)
111     (inst stwx temp dst i)
112     (inst bne loop)
113     DONE))