1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/sparc/vm/bytes_sparc.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,157 @@ 1.4 +/* 1.5 + * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class Bytes: AllStatic { 1.29 + public: 1.30 + // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering 1.31 + // Sparc needs to check for alignment. 1.32 + 1.33 + // can I count on address always being a pointer to an unsigned char? Yes 1.34 + 1.35 + // Returns true, if the byte ordering used by Java is different from the nativ byte ordering 1.36 + // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc. 1.37 + static inline bool is_Java_byte_ordering_different() { return false; } 1.38 + 1.39 + // Thus, a swap between native and Java ordering is always a no-op: 1.40 + static inline u2 swap_u2(u2 x) { return x; } 1.41 + static inline u4 swap_u4(u4 x) { return x; } 1.42 + static inline u8 swap_u8(u8 x) { return x; } 1.43 + 1.44 + static inline u2 get_native_u2(address p){ 1.45 + return (intptr_t(p) & 1) == 0 1.46 + ? *(u2*)p 1.47 + : ( u2(p[0]) << 8 ) 1.48 + | ( u2(p[1]) ); 1.49 + } 1.50 + 1.51 + static inline u4 get_native_u4(address p) { 1.52 + switch (intptr_t(p) & 3) { 1.53 + case 0: return *(u4*)p; 1.54 + 1.55 + case 2: return ( u4( ((u2*)p)[0] ) << 16 ) 1.56 + | ( u4( ((u2*)p)[1] ) ); 1.57 + 1.58 + default: return ( u4(p[0]) << 24 ) 1.59 + | ( u4(p[1]) << 16 ) 1.60 + | ( u4(p[2]) << 8 ) 1.61 + | u4(p[3]); 1.62 + } 1.63 + } 1.64 + 1.65 + static inline u8 get_native_u8(address p) { 1.66 + switch (intptr_t(p) & 7) { 1.67 + case 0: return *(u8*)p; 1.68 + 1.69 + case 4: return ( u8( ((u4*)p)[0] ) << 32 ) 1.70 + | ( u8( ((u4*)p)[1] ) ); 1.71 + 1.72 + case 2: return ( u8( ((u2*)p)[0] ) << 48 ) 1.73 + | ( u8( ((u2*)p)[1] ) << 32 ) 1.74 + | ( u8( ((u2*)p)[2] ) << 16 ) 1.75 + | ( u8( ((u2*)p)[3] ) ); 1.76 + 1.77 + default: return ( u8(p[0]) << 56 ) 1.78 + | ( u8(p[1]) << 48 ) 1.79 + | ( u8(p[2]) << 40 ) 1.80 + | ( u8(p[3]) << 32 ) 1.81 + | ( u8(p[4]) << 24 ) 1.82 + | ( u8(p[5]) << 16 ) 1.83 + | ( u8(p[6]) << 8 ) 1.84 + | u8(p[7]); 1.85 + } 1.86 + } 1.87 + 1.88 + 1.89 + 1.90 + static inline void put_native_u2(address p, u2 x) { 1.91 + if ( (intptr_t(p) & 1) == 0 ) *(u2*)p = x; 1.92 + else { 1.93 + p[0] = x >> 8; 1.94 + p[1] = x; 1.95 + } 1.96 + } 1.97 + 1.98 + static inline void put_native_u4(address p, u4 x) { 1.99 + switch ( intptr_t(p) & 3 ) { 1.100 + case 0: *(u4*)p = x; 1.101 + break; 1.102 + 1.103 + case 2: ((u2*)p)[0] = x >> 16; 1.104 + ((u2*)p)[1] = x; 1.105 + break; 1.106 + 1.107 + default: ((u1*)p)[0] = x >> 24; 1.108 + ((u1*)p)[1] = x >> 16; 1.109 + ((u1*)p)[2] = x >> 8; 1.110 + ((u1*)p)[3] = x; 1.111 + break; 1.112 + } 1.113 + } 1.114 + 1.115 + static inline void put_native_u8(address p, u8 x) { 1.116 + switch ( intptr_t(p) & 7 ) { 1.117 + case 0: *(u8*)p = x; 1.118 + break; 1.119 + 1.120 + case 4: ((u4*)p)[0] = x >> 32; 1.121 + ((u4*)p)[1] = x; 1.122 + break; 1.123 + 1.124 + case 2: ((u2*)p)[0] = x >> 48; 1.125 + ((u2*)p)[1] = x >> 32; 1.126 + ((u2*)p)[2] = x >> 16; 1.127 + ((u2*)p)[3] = x; 1.128 + break; 1.129 + 1.130 + default: ((u1*)p)[0] = x >> 56; 1.131 + ((u1*)p)[1] = x >> 48; 1.132 + ((u1*)p)[2] = x >> 40; 1.133 + ((u1*)p)[3] = x >> 32; 1.134 + ((u1*)p)[4] = x >> 24; 1.135 + ((u1*)p)[5] = x >> 16; 1.136 + ((u1*)p)[6] = x >> 8; 1.137 + ((u1*)p)[7] = x; 1.138 + } 1.139 + } 1.140 + 1.141 + 1.142 + // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering) 1.143 + // (no byte-order reversal is needed since SPARC CPUs are big-endian oriented) 1.144 + static inline u2 get_Java_u2(address p) { return get_native_u2(p); } 1.145 + static inline u4 get_Java_u4(address p) { return get_native_u4(p); } 1.146 + static inline u8 get_Java_u8(address p) { return get_native_u8(p); } 1.147 + 1.148 + static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); } 1.149 + static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); } 1.150 + static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); } 1.151 +}; 1.152 + 1.153 +//Reconciliation History 1.154 +// 1.7 98/02/24 10:18:41 bytes_i486.hpp 1.155 +// 1.10 98/04/08 18:47:57 bytes_i486.hpp 1.156 +// 1.13 98/07/15 17:10:03 bytes_i486.hpp 1.157 +// 1.14 98/08/13 10:38:23 bytes_i486.hpp 1.158 +// 1.15 98/10/05 16:30:21 bytes_i486.hpp 1.159 +// 1.17 99/06/22 16:37:35 bytes_i486.hpp 1.160 +//End