4 (define-vop (static-fun-template)
9 (:temporary (:scs (non-descriptor-reg)) temp)
10 (:temporary (:scs (descriptor-reg)) move-temp)
11 (:temporary (:sc descriptor-reg :offset lra-offset) lra)
12 (:temporary (:scs (interior-reg)) lip)
13 (:temporary (:sc any-reg :offset nargs-offset) nargs)
14 (:temporary (:sc any-reg :offset ocfp-offset) old-fp)
15 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save))
18 (eval-when (:compile-toplevel :load-toplevel :execute)
20 (defun static-fun-template-name (num-args num-results)
21 (intern (format nil "~:@(~R-arg-~R-result-static-fun~)"
22 num-args num-results)))
25 (defun moves (src dst)
27 (do ((src src (cdr src))
29 ((or (null src) (null dst)))
30 (moves `(move ,(car src) ,(car dst))))
33 (defun static-fun-template-vop (num-args num-results)
34 (unless (and (<= num-args register-arg-count)
35 (<= num-results register-arg-count))
36 (error "either too many args (~W) or too many results (~W); max = ~W"
37 num-args num-results register-arg-count))
38 (let ((num-temps (max num-args num-results)))
39 (collect ((temp-names) (temps) (arg-names) (args) (result-names) (results))
40 (dotimes (i num-results)
41 (let ((result-name (intern (format nil "RESULT-~D" i))))
42 (result-names result-name)
43 (results `(,result-name :scs (any-reg descriptor-reg)))))
44 (dotimes (i num-temps)
45 (let ((temp-name (intern (format nil "TEMP-~D" i))))
46 (temp-names temp-name)
47 (temps `(:temporary (:sc descriptor-reg
48 :offset ,(nth i *register-arg-offsets*)
49 ,@(when (< i num-args)
50 `(:from (:argument ,i)))
51 ,@(when (< i num-results)
53 :target ,(nth i (result-names)))))
56 (let ((arg-name (intern (format nil "ARG-~D" i))))
59 :scs (any-reg descriptor-reg)
60 :target ,(nth i (temp-names))))))
61 `(define-vop (,(static-fun-template-name num-args num-results)
65 (:results ,@(results))
66 (:generator ,(+ 50 num-args num-results)
67 (let ((lra-label (gen-label))
68 (cur-nfp (current-nfp-tn vop)))
69 ,@(moves (arg-names) (temp-names))
70 (inst li (fixnumize ,num-args) nargs)
71 (inst ldw (static-fun-offset symbol) null-tn lip)
73 (store-stack-tn nfp-save cur-nfp))
74 (inst move cfp-tn old-fp)
75 (inst compute-lra-from-code code-tn lra-label temp lra)
76 (note-this-location vop :call-site)
78 (inst move csp-tn cfp-tn)
79 (emit-return-pc lra-label)
80 ,(collect ((bindings) (links))
81 (do ((temp (temp-names) (cdr temp))
82 (name 'values (gensym))
87 (make-tn-ref ,(car temp) nil)))
89 (links `(setf (tn-ref-across ,prev) ,name))))
92 (default-unknown-values vop
93 ,(if (zerop num-results) nil 'values)
94 ,num-results move-temp temp lra-label)))
96 (load-stack-tn cur-nfp nfp-save))
97 ,@(moves (temp-names) (result-names))))))))
103 (collect ((templates (list 'progn)))
104 (dotimes (i register-arg-count)
105 (templates (static-fun-template-vop i 1)))
109 (defmacro define-static-fun (name args &key (results '(x)) translate
110 policy cost arg-types result-types)
112 ,(static-fun-template-name (length args)
115 (:note ,(format nil "static-fun ~@(~S~)" name))
117 `((:translate ,translate)))
119 `((:policy ,policy)))
121 `((:generator-cost ,cost)))
123 `((:arg-types ,@arg-types)))
125 `((:result-types ,@result-types)))))