0.7.1.20:
[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-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 srl 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 sll y x n-widetag-bits)
35     (inst or 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
57 ;;; Move untagged base-char arguments/return-values.
58 (define-vop (move-base-char-arg)
59   (:args (x :target y
60             :scs (base-char-reg))
61          (fp :scs (any-reg)
62              :load-if (not (sc-is y base-char-reg))))
63   (:results (y))
64   (:note "character arg move")
65   (:generator 0
66     (sc-case y
67       (base-char-reg
68        (move y x))
69       (base-char-stack
70        (storew x fp (tn-offset y))))))
71
72 (define-move-vop move-base-char-arg :move-arg
73   (any-reg base-char-reg) (base-char-reg))
74
75
76 ;;; Use standard MOVE-ARG + coercion to move an untagged base-char
77 ;;; to a descriptor passing location.
78 (define-move-vop move-arg :move-arg
79   (base-char-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 (base-char-reg) :target res))
89   (:arg-types base-char)
90   (:results (res :scs (any-reg)))
91   (:result-types positive-fixnum)
92   (:generator 1
93     (inst sll res ch 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 (base-char-reg)))
101   (:result-types base-char)
102   (:generator 1
103     (inst srl res code fixnum-tag-bits)))
104
105 \f
106 ;;; Comparison of base-chars.
107 (define-vop (base-char-compare)
108   (:args (x :scs (base-char-reg))
109          (y :scs (base-char-reg)))
110   (:arg-types base-char base-char)
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=/base-char base-char-compare)
122   (:translate char=)
123   (:variant :eq :ne))
124
125 (define-vop (fast-char</base-char base-char-compare)
126   (:translate char<)
127   (:variant :ltu :geu))
128
129 (define-vop (fast-char>/base-char base-char-compare)
130   (:translate char>)
131   (:variant :gtu :leu))