20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef CPU_PPC_VM_BYTES_PPC_HPP
27 #define CPU_PPC_VM_BYTES_PPC_HPP
28
29 #include "memory/allocation.hpp"
30
31 class Bytes: AllStatic {
32 public:
33 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
34 // PowerPC needs to check for alignment.
35
36 // Can I count on address always being a pointer to an unsigned char? Yes.
37
38 #if defined(VM_LITTLE_ENDIAN)
39
40 // Returns true, if the byte ordering used by Java is different from the native byte ordering
41 // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.
42 static inline bool is_Java_byte_ordering_different() { return true; }
43
44 // Forward declarations of the compiler-dependent implementation
45 static inline u2 swap_u2(u2 x);
46 static inline u4 swap_u4(u4 x);
47 static inline u8 swap_u8(u8 x);
48
49 static inline u2 get_native_u2(address p) {
50 return (intptr_t(p) & 1) == 0
51 ? *(u2*)p
52 : ( u2(p[1]) << 8 )
53 | ( u2(p[0]) );
54 }
55
56 static inline u4 get_native_u4(address p) {
57 switch (intptr_t(p) & 3) {
58 case 0: return *(u4*)p;
59
60 case 2: return ( u4( ((u2*)p)[1] ) << 16 )
61 | ( u4( ((u2*)p)[0] ) );
62
63 default: return ( u4(p[3]) << 24 )
137 ((u1*)p)[5] = x >> 40;
138 ((u1*)p)[4] = x >> 32;
139 ((u1*)p)[3] = x >> 24;
140 ((u1*)p)[2] = x >> 16;
141 ((u1*)p)[1] = x >> 8;
142 ((u1*)p)[0] = x;
143 }
144 }
145
146 // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
147 // (no byte-order reversal is needed since Power CPUs are big-endian oriented).
148 static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }
149 static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }
150 static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }
151
152 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }
153 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }
154 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }
155
156 #else // !defined(VM_LITTLE_ENDIAN)
157
158 // Returns true, if the byte ordering used by Java is different from the nativ byte ordering
159 // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.
160 static inline bool is_Java_byte_ordering_different() { return false; }
161
162 // Thus, a swap between native and Java ordering is always a no-op:
163 static inline u2 swap_u2(u2 x) { return x; }
164 static inline u4 swap_u4(u4 x) { return x; }
165 static inline u8 swap_u8(u8 x) { return x; }
166
167 static inline u2 get_native_u2(address p) {
168 return (intptr_t(p) & 1) == 0
169 ? *(u2*)p
170 : ( u2(p[0]) << 8 )
171 | ( u2(p[1]) );
172 }
173
174 static inline u4 get_native_u4(address p) {
175 switch (intptr_t(p) & 3) {
176 case 0: return *(u4*)p;
177
178 case 2: return ( u4( ((u2*)p)[0] ) << 16 )
179 | ( u4( ((u2*)p)[1] ) );
180
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef CPU_PPC_VM_BYTES_PPC_HPP
27 #define CPU_PPC_VM_BYTES_PPC_HPP
28
29 #include "memory/allocation.hpp"
30
31 class Bytes: AllStatic {
32 public:
33 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
34 // PowerPC needs to check for alignment.
35
36 // Can I count on address always being a pointer to an unsigned char? Yes.
37
38 #if defined(VM_LITTLE_ENDIAN)
39
40 // Forward declarations of the compiler-dependent implementation
41 static inline u2 swap_u2(u2 x);
42 static inline u4 swap_u4(u4 x);
43 static inline u8 swap_u8(u8 x);
44
45 static inline u2 get_native_u2(address p) {
46 return (intptr_t(p) & 1) == 0
47 ? *(u2*)p
48 : ( u2(p[1]) << 8 )
49 | ( u2(p[0]) );
50 }
51
52 static inline u4 get_native_u4(address p) {
53 switch (intptr_t(p) & 3) {
54 case 0: return *(u4*)p;
55
56 case 2: return ( u4( ((u2*)p)[1] ) << 16 )
57 | ( u4( ((u2*)p)[0] ) );
58
59 default: return ( u4(p[3]) << 24 )
133 ((u1*)p)[5] = x >> 40;
134 ((u1*)p)[4] = x >> 32;
135 ((u1*)p)[3] = x >> 24;
136 ((u1*)p)[2] = x >> 16;
137 ((u1*)p)[1] = x >> 8;
138 ((u1*)p)[0] = x;
139 }
140 }
141
142 // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
143 // (no byte-order reversal is needed since Power CPUs are big-endian oriented).
144 static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }
145 static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }
146 static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }
147
148 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }
149 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }
150 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }
151
152 #else // !defined(VM_LITTLE_ENDIAN)
153
154 // Thus, a swap between native and Java ordering is always a no-op:
155 static inline u2 swap_u2(u2 x) { return x; }
156 static inline u4 swap_u4(u4 x) { return x; }
157 static inline u8 swap_u8(u8 x) { return x; }
158
159 static inline u2 get_native_u2(address p) {
160 return (intptr_t(p) & 1) == 0
161 ? *(u2*)p
162 : ( u2(p[0]) << 8 )
163 | ( u2(p[1]) );
164 }
165
166 static inline u4 get_native_u4(address p) {
167 switch (intptr_t(p) & 3) {
168 case 0: return *(u4*)p;
169
170 case 2: return ( u4( ((u2*)p)[0] ) << 16 )
171 | ( u4( ((u2*)p)[1] ) );
172
|