1.0.24.34: IR2: additional representation for predicates, conditional moves
[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 ;;;; Generic conditional VOPs
25
26 ;;; The generic conditional branch, emitted immediately after test
27 ;;; VOPs that only set flags.
28
29 (define-vop (branch-if)
30   (:info dest flags not-p)
31   (:ignore dest flags not-p)
32   (:generator 0
33      (error "BRANCH-IF not yet implemented")))
34
35 (!def-vm-support-routine
36     convert-conditional-move-p (node dst-tn x-tn y-tn)
37   (declare (ignore node dst-tn x-tn y-tn))
38   nil)
39
40 \f
41 ;;;; conditional VOPs
42
43 ;;; Note: a constant-tn is allowed in CMP; it uses an EA displacement,
44 ;;; not immediate data.
45 (define-vop (if-eq)
46   (:args (x :scs (any-reg descriptor-reg control-stack constant)
47             :load-if (not (and (sc-is x immediate)
48                                (sc-is y any-reg descriptor-reg
49                                       control-stack constant))))
50          (y :scs (any-reg descriptor-reg immediate)
51             :load-if (not (and (sc-is x any-reg descriptor-reg immediate)
52                                (sc-is y control-stack constant)))))
53   (:conditional)
54   (:info target not-p)
55   (:policy :fast-safe)
56   (:translate eq)
57   (:generator 3
58     (let ((x-val (encode-value-if-immediate x))
59           (y-val (encode-value-if-immediate y)))
60       (cond
61         ;; Shorter instruction sequences for these two cases.
62         ((and (eql 0 y-val) (sc-is x any-reg descriptor-reg)) (inst test x x))
63         ((and (eql 0 x-val) (sc-is y any-reg descriptor-reg)) (inst test y y))
64
65         ;; An encoded value (literal integer) has to be the second argument.
66         ((sc-is x immediate) (inst cmp y x-val))
67
68         (t (inst cmp x y-val))))
69
70     (inst jmp (if not-p :ne :e) target)))