e83f65f12c3e50f31dd55e22f2dad4a03e41fe5f
[sbcl.git] / src / compiler / x86 / pred.lisp
1 ;;;; predicate VOPs for the x86 VM
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 ;;;; the branch VOP
15
16 ;;; The unconditional branch, emitted when we can't drop through to the desired
17 ;;; destination. Dest is the continuation we transfer control to.
18 (define-vop (branch)
19   (:info dest)
20   (:generator 5
21     (inst jmp dest)))
22
23 \f
24 ;;;; conditional VOPs
25
26 ;;; Note: a constant-tn is allowed in CMP; it uses an EA displacement,
27 ;;; not immediate data.
28 (define-vop (if-eq)
29   (:args (x :scs (any-reg descriptor-reg control-stack constant)
30             :load-if (not (and (sc-is x immediate)
31                                (sc-is y any-reg descriptor-reg
32                                       control-stack constant))))
33          (y :scs (any-reg descriptor-reg immediate)
34             :load-if (not (and (sc-is x any-reg descriptor-reg immediate)
35                                (sc-is y control-stack constant)))))
36   (:conditional)
37   (:info target not-p)
38   (:policy :fast-safe)
39   (:translate eq)
40   (:generator 3
41     (let ((x-val (encode-value-if-immediate x))
42           (y-val (encode-value-if-immediate y)))
43       (cond
44         ;; Shorter instruction sequences for these two cases.
45         ((and (eql 0 y-val) (sc-is x any-reg descriptor-reg)) (inst test x x))
46         ((and (eql 0 x-val) (sc-is y any-reg descriptor-reg)) (inst test y y))
47
48         ;; An encoded value (literal integer) has to be the second argument.
49         ((sc-is x immediate) (inst cmp y x-val))
50
51         (t (inst cmp x y-val))))
52
53     (inst jmp (if not-p :ne :e) target)))