Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/risc/bitRange/CompoundBitRange.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | bc8527f3071c |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
1 /* | |
2 * Copyright (c) 2007, 2011, 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.sun.max.asm.gen.risc.bitRange; | |
24 | |
25 import java.util.*; | |
26 | |
27 /** | |
28 * A range of bits that is composed of several disjoint subranges. | |
29 */ | |
30 | |
31 public class CompoundBitRange extends BitRange { | |
32 | |
33 public CompoundBitRange() { | |
34 super(); | |
35 } | |
36 | |
37 private List<ContiguousBitRange> contiguousBitRanges = new ArrayList<ContiguousBitRange>(); | |
38 | |
39 public List<ContiguousBitRange> contiguousBitRanges() { | |
40 return contiguousBitRanges; | |
41 } | |
42 | |
43 public void add(ContiguousBitRange contiguousBitRange) { | |
44 contiguousBitRanges.add(contiguousBitRange); | |
45 } | |
46 | |
47 @Override | |
48 public CompoundBitRange move(boolean left, int bits) { | |
49 final CompoundBitRange movedRange = new CompoundBitRange(); | |
50 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
51 movedRange.add((ContiguousBitRange) contiguousBitRange.move(left, bits)); | |
52 } | |
53 return movedRange; | |
54 } | |
55 | |
56 @Override | |
57 public int width() { | |
58 int result = 0; | |
59 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
60 result += contiguousBitRange.width(); | |
61 } | |
62 return result; | |
63 } | |
64 | |
65 @Override | |
66 public int encodedWidth() { | |
67 int result = 0; | |
68 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
69 result += contiguousBitRange.encodedWidth(); | |
70 } | |
71 return result; | |
72 } | |
73 | |
74 @Override | |
75 public int instructionMask() { | |
76 int mask = 0; | |
77 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
78 mask |= contiguousBitRange.instructionMask(); | |
79 } | |
80 return mask; | |
81 } | |
82 | |
83 @Override | |
84 public int numberOfLessSignificantBits() { | |
85 int result = 32; | |
86 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
87 final int n = contiguousBitRange.numberOfLessSignificantBits(); | |
88 if (n < result) { | |
89 result = n; | |
90 } | |
91 } | |
92 return result; | |
93 } | |
94 | |
95 @Override | |
96 public boolean equals(Object other) { | |
97 if (!(other instanceof CompoundBitRange)) { | |
98 return false; | |
99 } | |
100 final CompoundBitRange compoundBitRange = (CompoundBitRange) other; | |
101 return contiguousBitRanges.equals(compoundBitRange.contiguousBitRanges); | |
102 } | |
103 | |
104 @Override | |
105 public int hashCode() { | |
106 return contiguousBitRanges.hashCode(); | |
107 } | |
108 | |
109 @Override | |
110 public String toString() { | |
111 String result = null; | |
112 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
113 if (result != null) { | |
114 result += "," + contiguousBitRange; | |
115 } else { | |
116 result = contiguousBitRange.toString(); | |
117 } | |
118 } | |
119 return result; | |
120 } | |
121 | |
122 /* Extracting */ | |
123 | |
124 @Override | |
125 public int extractSignedInt(int instruction) { | |
126 final Iterator<ContiguousBitRange> iterator = contiguousBitRanges.iterator(); | |
127 final ContiguousBitRange firstBitRange = iterator.next(); | |
128 int signedInt = firstBitRange.extractSignedInt(instruction); | |
129 while (iterator.hasNext()) { | |
130 final ContiguousBitRange contiguousBitRange = iterator.next(); | |
131 signedInt <<= contiguousBitRange.width(); | |
132 signedInt |= contiguousBitRange.extractUnsignedInt(instruction); | |
133 } | |
134 return signedInt; | |
135 } | |
136 | |
137 @Override | |
138 public int extractUnsignedInt(int instruction) { | |
139 int unsignedInt = 0; | |
140 for (ContiguousBitRange contiguousBitRange : contiguousBitRanges) { | |
141 unsignedInt <<= contiguousBitRange.width(); | |
142 unsignedInt |= contiguousBitRange.extractUnsignedInt(instruction); | |
143 } | |
144 return unsignedInt; | |
145 } | |
146 | |
147 /* Inserting */ | |
148 | |
149 @Override | |
150 public int assembleUncheckedSignedInt(int signedInt) throws IndexOutOfBoundsException { | |
151 int value = signedInt; | |
152 int result = 0; | |
153 for (int i = contiguousBitRanges.size() - 1; i >= 0; i--) { | |
154 final ContiguousBitRange contiguousBitRange = contiguousBitRanges.get(i); | |
155 result |= contiguousBitRange.assembleUncheckedSignedInt(value); | |
156 value >>= contiguousBitRange.width(); | |
157 } | |
158 return result; | |
159 } | |
160 | |
161 @Override | |
162 public int assembleUncheckedUnsignedInt(int unsignedInt) throws IndexOutOfBoundsException { | |
163 int value = unsignedInt; | |
164 int result = 0; | |
165 for (int i = contiguousBitRanges.size() - 1; i >= 0; i--) { | |
166 final ContiguousBitRange contiguousBitRange = contiguousBitRanges.get(i); | |
167 result |= contiguousBitRange.assembleUncheckedUnsignedInt(value); | |
168 value >>>= contiguousBitRange.width(); | |
169 } | |
170 return result; | |
171 } | |
172 | |
173 @Override | |
174 public String encodingString(String value, boolean signed, boolean checked) { | |
175 final StringBuilder sb = new StringBuilder(); | |
176 int shift = 0; | |
177 for (int i = contiguousBitRanges.size() - 1; i >= 0; i--) { | |
178 final ContiguousBitRange contiguousBitRange = contiguousBitRanges.get(i); | |
179 final String bits = (shift == 0) ? value : "(" + value + (signed ? " >> " : " >>> ") + shift + ")"; | |
180 final String encoding = contiguousBitRange.encodingString(bits, signed, false); | |
181 if (encoding.length() != 0) { | |
182 if (sb.length() != 0) { | |
183 sb.append(" | "); | |
184 } | |
185 sb.append(encoding); | |
186 } | |
187 shift += contiguousBitRange.width(); | |
188 } | |
189 return sb.toString(); | |
190 } | |
191 } |