Mercurial > hg > graal-compiler
comparison src/cpu/ppc/vm/bytes_ppc.hpp @ 17830:56e7f5560e60
8036767: PPC64: Support for little endian execution model
Reviewed-by: goetz, kvn, dholmes, simonis
Contributed-by: asmundak@google.com
author | kvn |
---|---|
date | Wed, 02 Apr 2014 11:24:44 -0700 |
parents | 67fa91961822 |
children |
comparison
equal
deleted
inserted
replaced
17829:0118c8c7b80f | 17830:56e7f5560e60 |
---|---|
32 public: | 32 public: |
33 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering | 33 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering |
34 // PowerPC needs to check for alignment. | 34 // PowerPC needs to check for alignment. |
35 | 35 |
36 // Can I count on address always being a pointer to an unsigned char? Yes. | 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 ) | |
64 | ( u4(p[2]) << 16 ) | |
65 | ( u4(p[1]) << 8 ) | |
66 | u4(p[0]); | |
67 } | |
68 } | |
69 | |
70 static inline u8 get_native_u8(address p) { | |
71 switch (intptr_t(p) & 7) { | |
72 case 0: return *(u8*)p; | |
73 | |
74 case 4: return ( u8( ((u4*)p)[1] ) << 32 ) | |
75 | ( u8( ((u4*)p)[0] ) ); | |
76 | |
77 case 2: return ( u8( ((u2*)p)[3] ) << 48 ) | |
78 | ( u8( ((u2*)p)[2] ) << 32 ) | |
79 | ( u8( ((u2*)p)[1] ) << 16 ) | |
80 | ( u8( ((u2*)p)[0] ) ); | |
81 | |
82 default: return ( u8(p[7]) << 56 ) | |
83 | ( u8(p[6]) << 48 ) | |
84 | ( u8(p[5]) << 40 ) | |
85 | ( u8(p[4]) << 32 ) | |
86 | ( u8(p[3]) << 24 ) | |
87 | ( u8(p[2]) << 16 ) | |
88 | ( u8(p[1]) << 8 ) | |
89 | u8(p[0]); | |
90 } | |
91 } | |
92 | |
93 | |
94 | |
95 static inline void put_native_u2(address p, u2 x) { | |
96 if ( (intptr_t(p) & 1) == 0 ) *(u2*)p = x; | |
97 else { | |
98 p[1] = x >> 8; | |
99 p[0] = x; | |
100 } | |
101 } | |
102 | |
103 static inline void put_native_u4(address p, u4 x) { | |
104 switch ( intptr_t(p) & 3 ) { | |
105 case 0: *(u4*)p = x; | |
106 break; | |
107 | |
108 case 2: ((u2*)p)[1] = x >> 16; | |
109 ((u2*)p)[0] = x; | |
110 break; | |
111 | |
112 default: ((u1*)p)[3] = x >> 24; | |
113 ((u1*)p)[2] = x >> 16; | |
114 ((u1*)p)[1] = x >> 8; | |
115 ((u1*)p)[0] = x; | |
116 break; | |
117 } | |
118 } | |
119 | |
120 static inline void put_native_u8(address p, u8 x) { | |
121 switch ( intptr_t(p) & 7 ) { | |
122 case 0: *(u8*)p = x; | |
123 break; | |
124 | |
125 case 4: ((u4*)p)[1] = x >> 32; | |
126 ((u4*)p)[0] = x; | |
127 break; | |
128 | |
129 case 2: ((u2*)p)[3] = x >> 48; | |
130 ((u2*)p)[2] = x >> 32; | |
131 ((u2*)p)[1] = x >> 16; | |
132 ((u2*)p)[0] = x; | |
133 break; | |
134 | |
135 default: ((u1*)p)[7] = x >> 56; | |
136 ((u1*)p)[6] = x >> 48; | |
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) | |
37 | 157 |
38 // Returns true, if the byte ordering used by Java is different from the nativ byte ordering | 158 // Returns true, if the byte ordering used by Java is different from the nativ byte ordering |
39 // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc. | 159 // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc. |
40 static inline bool is_Java_byte_ordering_different() { return false; } | 160 static inline bool is_Java_byte_ordering_different() { return false; } |
41 | 161 |
148 static inline u8 get_Java_u8(address p) { return get_native_u8(p); } | 268 static inline u8 get_Java_u8(address p) { return get_native_u8(p); } |
149 | 269 |
150 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); } | 270 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); } |
151 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); } | 271 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); } |
152 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); } | 272 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); } |
273 | |
274 #endif // VM_LITTLE_ENDIAN | |
153 }; | 275 }; |
154 | 276 |
277 #if defined(TARGET_OS_ARCH_linux_ppc) | |
278 #include "bytes_linux_ppc.inline.hpp" | |
279 #endif | |
280 | |
155 #endif // CPU_PPC_VM_BYTES_PPC_HPP | 281 #endif // CPU_PPC_VM_BYTES_PPC_HPP |