Mercurial > hg > truffle
comparison graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Compare.java @ 5061:e808627bd16f
Renamed projects.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 08 Mar 2012 19:24:17 +0100 |
parents | graal/com.oracle.max.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Compare.java@4ed4295ce15f |
children | d89b20486d87 |
comparison
equal
deleted
inserted
replaced
5060:4ed4295ce15f | 5061:e808627bd16f |
---|---|
1 /* | |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.lir.amd64; | |
24 | |
25 import static com.oracle.max.cri.ci.CiValueUtil.*; | |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.max.asm.target.amd64.*; | |
30 import com.oracle.max.cri.ci.*; | |
31 import com.oracle.graal.graph.*; | |
32 import com.oracle.graal.lir.*; | |
33 import com.oracle.graal.lir.asm.*; | |
34 | |
35 public enum AMD64Compare { | |
36 ICMP, LCMP, ACMP, FCMP, DCMP; | |
37 | |
38 public static class CompareOp extends AMD64LIRInstruction { | |
39 public CompareOp(AMD64Compare opcode, CiValue x, CiValue y) { | |
40 super(opcode, LIRInstruction.NO_OPERANDS, null, new CiValue[] {x, y}, LIRInstruction.NO_OPERANDS, LIRInstruction.NO_OPERANDS); | |
41 } | |
42 | |
43 @Override | |
44 public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { | |
45 CiValue x = input(0); | |
46 CiValue y = input(1); | |
47 emit(tasm, masm, (AMD64Compare) code, x, y); | |
48 } | |
49 | |
50 @Override | |
51 public EnumSet<OperandFlag> flagsFor(OperandMode mode, int index) { | |
52 if (mode == OperandMode.Input && index == 0) { | |
53 return EnumSet.of(OperandFlag.Register); | |
54 } else if (mode == OperandMode.Input && index == 1) { | |
55 return EnumSet.of(OperandFlag.Register, OperandFlag.Stack, OperandFlag.Constant); | |
56 } | |
57 throw GraalInternalError.shouldNotReachHere(); | |
58 } | |
59 | |
60 @Override | |
61 protected void verify() { | |
62 CiValue x = input(0); | |
63 CiValue y = input(1); | |
64 | |
65 super.verify(); | |
66 assert (name().startsWith("I") && x.kind == CiKind.Int && y.kind.stackKind() == CiKind.Int) | |
67 || (name().startsWith("I") && x.kind == CiKind.Jsr && y.kind == CiKind.Jsr) | |
68 || (name().startsWith("L") && x.kind == CiKind.Long && y.kind == CiKind.Long) | |
69 || (name().startsWith("A") && x.kind == CiKind.Object && y.kind == CiKind.Object) | |
70 || (name().startsWith("F") && x.kind == CiKind.Float && y.kind == CiKind.Float) | |
71 || (name().startsWith("D") && x.kind == CiKind.Double && y.kind == CiKind.Double); | |
72 } | |
73 } | |
74 | |
75 public static void emit(TargetMethodAssembler tasm, AMD64MacroAssembler masm, AMD64Compare opcode, CiValue x, CiValue y) { | |
76 if (isRegister(y)) { | |
77 switch (opcode) { | |
78 case ICMP: masm.cmpl(asIntReg(x), asIntReg(y)); break; | |
79 case LCMP: masm.cmpq(asLongReg(x), asLongReg(y)); break; | |
80 case ACMP: masm.cmpptr(asObjectReg(x), asObjectReg(y)); break; | |
81 case FCMP: masm.ucomiss(asFloatReg(x), asFloatReg(y)); break; | |
82 case DCMP: masm.ucomisd(asDoubleReg(x), asDoubleReg(y)); break; | |
83 default: throw GraalInternalError.shouldNotReachHere(); | |
84 } | |
85 } else if (isConstant(y)) { | |
86 switch (opcode) { | |
87 case ICMP: masm.cmpl(asIntReg(x), tasm.asIntConst(y)); break; | |
88 case LCMP: masm.cmpq(asLongReg(x), tasm.asIntConst(y)); break; | |
89 case ACMP: | |
90 if (((CiConstant) y).isNull()) { | |
91 masm.cmpq(asObjectReg(x), 0); break; | |
92 } else { | |
93 throw GraalInternalError.shouldNotReachHere("Only null object constants are allowed in comparisons"); | |
94 } | |
95 case FCMP: masm.ucomiss(asFloatReg(x), tasm.asFloatConstRef(y)); break; | |
96 case DCMP: masm.ucomisd(asDoubleReg(x), tasm.asDoubleConstRef(y)); break; | |
97 default: throw GraalInternalError.shouldNotReachHere(); | |
98 } | |
99 } else { | |
100 switch (opcode) { | |
101 case ICMP: masm.cmpl(asIntReg(x), tasm.asIntAddr(y)); break; | |
102 case LCMP: masm.cmpq(asLongReg(x), tasm.asLongAddr(y)); break; | |
103 case ACMP: masm.cmpptr(asObjectReg(x), tasm.asObjectAddr(y)); break; | |
104 case FCMP: masm.ucomiss(asFloatReg(x), tasm.asFloatAddr(y)); break; | |
105 case DCMP: masm.ucomisd(asDoubleReg(x), tasm.asDoubleAddr(y)); break; | |
106 default: throw GraalInternalError.shouldNotReachHere(); | |
107 } | |
108 } | |
109 } | |
110 } |