0.6.12.5:
[sbcl.git] / src / compiler / alpha / char.lisp
1 ;;;; the Alpha VM definition of character operations
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 ;;;; moves and coercions
15
16 ;;; Move a tagged char to an untagged representation.
17 (define-vop (move-to-base-char)
18   (:args (x :scs (any-reg descriptor-reg)))
19   (:results (y :scs (base-char-reg)))
20   (:generator 1
21     (inst srl x sb!vm:type-bits y)))
22 ;;;
23 (define-move-vop move-to-base-char :move
24   (any-reg descriptor-reg) (base-char-reg))
25
26 ;;; Move an untagged char to a tagged representation.
27 (define-vop (move-from-base-char)
28   (:args (x :scs (base-char-reg)))
29   (:results (y :scs (any-reg descriptor-reg)))
30   (:generator 1
31     (inst sll x sb!vm:type-bits y)
32     (inst bis y sb!vm:base-char-type y)))
33 ;;;
34 (define-move-vop move-from-base-char :move
35   (base-char-reg) (any-reg descriptor-reg))
36
37 ;;; Move untagged base-char values.
38 (define-vop (base-char-move)
39   (:args (x :target y
40             :scs (base-char-reg)
41             :load-if (not (location= x y))))
42   (:results (y :scs (base-char-reg)
43                :load-if (not (location= x y))))
44   (:effects)
45   (:affected)
46   (:generator 0
47     (move x y)))
48 ;;;
49 (define-move-vop base-char-move :move
50   (base-char-reg) (base-char-reg))
51
52
53 ;;; Move untagged base-char arguments/return-values.
54 (define-vop (move-base-char-argument)
55   (:args (x :target y
56             :scs (base-char-reg))
57          (fp :scs (any-reg)
58              :load-if (not (sc-is y base-char-reg))))
59   (:results (y))
60   (:generator 0
61     (sc-case y
62       (base-char-reg
63        (move x y))
64       (base-char-stack
65        (storew x fp (tn-offset y))))))
66 ;;;
67 (define-move-vop move-base-char-argument :move-argument
68   (any-reg base-char-reg) (base-char-reg))
69
70
71 ;;; Use standard MOVE-ARGUMENT + coercion to move an untagged base-char
72 ;;; to a descriptor passing location.
73 ;;;
74 (define-move-vop move-argument :move-argument
75   (base-char-reg) (any-reg descriptor-reg))
76 \f
77 ;;;; other operations
78
79 (define-vop (char-code)
80   (:translate char-code)
81   (:policy :fast-safe)
82   (:args (ch :scs (base-char-reg) :target res))
83   (:arg-types base-char)
84   (:results (res :scs (any-reg)))
85   (:result-types positive-fixnum)
86   (:generator 1
87     (inst sll ch 2 res)))
88
89 (define-vop (code-char)
90   (:translate code-char)
91   (:policy :fast-safe)
92   (:args (code :scs (any-reg) :target res))
93   (:arg-types positive-fixnum)
94   (:results (res :scs (base-char-reg)))
95   (:result-types base-char)
96   (:generator 1
97     (inst srl code 2 res)))
98 \f
99 ;;;; comparison of BASE-CHARs
100
101 (define-vop (base-char-compare)
102   (:args (x :scs (base-char-reg))
103          (y :scs (base-char-reg)))
104   (:arg-types base-char base-char)
105   (:temporary (:scs (non-descriptor-reg)) temp)
106   (:conditional)
107   (:info target not-p)
108   (:policy :fast-safe)
109   (:note "inline comparison")
110   (:variant-vars cond)
111   (:generator 3
112     (ecase cond
113       (:eq (inst cmpeq x y temp))
114       (:lt (inst cmplt x y temp))
115       (:gt (inst cmplt y x temp)))
116     (if not-p
117         (inst beq temp target)
118         (inst bne temp target))))
119
120 (define-vop (fast-char=/base-char base-char-compare)
121   (:translate char=)
122   (:variant :eq))
123
124 (define-vop (fast-char</base-char base-char-compare)
125   (:translate char<)
126   (:variant :lt))
127
128 (define-vop (fast-char>/base-char base-char-compare)
129   (:translate char>)
130   (:variant :gt))