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