Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
366 lines (319 loc) · 11.6 KB

File metadata and controls

366 lines (319 loc) · 11.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
*
* Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
* that is described in this document. In particular, and without limitation, these intellectual property
* rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
* more additional patents or pending patent applications in the U.S. and in other countries.
*
* U.S. Government Rights - Commercial software. Government users are subject to the Sun
* Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
* supplements.
*
* Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
* registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
* are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
* U.S. and other countries.
*
* UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
* Company, Ltd.
*/
package com.sun.max.lang;
import java.io.*;
import java.nio.*;
/**
* Enumerated type with values for the most common more ways to arrange bits, bytes, etc.
*
* @author Bernd Mathiske
*/
public enum Endianness {
LITTLE {
@Override
public short readShort(InputStream stream) throws IOException {
final int low = readByte(stream) & 0xff;
final int high = readByte(stream);
return (short) ((high << 8) | low);
}
@Override
public int readInt(InputStream stream) throws IOException {
final int low = readShort(stream) & 0xffff;
final int high = readShort(stream);
return (high << 16) | low;
}
@Override
public long readLong(InputStream stream) throws IOException {
final long low = readInt(stream) & 0xffffffffL;
final long high = readInt(stream);
return (high << 32) | low;
}
@Override
public void writeShort(OutputStream stream, short value) throws IOException {
short v = value;
stream.write(v & 0xff);
v >>= 8;
stream.write(v & 0xff);
}
@Override
public void writeInt(OutputStream stream, int value) throws IOException {
int v = value;
stream.write(v & 0xff);
v >>= 8;
stream.write(v & 0xff);
v >>= 8;
stream.write(v & 0xff);
v >>= 8;
stream.write(v & 0xff);
}
@Override
public void writeLong(OutputStream stream, long value) throws IOException {
long v = value;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
v >>= 8;
stream.write((int) v & 0xff);
}
@Override
public byte[] toBytes(short value) {
short v = value;
final byte[] bytes = new byte[2];
bytes[0] = (byte) (v & 0xff);
v >>= 8;
bytes[1] = (byte) (v & 0xff);
return bytes;
}
@Override
public byte[] toBytes(int value) {
int v = value;
final byte[] bytes = new byte[4];
bytes[0] = (byte) (v & 0xff);
v >>= 8;
bytes[1] = (byte) (v & 0xff);
v >>= 8;
bytes[2] = (byte) (v & 0xff);
v >>= 8;
bytes[3] = (byte) (v & 0xff);
return bytes;
}
@Override
public byte[] toBytes(long value) {
long v = value;
final byte[] bytes = new byte[8];
bytes[0] = (byte) (v & 0xff);
v >>= 8;
bytes[1] = (byte) (v & 0xff);
v >>= 8;
bytes[2] = (byte) (v & 0xff);
v >>= 8;
bytes[3] = (byte) (v & 0xff);
v >>= 8;
bytes[4] = (byte) (v & 0xff);
v >>= 8;
bytes[5] = (byte) (v & 0xff);
v >>= 8;
bytes[6] = (byte) (v & 0xff);
v >>= 8;
bytes[7] = (byte) (v & 0xff);
return bytes;
}
@Override
public void toBytes(short value, byte[] result, int offset) {
short v = value;
for (int i = 0; i < Shorts.SIZE && i < result.length; i++) {
result[i + offset] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public void toBytes(int value, byte[] result, int offset) {
int v = value;
for (int i = 0; i < Ints.SIZE && i < result.length; i++) {
result[i + offset] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public void toBytes(long value, byte[] result, int offset) {
long v = value;
for (int i = 0; i < Longs.SIZE && i < result.length; i++) {
result[i + offset] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public int offsetWithinWord(WordWidth wordWidth, WordWidth dataWidth) {
return 0;
}
@Override
public ByteOrder asByteOrder() {
return ByteOrder.LITTLE_ENDIAN;
}
},
BIG {
@Override
public short readShort(InputStream stream) throws IOException {
final int high = readByte(stream);
final int low = readByte(stream) & 0xff;
return (short) ((high << 8) | low);
}
@Override
public int readInt(InputStream stream) throws IOException {
final int high = readShort(stream);
final int low = readShort(stream) & 0xffff;
return (high << 16) | low;
}
@Override
public long readLong(InputStream stream) throws IOException {
final long high = readInt(stream);
final long low = readInt(stream) & 0xffffffffL;
return (high << 32) | low;
}
@Override
public void writeShort(OutputStream stream, short value) throws IOException {
stream.write((value >> 8) & 0xff);
stream.write(value & 0xff);
}
@Override
public void writeInt(OutputStream stream, int value) throws IOException {
stream.write((value >> 24) & 0xff);
stream.write((value >> 16) & 0xff);
stream.write((value >> 8) & 0xff);
stream.write(value & 0xff);
}
@Override
public void writeLong(OutputStream stream, long value) throws IOException {
stream.write((int) (value >> 56) & 0xff);
stream.write((int) (value >> 48) & 0xff);
stream.write((int) (value >> 40) & 0xff);
stream.write((int) (value >> 32) & 0xff);
stream.write((int) (value >> 24) & 0xff);
stream.write((int) (value >> 16) & 0xff);
stream.write((int) (value >> 8) & 0xff);
stream.write((int) value & 0xff);
}
@Override
public byte[] toBytes(short value) {
short v = value;
final byte[] bytes = new byte[2];
bytes[1] = (byte) (v & 0xff);
v >>= 8;
bytes[0] = (byte) (v & 0xff);
return bytes;
}
@Override
public byte[] toBytes(int value) {
int v = value;
final byte[] bytes = new byte[4];
bytes[3] = (byte) (v & 0xff);
v >>= 8;
bytes[2] = (byte) (v & 0xff);
v >>= 8;
bytes[1] = (byte) (v & 0xff);
v >>= 8;
bytes[0] = (byte) (v & 0xff);
return bytes;
}
@Override
public byte[] toBytes(long value) {
long v = value;
final byte[] bytes = new byte[8];
bytes[7] = (byte) (v & 0xff);
v >>= 8;
bytes[6] = (byte) (v & 0xff);
v >>= 8;
bytes[5] = (byte) (v & 0xff);
v >>= 8;
bytes[4] = (byte) (v & 0xff);
v >>= 8;
bytes[3] = (byte) (v & 0xff);
v >>= 8;
bytes[2] = (byte) (v & 0xff);
v >>= 8;
bytes[1] = (byte) (v & 0xff);
v >>= 8;
bytes[0] = (byte) (v & 0xff);
return bytes;
}
@Override
public void toBytes(short value, byte[] result, int offset) {
short v = value;
int toIndex = offset + Shorts.SIZE - 1;
for (int i = 1; i <= Shorts.SIZE && i <= result.length; i++) {
result[toIndex--] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public void toBytes(int value, byte[] result, int offset) {
int v = value;
int toIndex = offset + Ints.SIZE - 1;
for (int i = 1; i <= Ints.SIZE && i <= result.length; i++) {
result[toIndex--] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public void toBytes(long value, byte[] result, int offset) {
long v = value;
int toIndex = offset + Longs.SIZE - 1;
for (int i = 1; i <= Longs.SIZE && i <= result.length; i++) {
result[toIndex--] = (byte) (v & 0xff);
v >>= 8;
}
}
@Override
public int offsetWithinWord(WordWidth wordWidth, WordWidth dataWidth) {
assert wordWidth.numberOfBytes >= dataWidth.numberOfBytes;
return wordWidth.numberOfBytes - dataWidth.numberOfBytes;
}
@Override
public ByteOrder asByteOrder() {
return ByteOrder.BIG_ENDIAN;
}
};
@Override
public String toString() {
return name().toLowerCase();
}
public byte readByte(InputStream stream) throws IOException {
final int result = stream.read();
if (result < 0) {
throw new IOException();
}
return (byte) result;
}
public abstract short readShort(InputStream stream) throws IOException;
public abstract int readInt(InputStream stream) throws IOException;
public abstract long readLong(InputStream stream) throws IOException;
public abstract void writeShort(OutputStream stream, short value) throws IOException;
public abstract void writeInt(OutputStream stream, int value) throws IOException;
public abstract void writeLong(OutputStream stream, long value) throws IOException;
public byte[] toBytes(byte value) {
final byte[] bytes = new byte[1];
bytes[0] = value;
return bytes;
}
public abstract byte[] toBytes(short value);
public abstract byte[] toBytes(int value);
public abstract byte[] toBytes(long value);
public void toBytes(byte value, byte[] result, int offset) {
if (result.length > 0) {
result[0] = value;
}
}
public abstract void toBytes(short value, byte[] result, int offset);
public abstract void toBytes(int value, byte[] result, int offset);
public abstract void toBytes(long value, byte[] result, int offset);
public abstract int offsetWithinWord(WordWidth wordWith, WordWidth dataWidth);
public abstract ByteOrder asByteOrder();
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.