0.pre7.137:
[sbcl.git] / src / compiler / x86 / char.lisp
1 ;;;; x86 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 control-stack) :target al))
19   (:temporary (:sc byte-reg :offset al-offset
20                    :from (:argument 0) :to (:eval 0)) al)
21   (:ignore al)
22   (:temporary (:sc byte-reg :offset ah-offset :target y
23                    :from (:argument 0) :to (:result 0)) ah)
24   (:results (y :scs (base-char-reg base-char-stack)))
25   (:note "character untagging")
26   (:generator 1
27     (move eax-tn x)
28     (move y ah)))
29 (define-move-vop move-to-base-char :move
30   (any-reg control-stack) (base-char-reg base-char-stack))
31
32 ;;; Move an untagged char to a tagged representation.
33 (define-vop (move-from-base-char)
34   (:args (x :scs (base-char-reg base-char-stack) :target ah))
35   (:temporary (:sc byte-reg :offset al-offset :target y
36                    :from (:argument 0) :to (:result 0)) al)
37   (:temporary (:sc byte-reg :offset ah-offset
38                    :from (:argument 0) :to (:result 0)) ah)
39   (:results (y :scs (any-reg descriptor-reg control-stack)))
40   (:note "character tagging")
41   (:generator 1
42     (move ah x)                         ; Maybe move char byte.
43     (inst mov al base-char-widetag)     ; x86 to type bits
44     (inst and eax-tn #xffff)            ; Remove any junk bits.
45     (move y eax-tn)))
46 (define-move-vop move-from-base-char :move
47   (base-char-reg base-char-stack) (any-reg descriptor-reg control-stack))
48
49 ;;; Move untagged base-char values.
50 (define-vop (base-char-move)
51   (:args (x :target y
52             :scs (base-char-reg)
53             :load-if (not (location= x y))))
54   (:results (y :scs (base-char-reg base-char-stack)
55                :load-if (not (location= x y))))
56   (:note "character move")
57   (:effects)
58   (:affected)
59   (:generator 0
60     (move y x)))
61 (define-move-vop base-char-move :move
62   (base-char-reg) (base-char-reg base-char-stack))
63
64 ;;; Move untagged base-char arguments/return-values.
65 (define-vop (move-base-char-arg)
66   (:args (x :target y
67             :scs (base-char-reg))
68          (fp :scs (any-reg)
69              :load-if (not (sc-is y base-char-reg))))
70   (:results (y))
71   (:note "character arg move")
72   (:generator 0
73     (sc-case y
74       (base-char-reg
75        (move y x))
76       (base-char-stack
77        (inst mov
78              (make-ea :byte :base fp :disp (- (* (1+ (tn-offset y)) 4)))
79              x)))))
80 (define-move-vop move-base-char-arg :move-arg
81   (any-reg base-char-reg) (base-char-reg))
82
83 ;;; Use standard MOVE-ARG + coercion to move an untagged base-char
84 ;;; to a descriptor passing location.
85 (define-move-vop move-arg :move-arg
86   (base-char-reg) (any-reg descriptor-reg))
87 \f
88 ;;;; other operations
89
90 (define-vop (char-code)
91   (:translate char-code)
92   (:policy :fast-safe)
93   (:args (ch :scs (base-char-reg base-char-stack)))
94   (:arg-types base-char)
95   (:results (res :scs (unsigned-reg)))
96   (:result-types positive-fixnum)
97   (:generator 1
98     (inst movzx res ch)))
99
100 (define-vop (code-char)
101   (:translate code-char)
102   (:policy :fast-safe)
103   (:args (code :scs (unsigned-reg unsigned-stack) :target eax))
104   (:arg-types positive-fixnum)
105   (:temporary (:sc unsigned-reg :offset eax-offset :target res
106                    :from (:argument 0) :to (:result 0))
107               eax)
108   (:results (res :scs (base-char-reg)))
109   (:result-types base-char)
110   (:generator 1
111     (move eax code)
112     (move res al-tn)))
113 \f
114 ;;; comparison of BASE-CHARs
115 (define-vop (base-char-compare)
116   (:args (x :scs (base-char-reg base-char-stack))
117          (y :scs (base-char-reg)
118             :load-if (not (and (sc-is x base-char-reg)
119                                (sc-is y base-char-stack)))))
120   (:arg-types base-char base-char)
121   (:conditional)
122   (:info target not-p)
123   (:policy :fast-safe)
124   (:note "inline comparison")
125   (:variant-vars condition not-condition)
126   (:generator 3
127     (inst cmp x y)
128     (inst jmp (if not-p not-condition condition) target)))
129
130 (define-vop (fast-char=/base-char base-char-compare)
131   (:translate char=)
132   (:variant :e :ne))
133
134 (define-vop (fast-char</base-char base-char-compare)
135   (:translate char<)
136   (:variant :b :nb))
137
138 (define-vop (fast-char>/base-char base-char-compare)
139   (:translate char>)
140   (:variant :a :na))