/
ArchitecturalWord32.java
138 lines (115 loc) · 2.81 KB
/
ArchitecturalWord32.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* This file is part of the Jikes RVM project (http://jikesrvm.org).
*
* This file is licensed to You under the Common Public License (CPL);
* You may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.opensource.org/licenses/cpl1.0.php
*
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership.
*/
package org.vmmagic.unboxed;
public final class ArchitecturalWord32 extends ArchitecturalWord {
private final int value;
private static final int SIGN_BIT = 1<<31;
ArchitecturalWord32(int value) {
assert getModel() == Architecture.BITS32;
this.value = value;
}
@Override
public boolean isZero() {
return value == 0;
}
@Override
public boolean isMax() {
return value == 0xFFFFFFFF;
}
@Override
public int toInt() {
return value;
}
@Override
public long toLongSignExtend() {
return value;
}
@Override
public long toLongZeroExtend() {
return value & 0xFFFFFFFFL;
}
@Override
boolean EQ(ArchitecturalWord word) {
return value == word.toInt();
}
/**
* Unsigned comparison - flip bit 31 and then use signed comparison.
*/
@Override
boolean LT(ArchitecturalWord word) {
return (value ^ SIGN_BIT) < (word.toInt() ^ SIGN_BIT);
}
@Override
ArchitecturalWord minus(long offset) {
return fromLong(value-(int)offset);
}
@Override
ArchitecturalWord plus(long offset) {
return fromLong(value + (int)offset);
}
@Override
ArchitecturalWord and(ArchitecturalWord w) {
return fromLong(value & w.toInt());
}
@Override
ArchitecturalWord lsh(int amt) {
return fromLong(value << amt);
}
@Override
ArchitecturalWord not() {
return fromLong(~value);
}
@Override
ArchitecturalWord or(ArchitecturalWord w) {
return fromLong(value | w.toInt());
}
@Override
ArchitecturalWord rsha(int amt) {
return fromLong(value >> amt);
}
@Override
ArchitecturalWord rshl(int amt) {
return fromLong(value >>> amt);
}
@Override
ArchitecturalWord xor(ArchitecturalWord w) {
return fromLong(value ^ w.toInt());
}
@Override
ArchitecturalWord diff(ArchitecturalWord w) {
return fromLong(value - w.toInt());
}
@Override
boolean sLT(ArchitecturalWord word) {
return value < word.toInt();
}
/**
* Create a string representation of the given int value as an address.
*/
public String toString() {
char[] chars = new char[10];
int v = value;
chars[0] = '0';
chars[1] = 'x';
for(int x = 9; x > 1; x--) {
int thisValue = v & 0x0F;
if (thisValue > 9) {
chars[x] = (char)('A' + thisValue - 10);
} else {
chars[x] = (char)('0' + thisValue);
}
v >>>= 4;
}
return new String(chars);
}
}