annotate src/cpu/sparc/vm/bytes_sparc.hpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 class Bytes: AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
26 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Sparc needs to check for alignment.
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // can I count on address always being a pointer to an unsigned char? Yes
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Returns true, if the byte ordering used by Java is different from the nativ byte ordering
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 static inline bool is_Java_byte_ordering_different() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Thus, a swap between native and Java ordering is always a no-op:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 static inline u2 swap_u2(u2 x) { return x; }
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static inline u4 swap_u4(u4 x) { return x; }
a61af66fc99e Initial load
duke
parents:
diff changeset
39 static inline u8 swap_u8(u8 x) { return x; }
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 static inline u2 get_native_u2(address p){
a61af66fc99e Initial load
duke
parents:
diff changeset
42 return (intptr_t(p) & 1) == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 ? *(u2*)p
a61af66fc99e Initial load
duke
parents:
diff changeset
44 : ( u2(p[0]) << 8 )
a61af66fc99e Initial load
duke
parents:
diff changeset
45 | ( u2(p[1]) );
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 static inline u4 get_native_u4(address p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 switch (intptr_t(p) & 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 case 0: return *(u4*)p;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 case 2: return ( u4( ((u2*)p)[0] ) << 16 )
a61af66fc99e Initial load
duke
parents:
diff changeset
53 | ( u4( ((u2*)p)[1] ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 default: return ( u4(p[0]) << 24 )
a61af66fc99e Initial load
duke
parents:
diff changeset
56 | ( u4(p[1]) << 16 )
a61af66fc99e Initial load
duke
parents:
diff changeset
57 | ( u4(p[2]) << 8 )
a61af66fc99e Initial load
duke
parents:
diff changeset
58 | u4(p[3]);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 static inline u8 get_native_u8(address p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 switch (intptr_t(p) & 7) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case 0: return *(u8*)p;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case 4: return ( u8( ((u4*)p)[0] ) << 32 )
a61af66fc99e Initial load
duke
parents:
diff changeset
67 | ( u8( ((u4*)p)[1] ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case 2: return ( u8( ((u2*)p)[0] ) << 48 )
a61af66fc99e Initial load
duke
parents:
diff changeset
70 | ( u8( ((u2*)p)[1] ) << 32 )
a61af66fc99e Initial load
duke
parents:
diff changeset
71 | ( u8( ((u2*)p)[2] ) << 16 )
a61af66fc99e Initial load
duke
parents:
diff changeset
72 | ( u8( ((u2*)p)[3] ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 default: return ( u8(p[0]) << 56 )
a61af66fc99e Initial load
duke
parents:
diff changeset
75 | ( u8(p[1]) << 48 )
a61af66fc99e Initial load
duke
parents:
diff changeset
76 | ( u8(p[2]) << 40 )
a61af66fc99e Initial load
duke
parents:
diff changeset
77 | ( u8(p[3]) << 32 )
a61af66fc99e Initial load
duke
parents:
diff changeset
78 | ( u8(p[4]) << 24 )
a61af66fc99e Initial load
duke
parents:
diff changeset
79 | ( u8(p[5]) << 16 )
a61af66fc99e Initial load
duke
parents:
diff changeset
80 | ( u8(p[6]) << 8 )
a61af66fc99e Initial load
duke
parents:
diff changeset
81 | u8(p[7]);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 static inline void put_native_u2(address p, u2 x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if ( (intptr_t(p) & 1) == 0 ) *(u2*)p = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 p[0] = x >> 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 p[1] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static inline void put_native_u4(address p, u4 x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 switch ( intptr_t(p) & 3 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 case 0: *(u4*)p = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 case 2: ((u2*)p)[0] = x >> 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 ((u2*)p)[1] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 default: ((u1*)p)[0] = x >> 24;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ((u1*)p)[1] = x >> 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 ((u1*)p)[2] = x >> 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 ((u1*)p)[3] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 static inline void put_native_u8(address p, u8 x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 switch ( intptr_t(p) & 7 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case 0: *(u8*)p = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case 4: ((u4*)p)[0] = x >> 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 ((u4*)p)[1] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 case 2: ((u2*)p)[0] = x >> 48;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 ((u2*)p)[1] = x >> 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 ((u2*)p)[2] = x >> 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 ((u2*)p)[3] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 default: ((u1*)p)[0] = x >> 56;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 ((u1*)p)[1] = x >> 48;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ((u1*)p)[2] = x >> 40;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ((u1*)p)[3] = x >> 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ((u1*)p)[4] = x >> 24;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 ((u1*)p)[5] = x >> 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ((u1*)p)[6] = x >> 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 ((u1*)p)[7] = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // (no byte-order reversal is needed since SPARC CPUs are big-endian oriented)
a61af66fc99e Initial load
duke
parents:
diff changeset
141 static inline u2 get_Java_u2(address p) { return get_native_u2(p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 static inline u4 get_Java_u4(address p) { return get_native_u4(p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 static inline u8 get_Java_u8(address p) { return get_native_u8(p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 };
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 //Reconciliation History
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // 1.7 98/02/24 10:18:41 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // 1.10 98/04/08 18:47:57 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // 1.13 98/07/15 17:10:03 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // 1.14 98/08/13 10:38:23 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // 1.15 98/10/05 16:30:21 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // 1.17 99/06/22 16:37:35 bytes_i486.hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
157 //End