comparison agent/src/share/classes/sun/jvm/hotspot/asm/sparc/SPARCArithmeticInstruction.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.asm.sparc;
26
27 import sun.jvm.hotspot.asm.*;
28
29 public class SPARCArithmeticInstruction extends SPARCFormat3AInstruction
30 implements ArithmeticInstruction {
31 final private int operation;
32
33 public SPARCArithmeticInstruction(String name, int opcode, int operation, SPARCRegister rs1,
34 ImmediateOrRegister operand2, SPARCRegister rd) {
35 super(name, opcode, rs1, operand2, rd);
36 this.operation = operation;
37 }
38
39 protected String getDescription() {
40 if (rd == rs1 && operand2.isImmediate()) {
41 int value = ((Immediate)operand2).getNumber().intValue();
42 StringBuffer buf = new StringBuffer();
43 switch (opcode) {
44 case ADD:
45 buf.append("inc");
46 break;
47 case ADDcc:
48 buf.append("inccc");
49 break;
50 case SUB:
51 buf.append("dec");
52 break;
53 case SUBcc:
54 buf.append("deccc");
55 break;
56 default:
57 return super.getDescription();
58 }
59 buf.append(spaces);
60 if (value != 1) {
61 buf.append(getOperand2String()); buf.append(comma);
62 }
63 buf.append(rd.toString());
64 return buf.toString();
65 } else if (rd == SPARCRegisters.G0 && opcode == SUBcc) {
66 StringBuffer buf = new StringBuffer();
67 buf.append("cmp");
68 buf.append(spaces);
69 buf.append(rs1.toString());
70 buf.append(comma);
71 buf.append(getOperand2String());
72 return buf.toString();
73 } else if (rs1 == SPARCRegisters.G0 && opcode == SUB && operand2.isRegister()) {
74 StringBuffer buf = new StringBuffer();
75 buf.append("neg");
76 buf.append(spaces);
77 buf.append(operand2.toString());
78 if (operand2 != rd) {
79 buf.append(comma);
80 buf.append(rd.toString());
81 }
82 return buf.toString();
83 }
84
85 return super.getDescription();
86 }
87
88 public Operand getArithmeticDestination() {
89 return getDestinationRegister();
90 }
91
92 public Operand[] getArithmeticSources() {
93 return (new Operand[] { rs1, operand2 });
94 }
95
96 public int getOperation() {
97 return operation;
98 }
99
100 public boolean isArithmetic() {
101 return true;
102 }
103 }