0.8.5.29:
[sbcl.git] / src / compiler / ppc / char.lisp
1 ;;;; the PPC 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   (:note "character untagging")
21   (:generator 1
22     (inst srwi y x n-widetag-bits)))
23
24 (define-move-vop move-to-base-char :move
25   (any-reg descriptor-reg) (base-char-reg))
26
27
28 ;;; Move an untagged char to a tagged representation.
29 (define-vop (move-from-base-char)
30   (:args (x :scs (base-char-reg)))
31   (:results (y :scs (any-reg descriptor-reg)))
32   (:note "character tagging")
33   (:generator 1
34     (inst slwi y x n-widetag-bits)
35     (inst ori y y base-char-widetag)))
36
37 (define-move-vop move-from-base-char :move
38   (base-char-reg) (any-reg descriptor-reg))
39
40 ;;; Move untagged base-char values.
41 (define-vop (base-char-move)
42   (:args (x :target y
43             :scs (base-char-reg)
44             :load-if (not (location= x y))))
45   (:results (y :scs (base-char-reg)
46                :load-if (not (location= x y))))
47   (:note "character move")
48   (:effects)
49   (:affected)
50   (:generator 0
51     (move y x)))
52
53 (define-move-vop base-char-move :move
54   (base-char-reg) (base-char-reg))
55
56 ;;; Move untagged base-char arguments/return-values.
57 (define-vop (move-base-char-arg)
58   (:args (x :target y
59             :scs (base-char-reg))
60          (fp :scs (any-reg)
61              :load-if (not (sc-is y base-char-reg))))
62   (:results (y))
63   (:note "character arg move")
64   (:generator 0
65     (sc-case y
66       (base-char-reg
67        (move y x))
68       (base-char-stack
69        (storew x fp (tn-offset y))))))
70
71 (define-move-vop move-base-char-arg :move-arg
72   (any-reg base-char-reg) (base-char-reg))
73
74
75 ;;; Use standard MOVE-ARG + coercion to move an untagged base-char
76 ;;; to a descriptor passing location.
77 (define-move-vop move-arg :move-arg
78   (base-char-reg) (any-reg descriptor-reg))
79
80
81 \f
82 ;;;; Other operations:
83
84 (define-vop (char-code)
85   (:translate char-code)
86   (:policy :fast-safe)
87   (:args (ch :scs (base-char-reg) :target res))
88   (:arg-types base-char)
89   (:results (res :scs (any-reg)))
90   (:result-types positive-fixnum)
91   (:generator 1
92     (inst slwi res ch 2)))
93
94 (define-vop (code-char)
95   (:translate code-char)
96   (:policy :fast-safe)
97   (:args (code :scs (any-reg) :target res))
98   (:arg-types positive-fixnum)
99   (:results (res :scs (base-char-reg)))
100   (:result-types base-char)
101   (:generator 1
102     (inst srwi res code 2)))
103
104 \f
105 ;;; Comparison of base-chars.
106 (define-vop (base-char-compare)
107   (:args (x :scs (base-char-reg))
108          (y :scs (base-char-reg)))
109   (:arg-types base-char base-char)
110   (:conditional)
111   (:info target not-p)
112   (:policy :fast-safe)
113   (:note "inline comparison")
114   (:variant-vars condition not-condition)
115   (:generator 3
116     (inst cmplw x y)
117     (inst b? (if not-p not-condition condition) target)))
118
119 (define-vop (fast-char=/base-char base-char-compare)
120   (:translate char=)
121   (:variant :eq :ne))
122
123 (define-vop (fast-char</base-char base-char-compare)
124   (:translate char<)
125   (:variant :lt :ge))
126
127 (define-vop (fast-char>/base-char base-char-compare)
128   (:translate char>)
129   (:variant :gt :le))
130
131 (define-vop (base-char-compare/c)
132   (:args (x :scs (base-char-reg)))
133   (:arg-types base-char (:constant base-char))
134   (:conditional)
135   (:info target not-p y)
136   (:policy :fast-safe)
137   (:note "inline comparison")
138   (:variant-vars condition not-condition)
139   (:generator 2
140     (inst cmplwi x (sb!xc:char-code y))
141     (inst b? (if not-p not-condition condition) target)))
142
143 (define-vop (fast-char=/base-char/c base-char-compare/c)
144   (:translate char=)
145   (:variant :eq :ne))
146
147 (define-vop (fast-char</base-char/c base-char-compare/c)
148   (:translate char<)
149   (:variant :lt :ge))
150
151 (define-vop (fast-char>/base-char/c base-char-compare/c)
152   (:translate char>)
153   (:variant :gt :le))
154